From 27a088a6a1ea30c160934fda530328df93e55c76 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 4 Oct 2023 03:13:20 +0200 Subject: [PATCH] [client] Improved update checker --- packages/client/src/pages/admin/index.vue | 23 +++++++++++++---- packages/client/src/ui/_common_/navbar.vue | 29 ++++++++++++++++------ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/packages/client/src/pages/admin/index.vue b/packages/client/src/pages/admin/index.vue index 34c3374d6..de34071cb 100644 --- a/packages/client/src/pages/admin/index.vue +++ b/packages/client/src/pages/admin/index.vue @@ -127,11 +127,24 @@ os.api("admin/abuse-user-reports", { if (defaultStore.state.showAdminUpdates) { os.api("latest-version").then((res) => { - const cleanRes = parseInt(res?.tag_name.replace(/[^0-9]/g, "")); - const cleanVersion = parseInt(version.replace(/[^0-9]/g, "")); - if (cleanRes > cleanVersion) { - updateAvailable = true; - } + if (!res?.tag_name) { + updateAvailable = false; + return; + } + + const tag = res.tag_name as string; + if (tag === `v${version}`) { + updateAvailable = false; + return; + } + const tagDate = tag.includes('-') ? tag.substring(0, tag.indexOf('-')) : tag; + const versionDate = version.includes('-') ? version.substring(0, version.indexOf('-')) : version; + if (tagDate < versionDate) { + updateAvailable = false; + return; + } + updateAvailable = true; + return; }); } diff --git a/packages/client/src/ui/_common_/navbar.vue b/packages/client/src/ui/_common_/navbar.vue index 5a631de3b..822bb70f3 100644 --- a/packages/client/src/ui/_common_/navbar.vue +++ b/packages/client/src/ui/_common_/navbar.vue @@ -193,16 +193,29 @@ if ($i?.isAdmin) { }).then((reports) => { if (reports?.length > 0) thereIsUnresolvedAbuseReport = true; }); -} -if (defaultStore.state.showAdminUpdates) { - os.api("latest-version").then((res) => { - const cleanRes = parseInt(res?.tag_name.replace(/[^0-9]/g, "")); - const cleanVersion = parseInt(version.replace(/[^0-9]/g, "")); - if (cleanRes > cleanVersion) { + if (defaultStore.state.showAdminUpdates) { + os.api("latest-version").then((res) => { + if (!res?.tag_name) { + updateAvailable = false; + return; + } + + const tag = res.tag_name as string; + if (tag === `v${version}`) { + updateAvailable = false; + return; + } + const tagDate = tag.includes('-') ? tag.substring(0, tag.indexOf('-')) : tag; + const versionDate = version.includes('-') ? version.substring(0, version.indexOf('-')) : version; + if (tagDate < versionDate) { + updateAvailable = false; + return; + } updateAvailable = true; - } - }); + return; + }); + } } function openAccountMenu(ev: MouseEvent) {