Skip to content

Commit

Permalink
Fix/gql about webui query same response type as webui update info (#781)
Browse files Browse the repository at this point in the history
* Use a new type for the webui about info query

Using the same type for this and the webui update queries/mutations caused apollo to save it as the same data in the cache, overwriting the "about info"

* Use a new type for the webui about check query

To prevent similar issues (cc3bf5f34a8afebadd306d037db1a10088ef9334) with the "update check" and the "update progress" payloads

* Throw update check error when calling it via the query

Otherwise, the error is never raised to the frontend

* Set "ERROR" state in case the update check failed on WebUI update trigger
  • Loading branch information
schroda authored Nov 26, 2023
1 parent d65ed6c commit 94b670e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package suwayomi.tachidesk.graphql.mutations
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withTimeout
import suwayomi.tachidesk.graphql.types.UpdateState.DOWNLOADING
import suwayomi.tachidesk.graphql.types.UpdateState.ERROR
import suwayomi.tachidesk.graphql.types.UpdateState.STOPPED
import suwayomi.tachidesk.graphql.types.WebUIUpdateInfo
import suwayomi.tachidesk.graphql.types.WebUIUpdateStatus
Expand Down Expand Up @@ -32,6 +33,8 @@ class InfoMutation {
val (version, updateAvailable) = WebInterfaceManager.isUpdateAvailable()

if (!updateAvailable) {
val didUpdateCheckFail = version.isEmpty()

return@withTimeout WebUIUpdatePayload(
input.clientMutationId,
WebUIUpdateStatus(
Expand All @@ -41,7 +44,7 @@ class InfoMutation {
tag = version,
updateAvailable,
),
state = STOPPED,
state = if (didUpdateCheckFail) ERROR else STOPPED,
progress = 0,
),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package suwayomi.tachidesk.graphql.queries

import suwayomi.tachidesk.global.impl.AppUpdate
import suwayomi.tachidesk.graphql.types.WebUIUpdateInfo
import suwayomi.tachidesk.graphql.types.AboutWebUI
import suwayomi.tachidesk.graphql.types.WebUIUpdateCheck
import suwayomi.tachidesk.graphql.types.WebUIUpdateStatus
import suwayomi.tachidesk.server.JavalinSetup.future
import suwayomi.tachidesk.server.generated.BuildConfig
Expand Down Expand Up @@ -51,16 +52,16 @@ class InfoQuery {
}
}

fun aboutWebUI(): CompletableFuture<WebUIUpdateInfo> {
fun aboutWebUI(): CompletableFuture<AboutWebUI> {
return future {
WebInterfaceManager.getAboutInfo()
}
}

fun checkForWebUIUpdate(): CompletableFuture<WebUIUpdateInfo> {
fun checkForWebUIUpdate(): CompletableFuture<WebUIUpdateCheck> {
return future {
val (version, updateAvailable) = WebInterfaceManager.isUpdateAvailable()
WebUIUpdateInfo(
val (version, updateAvailable) = WebInterfaceManager.isUpdateAvailable(raiseError = true)
WebUIUpdateCheck(
channel = serverConfig.webUIChannel.value,
tag = version,
updateAvailable,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package suwayomi.tachidesk.graphql.types

data class AboutWebUI(
val channel: String,
val tag: String,
)

data class WebUIUpdateCheck(
val channel: String,
val tag: String,
val updateAvailable: Boolean,
)

data class WebUIUpdateInfo(
val channel: String,
val tag: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import net.lingala.zip4j.ZipFile
import org.kodein.di.DI
import org.kodein.di.conf.global
import org.kodein.di.instance
import suwayomi.tachidesk.graphql.types.AboutWebUI
import suwayomi.tachidesk.graphql.types.UpdateState
import suwayomi.tachidesk.graphql.types.UpdateState.DOWNLOADING
import suwayomi.tachidesk.graphql.types.UpdateState.ERROR
Expand Down Expand Up @@ -167,18 +168,17 @@ object WebInterfaceManager {
)
}

suspend fun getAboutInfo(): WebUIUpdateInfo {
suspend fun getAboutInfo(): AboutWebUI {
val currentVersion = getLocalVersion()

val failedToGetVersion = currentVersion === "r-1"
if (failedToGetVersion) {
throw Exception("Failed to get current version")
}

return WebUIUpdateInfo(
return AboutWebUI(
channel = serverConfig.webUIChannel.value,
tag = currentVersion,
updateAvailable = isUpdateAvailable(currentVersion).second,
)
}

Expand Down Expand Up @@ -661,14 +661,22 @@ object WebInterfaceManager {
ZipFile(zipFilePath).use { it.extractAll(targetPath) }
}

suspend fun isUpdateAvailable(currentVersion: String = getLocalVersion()): Pair<String, Boolean> {
suspend fun isUpdateAvailable(
currentVersion: String = getLocalVersion(),
raiseError: Boolean = false,
): Pair<String, Boolean> {
return try {
val latestCompatibleVersion = getLatestCompatibleVersion()
val isUpdateAvailable = latestCompatibleVersion != currentVersion

Pair(latestCompatibleVersion, isUpdateAvailable)
} catch (e: Exception) {
logger.warn(e) { "isUpdateAvailable: check failed due to" }

if (raiseError) {
throw e
}

Pair("", false)
}
}
Expand Down

0 comments on commit 94b670e

Please sign in to comment.