add update file
This commit is contained in:
+11
-1
@@ -9,13 +9,14 @@ import ru.shadowsparky.updater.domain.UpdateFetcher
|
||||
import ru.shadowsparky.updater.domain.UpdateInfo
|
||||
import java.io.File
|
||||
|
||||
@Factory
|
||||
@Factory(binds = [BackendUpdateFetcher::class])
|
||||
class BackendUpdateFetcher(
|
||||
private val envFetcher: EnvFetcher,
|
||||
private val json: Json,
|
||||
private val dispatcherProvider: DispatcherProvider
|
||||
) : UpdateFetcher {
|
||||
private var config: UpdateInfo? = null
|
||||
private var updateFile: File? = null
|
||||
|
||||
override suspend fun fetch(versionCode: Long): UpdateInfo = withContext(dispatcherProvider.io) {
|
||||
config?.let { return@withContext it }
|
||||
@@ -28,4 +29,13 @@ class BackendUpdateFetcher(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateFile(): File = withContext(dispatcherProvider.io) {
|
||||
val updateFilePath = envFetcher.get("UPDATE_FILE")
|
||||
if (updateFilePath.isBlank()) error("Update not found")
|
||||
val file = File(updateFilePath)
|
||||
if (!file.exists()) error("File not exists")
|
||||
updateFile = file
|
||||
file
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class RoutingEntryPoint(
|
||||
val savedMovieFactory: SavedMovieRepositoryFactory,
|
||||
val movieTagFactory: MovieTagRepositoryFactory,
|
||||
val userTagFactory: UserTagRepositoryFactory,
|
||||
val updateFetcher: UpdateFetcher
|
||||
val updateFetcher: BackendUpdateFetcher
|
||||
)
|
||||
|
||||
@Single
|
||||
|
||||
+6
-1
@@ -1,15 +1,20 @@
|
||||
package ru.shadowsparky.vbox.backend.presentation.routing
|
||||
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.response.respondFile
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.get
|
||||
import io.ktor.server.util.getOrFail
|
||||
import ru.shadowsparky.updater.domain.UpdateFetcher
|
||||
import ru.shadowsparky.vbox.backend.data.BackendUpdateFetcher
|
||||
import ru.shadowsparky.vbox.shared.domain.DYNAMIC_PREFIX
|
||||
|
||||
fun Route.setupUpdates(updateFetcher: UpdateFetcher) {
|
||||
fun Route.setupUpdates(updateFetcher: BackendUpdateFetcher) {
|
||||
get("$DYNAMIC_PREFIX/checkUpdates") {
|
||||
val versionCode = call.parameters.getOrFail(UpdateFetcher.ARG_VERSION_CODE).toLong()
|
||||
call.respond(updateFetcher.fetch(versionCode))
|
||||
}
|
||||
get("$DYNAMIC_PREFIX/getApk") {
|
||||
call.respondFile(updateFetcher.updateFile())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user