refactor and comment
This commit is contained in:
@@ -112,7 +112,7 @@ val tachideskRevision = runCatching {
|
||||
|
||||
buildConfig {
|
||||
clsName = "BuildConfig"
|
||||
packageName = "suwayomi.server"
|
||||
packageName = "suwayomi.tachidesk.server"
|
||||
|
||||
|
||||
buildConfigField("String", "NAME", rootProject.name)
|
||||
|
||||
@@ -1,30 +1,24 @@
|
||||
package suwayomi.tachidesk.global
|
||||
|
||||
import io.javalin.Javalin
|
||||
import suwayomi.tachidesk.global.impl.About
|
||||
import suwayomi.tachidesk.global.impl.AppUpdate
|
||||
import suwayomi.tachidesk.server.JavalinSetup
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import io.javalin.Javalin
|
||||
import io.javalin.apibuilder.ApiBuilder.get
|
||||
import io.javalin.apibuilder.ApiBuilder.path
|
||||
import suwayomi.tachidesk.global.controller.SettingsController
|
||||
|
||||
object GlobalAPI {
|
||||
fun defineEndpoints(app: Javalin) {
|
||||
// returns some static info about the current app build
|
||||
app.get("/api/v1/settings/about/") { ctx ->
|
||||
ctx.json(About.getAbout())
|
||||
}
|
||||
|
||||
// check for app updates
|
||||
app.get("/api/v1/settings/check-update/") { ctx ->
|
||||
|
||||
ctx.json(
|
||||
JavalinSetup.future { AppUpdate.checkUpdate() }
|
||||
)
|
||||
app.routes {
|
||||
path("api/v1/settings") {
|
||||
get("about", SettingsController::about)
|
||||
get("check-update", SettingsController::checkUpdate)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package suwayomi.tachidesk.global.controller
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import io.javalin.http.Context
|
||||
import suwayomi.tachidesk.global.impl.About
|
||||
import suwayomi.tachidesk.global.impl.AppUpdate
|
||||
import suwayomi.tachidesk.server.JavalinSetup
|
||||
|
||||
/** Settings Page/Screen */
|
||||
object SettingsController {
|
||||
/** returns some static info about the current app build */
|
||||
fun about(ctx: Context): Context {
|
||||
return ctx.json(About.getAbout())
|
||||
}
|
||||
|
||||
/** check for app updates */
|
||||
fun checkUpdate(ctx: Context): Context {
|
||||
return ctx.json(
|
||||
JavalinSetup.future { AppUpdate.checkUpdate() }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ package suwayomi.tachidesk.global.impl
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import suwayomi.server.BuildConfig
|
||||
import suwayomi.tachidesk.server.BuildConfig
|
||||
|
||||
data class AboutDataClass(
|
||||
val name: String,
|
||||
|
||||
@@ -16,14 +16,15 @@ import uy.kohesive.injekt.injectLazy
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
data class UpdateDataClass(
|
||||
/** [channel] mirrors [suwayomi.tachidesk.server.BuildConfig.BUILD_TYPE] */
|
||||
val channel: String,
|
||||
val tag: String,
|
||||
val url: String
|
||||
)
|
||||
|
||||
object AppUpdate {
|
||||
private const val LATEST_STABLE_URL = "https://api.github.com/repos/Suwayomi/Tachidesk/releases/latest"
|
||||
private const val LATEST_PREVIEW_URL = "https://api.github.com/repos/Suwayomi/Tachidesk-preview/releases/latest"
|
||||
private const val LATEST_STABLE_CHANNEL_URL = "https://api.github.com/repos/Suwayomi/Tachidesk/releases/latest"
|
||||
private const val LATEST_PREVIEW_CHANNEL_URL = "https://api.github.com/repos/Suwayomi/Tachidesk-preview/releases/latest"
|
||||
|
||||
private val json: Json by injectLazy()
|
||||
private val network: NetworkHelper by injectLazy()
|
||||
@@ -31,13 +32,13 @@ object AppUpdate {
|
||||
suspend fun checkUpdate(): List<UpdateDataClass> {
|
||||
val stableJson = json.parseToJsonElement(
|
||||
network.client.newCall(
|
||||
GET(LATEST_STABLE_URL)
|
||||
GET(LATEST_STABLE_CHANNEL_URL)
|
||||
).await().body!!.string()
|
||||
).jsonObject
|
||||
|
||||
val previewJson = json.parseToJsonElement(
|
||||
network.client.newCall(
|
||||
GET(LATEST_PREVIEW_URL)
|
||||
GET(LATEST_PREVIEW_CHANNEL_URL)
|
||||
).await().body!!.string()
|
||||
).jsonObject
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.kodein.di.DI
|
||||
import org.kodein.di.bind
|
||||
import org.kodein.di.conf.global
|
||||
import org.kodein.di.singleton
|
||||
import suwayomi.server.BuildConfig
|
||||
import suwayomi.tachidesk.server.BuildConfig
|
||||
import suwayomi.tachidesk.server.database.databaseUp
|
||||
import suwayomi.tachidesk.server.util.AppMutex.handleAppMutex
|
||||
import suwayomi.tachidesk.server.util.SystemTray.systemTray
|
||||
|
||||
@@ -10,7 +10,7 @@ package suwayomi.tachidesk.server.util
|
||||
import dorkbox.systemTray.MenuItem
|
||||
import dorkbox.systemTray.SystemTray
|
||||
import dorkbox.util.CacheUtil
|
||||
import suwayomi.server.BuildConfig
|
||||
import suwayomi.tachidesk.server.BuildConfig
|
||||
import suwayomi.tachidesk.server.ServerConfig
|
||||
import suwayomi.tachidesk.server.serverConfig
|
||||
import suwayomi.tachidesk.server.util.Browser.openInBrowser
|
||||
|
||||
Reference in New Issue
Block a user