From d1b864c7df8f08f924117df05f1ab96207192c9e Mon Sep 17 00:00:00 2001 From: David Zwart Date: Tue, 16 Jan 2024 21:21:10 +0100 Subject: [PATCH 1/3] feat: allow downgrade of versions --- src/backend/app.service.ts | 7 +- .../Settings/SoftwareUpgradeSettings.vue | 121 ++++++++++++------ 2 files changed, 88 insertions(+), 40 deletions(-) diff --git a/src/backend/app.service.ts b/src/backend/app.service.ts index 6d454a2b..45cff889 100644 --- a/src/backend/app.service.ts +++ b/src/backend/app.service.ts @@ -5,8 +5,11 @@ import { IClientReleases } from "@/models/server/client-releases.model"; import { getHttpClient } from "@/shared/http-client"; export class AppService extends BaseService { - static async updateClientDistGithub(tag_name: string) { - return await this.postApi("api/server/update-client-bundle-github", { tag_name }); + static async updateClientDistGithub(version?: string, allowDowngrade?: boolean) { + return await this.postApi("api/server/update-client-bundle-github", { + downloadRelease: version, + allowDowngrade, + }); } static async getClientReleases() { diff --git a/src/components/Settings/SoftwareUpgradeSettings.vue b/src/components/Settings/SoftwareUpgradeSettings.vue index eb4688c3..5b0a6929 100644 --- a/src/components/Settings/SoftwareUpgradeSettings.vue +++ b/src/components/Settings/SoftwareUpgradeSettings.vue @@ -10,16 +10,16 @@ - Current versions: + Current versions in use: Your server's version is: {{ serverVersion }}
- Your clients's version is: {{ version }} + Your client's version is: {{ version }}
Your MonsterPi version is: {{ monsterPiVersion }}
- No MonsterPi distro detected. + No MonsterPi distro was detected.
@@ -51,32 +51,45 @@ Select a release to upgrade to: - - - - - + + Loading releases... + + + + + No releases to show.
- You are viewing prereleases, please install such versions at your own risk! + You are viewing prereleases, please install such versions at your own risk! +
+
+ + Reload release version list + upgrade - Upgrade client + Upgrade/downgrade client
@@ -99,10 +112,11 @@ import { version as packageJsonVersion } from "../../../package.json"; import { IRelease } from "@/models/server/client-releases.model"; import { compare, minor } from "semver"; +const loading = ref(true); +const allowDowngrade = ref(false); const serverVersion = ref(""); const monsterPiVersion = ref(""); const version = ref(packageJsonVersion); -const releases = ref([]); const current = ref(); const minimum = ref(); const selectedRelease = ref(); @@ -110,46 +124,77 @@ const showPrereleases = ref(false); const loadedClientReleases = ref([]); onMounted(async () => { - const clientReleases = await AppService.getClientReleases(); - current.value = clientReleases.current; - minimum.value = clientReleases.minimum; - loadedClientReleases.value = clientReleases.releases; + await loadReleases(); const versionSpec = await AppService.getVersion(); serverVersion.value = versionSpec.version; monsterPiVersion.value = versionSpec.monsterPi; }); +async function loadReleases() { + loading.value = true; + const clientReleases = await AppService.getClientReleases(); + current.value = clientReleases.current; + minimum.value = clientReleases.minimum; + loadedClientReleases.value = clientReleases.releases; + loading.value = false; +} + const filteredReleases = computed(() => { + const currentlyUnstable = isCurrentUnstable(); return loadedClientReleases.value.filter((release) => { const isMinimumVersion = minor(release.tag_name) === minor(minimum.value!.tag_name); - const isReleaseCandidate = - release.prerelease || - release.tag_name.includes("rc") || - release.tag_name.includes("unstable"); + const isReleaseCandidate = isVersionUnstable(release); const isDraft = release.draft; - return isMinimumVersion && (showPrereleases.value || !isReleaseCandidate) && !isDraft; + + return ( + isMinimumVersion && + (currentlyUnstable || showPrereleases.value || !isReleaseCandidate) && + !isDraft + ); }); }); -function isCurrentRelease(release: IRelease) { - return release.tag_name === current.value?.tag_name; +const getIsCurrentUnstable = computed(() => { + return isCurrentUnstable(); +}); + +function isCurrentUnstable() { + // Determine if current is rc/unstable, meaning we should ignore prerelease filter checkbox + const currentRelease = current.value; + return isVersionUnstable(currentRelease); } -function isDowngrade(release: IRelease, current?: IRelease) { +function isVersionUnstable(release?: IRelease) { + if (release?.tag_name.length) { + return ( + release.prerelease || release.tag_name.includes("rc") || release.tag_name.includes("unstable") + ); + } + return false; +} + +function isUpgradeOrAllowedDowngrade(release: IRelease, current?: IRelease) { // If no current release is known, we need to throw if (!current) { throw new Error("No current release is known, cannot compare."); } - return compare(release.tag_name, current.tag_name) === -1; + if (allowDowngrade.value) { + return true; + } + return compare(release.tag_name, current.tag_name) !== -1; +} + +function isCurrentRelease(release: IRelease) { + return release.tag_name === current.value?.tag_name; } -async function clickUpdateClient(tagName: string) { +async function clickUpdateClient(version?: string) { if (!confirm("Are you sure? This might cause breaking changes, if the server is outdated")) { return; } - await AppService.updateClientDistGithub(tagName); + await AppService.updateClientDistGithub(version, allowDowngrade.value); location.reload(); } From 801d55485e781e29c698ba34683e20cd2c53c616 Mon Sep 17 00:00:00 2001 From: David Zwart Date: Tue, 16 Jan 2024 22:36:03 +0100 Subject: [PATCH 2/3] fix: minimum required version not respected, detect current prerelease --- .../Settings/SoftwareUpgradeSettings.vue | 36 +++++++++++++------ src/components/TopBar.vue | 16 +++++++-- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/components/Settings/SoftwareUpgradeSettings.vue b/src/components/Settings/SoftwareUpgradeSettings.vue index 5b0a6929..a9531304 100644 --- a/src/components/Settings/SoftwareUpgradeSettings.vue +++ b/src/components/Settings/SoftwareUpgradeSettings.vue @@ -51,25 +51,34 @@ Select a release to upgrade to: + + Minimum required version: {{ minimum?.tag_name }} Loading releases... + No releases to show. - No releases to show.
You are viewing prereleases, please install such versions at your own risk! @@ -141,15 +150,14 @@ async function loadReleases() { } const filteredReleases = computed(() => { - const currentlyUnstable = isCurrentUnstable(); return loadedClientReleases.value.filter((release) => { - const isMinimumVersion = minor(release.tag_name) === minor(minimum.value!.tag_name); + const isMinimumVersionOrHigher = minor(release.tag_name) === minor(minimum.value!.tag_name); const isReleaseCandidate = isVersionUnstable(release); const isDraft = release.draft; return ( - isMinimumVersion && - (currentlyUnstable || showPrereleases.value || !isReleaseCandidate) && + isMinimumVersionOrHigher && + (isCurrentUnstable() || showPrereleases.value || !isReleaseCandidate) && !isDraft ); }); @@ -166,7 +174,7 @@ function isCurrentUnstable() { } function isVersionUnstable(release?: IRelease) { - if (release?.tag_name.length) { + if (release?.tag_name?.length) { return ( release.prerelease || release.tag_name.includes("rc") || release.tag_name.includes("unstable") ); @@ -174,6 +182,10 @@ function isVersionUnstable(release?: IRelease) { return false; } +function isBelowMinimum(release: IRelease) { + return compare(release.tag_name, minimum.value!.tag_name) === -1; +} + function isUpgradeOrAllowedDowngrade(release: IRelease, current?: IRelease) { // If no current release is known, we need to throw if (!current) { @@ -182,7 +194,11 @@ function isUpgradeOrAllowedDowngrade(release: IRelease, current?: IRelease) { if (allowDowngrade.value) { return true; } - return compare(release.tag_name, current.tag_name) !== -1; + + return ( + compare(release.tag_name, current.tag_name) !== -1 && + compare(minimum.value!.tag_name, current.tag_name) !== -1 + ); } function isCurrentRelease(release: IRelease) { diff --git a/src/components/TopBar.vue b/src/components/TopBar.vue index 68da6365..46183b84 100644 --- a/src/components/TopBar.vue +++ b/src/components/TopBar.vue @@ -50,7 +50,14 @@ help - + Close Help close @@ -61,7 +68,12 @@ Showing help from docs.fdm-monster.net -