From d3afebf42034f400e5b736fa3798948be15e1d13 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sun, 26 Jul 2026 11:31:27 +0300 Subject: [PATCH] update no token message --- .../vbox/backend/data/BackendUpdateFetcher.kt | 18 ++++++++++++++++-- .../shadowsparky/vbox/backend/di/EntryPoint.kt | 5 ++--- .../presentation/routing/AuthRouting.kt | 2 +- .../presentation/routing/UpdateRouting.kt | 7 +++++-- .../backend/domain/LoginVerifier.kt | 2 +- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/data/BackendUpdateFetcher.kt b/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/data/BackendUpdateFetcher.kt index bae095a..90f0f49 100644 --- a/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/data/BackendUpdateFetcher.kt +++ b/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/data/BackendUpdateFetcher.kt @@ -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 diff --git a/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/di/EntryPoint.kt b/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/di/EntryPoint.kt index 692f93c..c497dd3 100644 --- a/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/di/EntryPoint.kt +++ b/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/di/EntryPoint.kt @@ -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 diff --git a/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/presentation/routing/AuthRouting.kt b/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/presentation/routing/AuthRouting.kt index 0091b35..f16d5bd 100644 --- a/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/presentation/routing/AuthRouting.kt +++ b/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/presentation/routing/AuthRouting.kt @@ -44,6 +44,6 @@ fun Routing.setupAuthMethods( setupRecentlyWatched(recentlyFactory) setupSavedMovie(savedMovieFactory) setupTagsRouting(userTagFactory, movieTagFactory) - setupUpdates(updateFetcher) + setupUpdates(updateFetcherFactory) } } diff --git a/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/presentation/routing/UpdateRouting.kt b/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/presentation/routing/UpdateRouting.kt index f9a2781..146604f 100644 --- a/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/presentation/routing/UpdateRouting.kt +++ b/apps/vbox/backend/src/main/kotlin/ru/shadowsparky/vbox/backend/presentation/routing/UpdateRouting.kt @@ -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()) } } diff --git a/libs/backend-base/src/main/kotlin/ru/shadowsparky/backend/domain/LoginVerifier.kt b/libs/backend-base/src/main/kotlin/ru/shadowsparky/backend/domain/LoginVerifier.kt index 741eb44..6247de0 100644 --- a/libs/backend-base/src/main/kotlin/ru/shadowsparky/backend/domain/LoginVerifier.kt +++ b/libs/backend-base/src/main/kotlin/ru/shadowsparky/backend/domain/LoginVerifier.kt @@ -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 = "Для выполнения этого действия требуется авторизация."