mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-03 10:54:38 -05:00
Feature/webui update download failure do not immediately fallback to bundled version (#620)
* Return actual version for "PREVIEW" in "getLatestCompatibleVersion" In case "PREVIEW" is the latest available version, the function should immediately fetch the actual webUI version that is currently the latest released version. Thus, the function always returns a valid version and the preview version has not to be considered anymore at other places in the code * Ignore download failure in case local webUI version is valid In case the download failed e.g. due to internet connection issues, the server should only fall back to another version in case the local version is invalid or missing
This commit is contained in:
@@ -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.
|
* 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() {
|
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) {
|
if (!fallbackToDefaultWebUI) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -141,7 +155,7 @@ object WebInterfaceManager {
|
|||||||
|
|
||||||
serverConfig.webUIFlavor = DEFAULT_WEB_UI
|
serverConfig.webUIFlavor = DEFAULT_WEB_UI
|
||||||
|
|
||||||
val fallbackToBundledVersion = !downloadLatestCompatibleVersion()
|
val fallbackToBundledVersion = !doDownload()
|
||||||
if (!fallbackToBundledVersion) {
|
if (!fallbackToBundledVersion) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -186,9 +200,8 @@ object WebInterfaceManager {
|
|||||||
private fun getDownloadUrlFor(version: String): String {
|
private fun getDownloadUrlFor(version: String): String {
|
||||||
val baseReleasesUrl = "${WebUI.WEBUI.repoUrl}/releases"
|
val baseReleasesUrl = "${WebUI.WEBUI.repoUrl}/releases"
|
||||||
val downloadSpecificVersionBaseUrl = "$baseReleasesUrl/download"
|
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 {
|
private fun getLocalVersion(path: String): String {
|
||||||
@@ -267,13 +280,15 @@ object WebInterfaceManager {
|
|||||||
|
|
||||||
for (i in 0 until webUIToServerVersionMappings.length()) {
|
for (i in 0 until webUIToServerVersionMappings.length()) {
|
||||||
val webUIToServerVersionEntry = webUIToServerVersionMappings.getJSONObject(i)
|
val webUIToServerVersionEntry = webUIToServerVersionMappings.getJSONObject(i)
|
||||||
val webUIVersion = webUIToServerVersionEntry.getString("uiVersion")
|
var webUIVersion = webUIToServerVersionEntry.getString("uiVersion")
|
||||||
val minServerVersionString = webUIToServerVersionEntry.getString("serverVersion")
|
val minServerVersionString = webUIToServerVersionEntry.getString("serverVersion")
|
||||||
val minServerVersionNumber = extractVersion(minServerVersionString)
|
val minServerVersionNumber = extractVersion(minServerVersionString)
|
||||||
|
|
||||||
val ignorePreviewVersion = !WebUIChannel.doesConfigChannelEqual(WebUIChannel.PREVIEW) && webUIVersion == webUIPreviewVersion
|
val ignorePreviewVersion = !WebUIChannel.doesConfigChannelEqual(WebUIChannel.PREVIEW) && webUIVersion == webUIPreviewVersion
|
||||||
if (ignorePreviewVersion) {
|
if (ignorePreviewVersion) {
|
||||||
continue
|
continue
|
||||||
|
} else {
|
||||||
|
webUIVersion = fetchPreviewVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
val isCompatibleVersion = minServerVersionNumber <= currentServerVersionNumber
|
val isCompatibleVersion = minServerVersionNumber <= currentServerVersionNumber
|
||||||
@@ -286,17 +301,7 @@ object WebInterfaceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun downloadLatestCompatibleVersion(retryCount: Int = 0): Boolean {
|
fun downloadLatestCompatibleVersion(retryCount: Int = 0): Boolean {
|
||||||
val latestCompatibleVersion = try {
|
val latestCompatibleVersion = getLatestCompatibleVersion()
|
||||||
val version = getLatestCompatibleVersion()
|
|
||||||
|
|
||||||
if (version == webUIPreviewVersion) {
|
|
||||||
fetchPreviewVersion()
|
|
||||||
} else {
|
|
||||||
version
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
BuildConfig.WEBUI_TAG
|
|
||||||
}
|
|
||||||
|
|
||||||
val webUIZip = "${WebUI.WEBUI.baseFileName}-$latestCompatibleVersion.zip"
|
val webUIZip = "${WebUI.WEBUI.baseFileName}-$latestCompatibleVersion.zip"
|
||||||
val webUIZipPath = "$tmpDir/$webUIZip"
|
val webUIZipPath = "$tmpDir/$webUIZip"
|
||||||
@@ -385,13 +390,7 @@ object WebInterfaceManager {
|
|||||||
|
|
||||||
fun isUpdateAvailable(currentVersion: String): Boolean {
|
fun isUpdateAvailable(currentVersion: String): Boolean {
|
||||||
return try {
|
return try {
|
||||||
val version = getLatestCompatibleVersion()
|
val latestCompatibleVersion = getLatestCompatibleVersion()
|
||||||
val latestCompatibleVersion = if (version == webUIPreviewVersion) {
|
|
||||||
fetchPreviewVersion()
|
|
||||||
} else {
|
|
||||||
version
|
|
||||||
}
|
|
||||||
|
|
||||||
latestCompatibleVersion != currentVersion
|
latestCompatibleVersion != currentVersion
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.debug { "isUpdateAvailable: check failed due to $e" }
|
logger.debug { "isUpdateAvailable: check failed due to $e" }
|
||||||
|
|||||||
Reference in New Issue
Block a user