update no token message

This commit is contained in:
2026-07-26 11:31:27 +03:00
parent ea51196433
commit d3afebf420
5 changed files with 25 additions and 9 deletions
@@ -1,19 +1,33 @@
package ru.shadowsparky.vbox.backend.data
import io.ktor.http.HttpStatusCode
import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json
import org.koin.core.annotation.Factory
import ru.shadowsparky.backend.data.EnvFetcher
import ru.shadowsparky.domain.DispatcherProvider
import ru.shadowsparky.http.domain.HttpException
import ru.shadowsparky.updater.domain.UpdateFetcher
import ru.shadowsparky.updater.domain.UpdateInfo
import java.io.File
@Factory
class BackendUpdateFetcherFactory(
private val envFetcher: EnvFetcher,
private val json: Json,
private val dispatcherProvider: DispatcherProvider
) {
fun create(userId: Long): BackendUpdateFetcher {
return BackendUpdateFetcher(envFetcher, json, dispatcherProvider, userId)
}
}
@Factory(binds = [BackendUpdateFetcher::class])
class BackendUpdateFetcher(
private val envFetcher: EnvFetcher,
private val json: Json,
private val dispatcherProvider: DispatcherProvider
private val dispatcherProvider: DispatcherProvider,
private val userId: Long
) : UpdateFetcher {
private var config: UpdateInfo? = null
private var updateFile: File? = null
@@ -32,7 +46,7 @@ class BackendUpdateFetcher(
suspend fun updateFile(): File = withContext(dispatcherProvider.io) {
val updateFilePath = envFetcher.get("UPDATE_FILE")
if (updateFilePath.isBlank()) error("Update not found")
if (updateFilePath.isBlank()) throw HttpException(HttpStatusCode.NotFound.value, "Update not found")
val file = File(updateFilePath)
if (!file.exists()) error("File not exists")
updateFile = file
@@ -5,9 +5,8 @@ import org.koin.core.annotation.Single
import ru.shadowsparky.backend.data.TokenVerifier
import ru.shadowsparky.backend.domain.JwtInfo
import ru.shadowsparky.backend.domain.LoginVerifier
import ru.shadowsparky.updater.domain.UpdateFetcher
import ru.shadowsparky.vbox.backend.data.BackendRemoteEventHandler
import ru.shadowsparky.vbox.backend.data.BackendUpdateFetcher
import ru.shadowsparky.vbox.backend.data.BackendUpdateFetcherFactory
import ru.shadowsparky.vbox.backend.data.auth.AuthTokenRepositoryFactory
import ru.shadowsparky.vbox.backend.data.tags.MovieTagRepositoryFactory
import ru.shadowsparky.vbox.backend.data.tags.UserTagRepositoryFactory
@@ -25,7 +24,7 @@ class RoutingEntryPoint(
val savedMovieFactory: SavedMovieRepositoryFactory,
val movieTagFactory: MovieTagRepositoryFactory,
val userTagFactory: UserTagRepositoryFactory,
val updateFetcher: BackendUpdateFetcher
val updateFetcherFactory: BackendUpdateFetcherFactory
)
@Single
@@ -44,6 +44,6 @@ fun Routing.setupAuthMethods(
setupRecentlyWatched(recentlyFactory)
setupSavedMovie(savedMovieFactory)
setupTagsRouting(userTagFactory, movieTagFactory)
setupUpdates(updateFetcher)
setupUpdates(updateFetcherFactory)
}
}
@@ -6,15 +6,18 @@ 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.backend.data.BackendUpdateFetcherFactory
import ru.shadowsparky.vbox.backend.presentation.obtainUserId
import ru.shadowsparky.vbox.shared.domain.DYNAMIC_PREFIX
fun Route.setupUpdates(updateFetcher: BackendUpdateFetcher) {
fun Route.setupUpdates(updateFetcherFactory: BackendUpdateFetcherFactory) {
get("$DYNAMIC_PREFIX/checkUpdates") {
val versionCode = call.parameters.getOrFail(UpdateFetcher.ARG_VERSION_CODE).toLong()
val updateFetcher = updateFetcherFactory.create(call.obtainUserId())
call.respond(updateFetcher.fetch(versionCode))
}
get("$DYNAMIC_PREFIX/getApk") {
val updateFetcher = updateFetcherFactory.create(call.obtainUserId())
call.respondFile(updateFetcher.updateFile())
}
}
@@ -7,4 +7,4 @@ interface LoginVerifier {
const val LOGIN_NAME = "login"
const val USER_ID_ARG = "user_id"
const val INVALID_TOKEN_MSG = "Был передан неправильный токен"
const val INVALID_TOKEN_MSG = "Для выполнения этого действия требуется авторизация."