diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt index e733ab9d..b8fe8778 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt @@ -129,9 +129,23 @@ object WebInterfaceManager { * Tries to download the latest compatible version for the selected webUI and falls back to the default webUI in case of errors. */ private fun doInitialSetup() { - val downloadSucceeded = downloadLatestCompatibleVersion() + val isLocalWebUIValid = isLocalWebUIValid(applicationDirs.webUIRoot) - val fallbackToDefaultWebUI = !downloadSucceeded + /** + * Performs the download and returns if the download was successful. + * + * In case the download failed but the local webUI is valid the download is considered a success to prevent the fallback logic + */ + val doDownload = { + try { + downloadLatestCompatibleVersion() + } catch (e: Exception) { + false + } || isLocalWebUIValid + } + + // download the latest compatible version for the current selected webUI + val fallbackToDefaultWebUI = !doDownload() if (!fallbackToDefaultWebUI) { return } @@ -141,7 +155,7 @@ object WebInterfaceManager { serverConfig.webUIFlavor = DEFAULT_WEB_UI - val fallbackToBundledVersion = !downloadLatestCompatibleVersion() + val fallbackToBundledVersion = !doDownload() if (!fallbackToBundledVersion) { return } @@ -186,9 +200,8 @@ object WebInterfaceManager { private fun getDownloadUrlFor(version: String): String { val baseReleasesUrl = "${WebUI.WEBUI.repoUrl}/releases" val downloadSpecificVersionBaseUrl = "$baseReleasesUrl/download" - val downloadLatestVersionBaseUrl = "$baseReleasesUrl/latest/download" - return if (version == webUIPreviewVersion) downloadLatestVersionBaseUrl else "$downloadSpecificVersionBaseUrl/$version" + return "$downloadSpecificVersionBaseUrl/$version" } private fun getLocalVersion(path: String): String { @@ -267,13 +280,15 @@ object WebInterfaceManager { for (i in 0 until webUIToServerVersionMappings.length()) { val webUIToServerVersionEntry = webUIToServerVersionMappings.getJSONObject(i) - val webUIVersion = webUIToServerVersionEntry.getString("uiVersion") + var webUIVersion = webUIToServerVersionEntry.getString("uiVersion") val minServerVersionString = webUIToServerVersionEntry.getString("serverVersion") val minServerVersionNumber = extractVersion(minServerVersionString) val ignorePreviewVersion = !WebUIChannel.doesConfigChannelEqual(WebUIChannel.PREVIEW) && webUIVersion == webUIPreviewVersion if (ignorePreviewVersion) { continue + } else { + webUIVersion = fetchPreviewVersion() } val isCompatibleVersion = minServerVersionNumber <= currentServerVersionNumber @@ -286,17 +301,7 @@ object WebInterfaceManager { } fun downloadLatestCompatibleVersion(retryCount: Int = 0): Boolean { - val latestCompatibleVersion = try { - val version = getLatestCompatibleVersion() - - if (version == webUIPreviewVersion) { - fetchPreviewVersion() - } else { - version - } - } catch (e: Exception) { - BuildConfig.WEBUI_TAG - } + val latestCompatibleVersion = getLatestCompatibleVersion() val webUIZip = "${WebUI.WEBUI.baseFileName}-$latestCompatibleVersion.zip" val webUIZipPath = "$tmpDir/$webUIZip" @@ -385,13 +390,7 @@ object WebInterfaceManager { fun isUpdateAvailable(currentVersion: String): Boolean { return try { - val version = getLatestCompatibleVersion() - val latestCompatibleVersion = if (version == webUIPreviewVersion) { - fetchPreviewVersion() - } else { - version - } - + val latestCompatibleVersion = getLatestCompatibleVersion() latestCompatibleVersion != currentVersion } catch (e: Exception) { logger.debug { "isUpdateAvailable: check failed due to $e" }