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