mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -05:00
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.flow.first
|
||||||
import kotlinx.coroutines.withTimeout
|
import kotlinx.coroutines.withTimeout
|
||||||
import suwayomi.tachidesk.graphql.types.UpdateState.DOWNLOADING
|
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.UpdateState.STOPPED
|
||||||
import suwayomi.tachidesk.graphql.types.WebUIUpdateInfo
|
import suwayomi.tachidesk.graphql.types.WebUIUpdateInfo
|
||||||
import suwayomi.tachidesk.graphql.types.WebUIUpdateStatus
|
import suwayomi.tachidesk.graphql.types.WebUIUpdateStatus
|
||||||
@@ -32,6 +33,8 @@ class InfoMutation {
|
|||||||
val (version, updateAvailable) = WebInterfaceManager.isUpdateAvailable()
|
val (version, updateAvailable) = WebInterfaceManager.isUpdateAvailable()
|
||||||
|
|
||||||
if (!updateAvailable) {
|
if (!updateAvailable) {
|
||||||
|
val didUpdateCheckFail = version.isEmpty()
|
||||||
|
|
||||||
return@withTimeout WebUIUpdatePayload(
|
return@withTimeout WebUIUpdatePayload(
|
||||||
input.clientMutationId,
|
input.clientMutationId,
|
||||||
WebUIUpdateStatus(
|
WebUIUpdateStatus(
|
||||||
@@ -41,7 +44,7 @@ class InfoMutation {
|
|||||||
tag = version,
|
tag = version,
|
||||||
updateAvailable,
|
updateAvailable,
|
||||||
),
|
),
|
||||||
state = STOPPED,
|
state = if (didUpdateCheckFail) ERROR else STOPPED,
|
||||||
progress = 0,
|
progress = 0,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package suwayomi.tachidesk.graphql.queries
|
package suwayomi.tachidesk.graphql.queries
|
||||||
|
|
||||||
import suwayomi.tachidesk.global.impl.AppUpdate
|
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.graphql.types.WebUIUpdateStatus
|
||||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||||
import suwayomi.tachidesk.server.generated.BuildConfig
|
import suwayomi.tachidesk.server.generated.BuildConfig
|
||||||
@@ -51,16 +52,16 @@ class InfoQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun aboutWebUI(): CompletableFuture<WebUIUpdateInfo> {
|
fun aboutWebUI(): CompletableFuture<AboutWebUI> {
|
||||||
return future {
|
return future {
|
||||||
WebInterfaceManager.getAboutInfo()
|
WebInterfaceManager.getAboutInfo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkForWebUIUpdate(): CompletableFuture<WebUIUpdateInfo> {
|
fun checkForWebUIUpdate(): CompletableFuture<WebUIUpdateCheck> {
|
||||||
return future {
|
return future {
|
||||||
val (version, updateAvailable) = WebInterfaceManager.isUpdateAvailable()
|
val (version, updateAvailable) = WebInterfaceManager.isUpdateAvailable(raiseError = true)
|
||||||
WebUIUpdateInfo(
|
WebUIUpdateCheck(
|
||||||
channel = serverConfig.webUIChannel.value,
|
channel = serverConfig.webUIChannel.value,
|
||||||
tag = version,
|
tag = version,
|
||||||
updateAvailable,
|
updateAvailable,
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
package suwayomi.tachidesk.graphql.types
|
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(
|
data class WebUIUpdateInfo(
|
||||||
val channel: String,
|
val channel: String,
|
||||||
val tag: String,
|
val tag: String,
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import net.lingala.zip4j.ZipFile
|
|||||||
import org.kodein.di.DI
|
import org.kodein.di.DI
|
||||||
import org.kodein.di.conf.global
|
import org.kodein.di.conf.global
|
||||||
import org.kodein.di.instance
|
import org.kodein.di.instance
|
||||||
|
import suwayomi.tachidesk.graphql.types.AboutWebUI
|
||||||
import suwayomi.tachidesk.graphql.types.UpdateState
|
import suwayomi.tachidesk.graphql.types.UpdateState
|
||||||
import suwayomi.tachidesk.graphql.types.UpdateState.DOWNLOADING
|
import suwayomi.tachidesk.graphql.types.UpdateState.DOWNLOADING
|
||||||
import suwayomi.tachidesk.graphql.types.UpdateState.ERROR
|
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 currentVersion = getLocalVersion()
|
||||||
|
|
||||||
val failedToGetVersion = currentVersion === "r-1"
|
val failedToGetVersion = currentVersion === "r-1"
|
||||||
@@ -175,10 +176,9 @@ object WebInterfaceManager {
|
|||||||
throw Exception("Failed to get current version")
|
throw Exception("Failed to get current version")
|
||||||
}
|
}
|
||||||
|
|
||||||
return WebUIUpdateInfo(
|
return AboutWebUI(
|
||||||
channel = serverConfig.webUIChannel.value,
|
channel = serverConfig.webUIChannel.value,
|
||||||
tag = currentVersion,
|
tag = currentVersion,
|
||||||
updateAvailable = isUpdateAvailable(currentVersion).second,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,7 +661,10 @@ object WebInterfaceManager {
|
|||||||
ZipFile(zipFilePath).use { it.extractAll(targetPath) }
|
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 {
|
return try {
|
||||||
val latestCompatibleVersion = getLatestCompatibleVersion()
|
val latestCompatibleVersion = getLatestCompatibleVersion()
|
||||||
val isUpdateAvailable = latestCompatibleVersion != currentVersion
|
val isUpdateAvailable = latestCompatibleVersion != currentVersion
|
||||||
@@ -669,6 +672,11 @@ object WebInterfaceManager {
|
|||||||
Pair(latestCompatibleVersion, isUpdateAvailable)
|
Pair(latestCompatibleVersion, isUpdateAvailable)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.warn(e) { "isUpdateAvailable: check failed due to" }
|
logger.warn(e) { "isUpdateAvailable: check failed due to" }
|
||||||
|
|
||||||
|
if (raiseError) {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
|
||||||
Pair("", false)
|
Pair("", false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user