Fix/gql about webui query same response type as webui update info (#781)
* 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
This commit is contained in:
@@ -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
|
||||
@@ -32,6 +33,8 @@ class InfoMutation {
|
||||
val (version, updateAvailable) = WebInterfaceManager.isUpdateAvailable()
|
||||
|
||||
if (!updateAvailable) {
|
||||
val didUpdateCheckFail = version.isEmpty()
|
||||
|
||||
return@withTimeout WebUIUpdatePayload(
|
||||
input.clientMutationId,
|
||||
WebUIUpdateStatus(
|
||||
@@ -41,7 +44,7 @@ class InfoMutation {
|
||||
tag = version,
|
||||
updateAvailable,
|
||||
),
|
||||
state = STOPPED,
|
||||
state = if (didUpdateCheckFail) ERROR else STOPPED,
|
||||
progress = 0,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -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
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
@@ -167,7 +168,7 @@ object WebInterfaceManager {
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun getAboutInfo(): WebUIUpdateInfo {
|
||||
suspend fun getAboutInfo(): AboutWebUI {
|
||||
val currentVersion = getLocalVersion()
|
||||
|
||||
val failedToGetVersion = currentVersion === "r-1"
|
||||
@@ -175,10 +176,9 @@ object WebInterfaceManager {
|
||||
throw Exception("Failed to get current version")
|
||||
}
|
||||
|
||||
return WebUIUpdateInfo(
|
||||
return AboutWebUI(
|
||||
channel = serverConfig.webUIChannel.value,
|
||||
tag = currentVersion,
|
||||
updateAvailable = isUpdateAvailable(currentVersion).second,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -661,7 +661,10 @@ 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
|
||||
@@ -669,6 +672,11 @@ object WebInterfaceManager {
|
||||
Pair(latestCompatibleVersion, isUpdateAvailable)
|
||||
} catch (e: Exception) {
|
||||
logger.warn(e) { "isUpdateAvailable: check failed due to" }
|
||||
|
||||
if (raiseError) {
|
||||
throw e
|
||||
}
|
||||
|
||||
Pair("", false)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user