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