From 06d7a6d892ec98b15583a980065acb1bfed2cefb Mon Sep 17 00:00:00 2001 From: Mitchell Syer Date: Thu, 3 Aug 2023 18:09:11 -0400 Subject: [PATCH] Info Queries (#627) --- .../tachidesk/global/impl/AppUpdate.kt | 4 +- .../tachidesk/graphql/queries/InfoQuery.kt | 49 +++++++++++++++++++ .../graphql/server/TachideskGraphQLSchema.kt | 2 + 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/InfoQuery.kt diff --git a/server/src/main/kotlin/suwayomi/tachidesk/global/impl/AppUpdate.kt b/server/src/main/kotlin/suwayomi/tachidesk/global/impl/AppUpdate.kt index e3b14ac1e..8286af5d9 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/global/impl/AppUpdate.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/global/impl/AppUpdate.kt @@ -33,13 +33,13 @@ object AppUpdate { val stableJson = json.parseToJsonElement( network.client.newCall( GET(LATEST_STABLE_CHANNEL_URL) - ).await().body!!.string() + ).await().body.string() ).jsonObject val previewJson = json.parseToJsonElement( network.client.newCall( GET(LATEST_PREVIEW_CHANNEL_URL) - ).await().body!!.string() + ).await().body.string() ).jsonObject return listOf( diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/InfoQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/InfoQuery.kt new file mode 100644 index 000000000..add167810 --- /dev/null +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/InfoQuery.kt @@ -0,0 +1,49 @@ +package suwayomi.tachidesk.graphql.queries + +import suwayomi.tachidesk.global.impl.AppUpdate +import suwayomi.tachidesk.server.BuildConfig +import suwayomi.tachidesk.server.JavalinSetup.future +import java.util.concurrent.CompletableFuture + +class InfoQuery { + data class AboutPayload( + val name: String, + val version: String, + val revision: String, + val buildType: String, + val buildTime: Long, + val github: String, + val discord: String + ) + + fun about(): AboutPayload { + return AboutPayload( + BuildConfig.NAME, + BuildConfig.VERSION, + BuildConfig.REVISION, + BuildConfig.BUILD_TYPE, + BuildConfig.BUILD_TIME, + BuildConfig.GITHUB, + BuildConfig.DISCORD + ) + } + + data class CheckForUpdatesPayload( + /** [channel] mirrors [suwayomi.tachidesk.server.BuildConfig.BUILD_TYPE] */ + val channel: String, + val tag: String, + val url: String + ) + + fun checkForUpdates(): CompletableFuture> { + return future { + AppUpdate.checkUpdate().map { + CheckForUpdatesPayload( + channel = it.channel, + tag = it.tag, + url = it.url + ) + } + } + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt index dc4b9c4b5..7f6998a80 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskGraphQLSchema.kt @@ -27,6 +27,7 @@ import suwayomi.tachidesk.graphql.queries.CategoryQuery import suwayomi.tachidesk.graphql.queries.ChapterQuery import suwayomi.tachidesk.graphql.queries.DownloadQuery import suwayomi.tachidesk.graphql.queries.ExtensionQuery +import suwayomi.tachidesk.graphql.queries.InfoQuery import suwayomi.tachidesk.graphql.queries.MangaQuery import suwayomi.tachidesk.graphql.queries.MetaQuery import suwayomi.tachidesk.graphql.queries.SourceQuery @@ -61,6 +62,7 @@ val schema = toSchema( TopLevelObject(ChapterQuery()), TopLevelObject(DownloadQuery()), TopLevelObject(ExtensionQuery()), + TopLevelObject(InfoQuery()), TopLevelObject(MangaQuery()), TopLevelObject(MetaQuery()), TopLevelObject(SourceQuery()),