Skip to content

Commit

Permalink
Feature/webui update download failure do not immediately fallback to …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
schroda authored Jul 30, 2023
1 parent 47e5b03 commit a2715fb
Showing 1 changed file with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

/**
* 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
}

val fallbackToDefaultWebUI = !downloadSucceeded
// download the latest compatible version for the current selected webUI
val fallbackToDefaultWebUI = !doDownload()
if (!fallbackToDefaultWebUI) {
return
}
Expand All @@ -141,7 +155,7 @@ object WebInterfaceManager {

serverConfig.webUIFlavor = DEFAULT_WEB_UI

val fallbackToBundledVersion = !downloadLatestCompatibleVersion()
val fallbackToBundledVersion = !doDownload()
if (!fallbackToBundledVersion) {
return
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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" }
Expand Down

0 comments on commit a2715fb

Please sign in to comment.