From bade983b27b64d553c4b0eee87a62e9d63c730ed Mon Sep 17 00:00:00 2001 From: mertmit Date: Fri, 15 Jul 2022 08:51:19 +0300 Subject: [PATCH 1/3] refactor: version api Signed-off-by: mertmit --- packages/nc-gui/components/ReleaseInfo.vue | 6 +++--- packages/nc-gui/plugins/projectLoader.js | 14 ++++++-------- packages/nc-gui/store/app.js | 6 +++--- packages/nocodb/src/lib/meta/api/utilApis.ts | 5 +++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/nc-gui/components/ReleaseInfo.vue b/packages/nc-gui/components/ReleaseInfo.vue index 65a744e17b..94969a355d 100644 --- a/packages/nc-gui/components/ReleaseInfo.vue +++ b/packages/nc-gui/components/ReleaseInfo.vue @@ -42,9 +42,9 @@ export default { get() { return ( !this.loading && - this.$store.state.app.releaseVersion && + this.$store.state.app.currentVersion && this.$store.state.app.latestRelease && - this.$store.state.app.releaseVersion !== this.$store.state.app.latestRelease && + this.$store.state.app.currentVersion !== this.$store.state.app.latestRelease && this.$store.state.app.latestRelease !== this.$store.state.app.hiddenRelease ); }, @@ -53,7 +53,7 @@ export default { }, }, releaseVersion() { - return this.$store.state.app.releaseVersion; + return this.$store.state.app.latestRelease; }, }, mounted() { diff --git a/packages/nc-gui/plugins/projectLoader.js b/packages/nc-gui/plugins/projectLoader.js index 90bcbe3a5d..473d494630 100644 --- a/packages/nc-gui/plugins/projectLoader.js +++ b/packages/nc-gui/plugins/projectLoader.js @@ -63,13 +63,12 @@ export default async({ store, redirect, $axios, $toast, $api, route }) => { // fetch latest release info const fetchReleaseInfo = async() => { try { - const releaseInfo = await $api.utils.appInfo() - const latestRelease = await $api.utils.appVersion() - if (releaseInfo && latestRelease && releaseInfo.version) { - store.commit('app/MutReleaseVersion', releaseInfo.version) - store.commit('app/MutLatestRelease', latestRelease.releaseVersion || null) + const versionInfo = await $api.utils.appVersion() + if (versionInfo && versionInfo.releaseVersion && versionInfo.currentVersion) { + store.commit('app/MutCurrentVersion', versionInfo.currentVersion) + store.commit('app/MutLatestRelease', versionInfo.releaseVersion || null) } else { - store.commit('app/MutReleaseVersion', null) + store.commit('app/MutCurrentVersion', null) store.commit('app/MutLatestRelease', null) } } catch (e) { @@ -77,8 +76,7 @@ export default async({ store, redirect, $axios, $toast, $api, route }) => { } } - fetchReleaseInfo().then(() => { - }) + fetchReleaseInfo() setInterval(fetchReleaseInfo, 10 * 60 * 1000) } /** diff --git a/packages/nc-gui/store/app.js b/packages/nc-gui/store/app.js index 8e175eef52..47cad17b95 100644 --- a/packages/nc-gui/store/app.js +++ b/packages/nc-gui/store/app.js @@ -1,12 +1,12 @@ export const state = () => ({ - releaseVersion: null, + currentVersion: null, hiddenRelease: null, latestRelease: null }) export const mutations = { - MutReleaseVersion(state, releaseVersion) { - state.releaseVersion = releaseVersion + MutCurrentVersion(state, currentVersion) { + state.currentVersion = currentVersion }, MutHiddenRelease(state, hiddenRelease) { state.hiddenRelease = hiddenRelease diff --git a/packages/nocodb/src/lib/meta/api/utilApis.ts b/packages/nocodb/src/lib/meta/api/utilApis.ts index 5bd30b974b..6f72e5c4f4 100644 --- a/packages/nocodb/src/lib/meta/api/utilApis.ts +++ b/packages/nocodb/src/lib/meta/api/utilApis.ts @@ -45,11 +45,12 @@ export async function appInfo(req: Request, res: Response) { res.json(result); } -export async function releaseVersion(_req: Request, res: Response) { +export async function versionInfo(_req: Request, res: Response) { const result = await axios .get('https://github.com/nocodb/nocodb/releases/latest') .then((response) => { return { + currentVersion: packageVersion, releaseVersion: response.request.res.responseUrl.replace( 'https://github.com/nocodb/nocodb/releases/tag/', '' @@ -142,6 +143,6 @@ export default (router) => { ); router.get('/api/v1/db/meta/nocodb/info', catchError(appInfo)); router.post('/api/v1/db/meta/axiosRequestMake', catchError(axiosRequestMake)); - router.get('/api/v1/version', catchError(releaseVersion)); + router.get('/api/v1/version', catchError(versionInfo)); router.get('/api/v1/health', catchError(appHealth)); }; From 964bc7084bde1c529255bc5833c0857702fb6da6 Mon Sep 17 00:00:00 2001 From: mertmit Date: Fri, 15 Jul 2022 11:00:44 +0300 Subject: [PATCH 2/3] feat: hide upgrade alert for timely/pr builds Signed-off-by: mertmit --- packages/nc-gui/plugins/projectLoader.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/nc-gui/plugins/projectLoader.js b/packages/nc-gui/plugins/projectLoader.js index 473d494630..a53747b2b6 100644 --- a/packages/nc-gui/plugins/projectLoader.js +++ b/packages/nc-gui/plugins/projectLoader.js @@ -64,7 +64,10 @@ export default async({ store, redirect, $axios, $toast, $api, route }) => { const fetchReleaseInfo = async() => { try { const versionInfo = await $api.utils.appVersion() - if (versionInfo && versionInfo.releaseVersion && versionInfo.currentVersion) { + if (versionInfo && + versionInfo.releaseVersion && + versionInfo.currentVersion && + !(/[^0-9.]/.test(versionInfo.currentVersion))) { store.commit('app/MutCurrentVersion', versionInfo.currentVersion) store.commit('app/MutLatestRelease', versionInfo.releaseVersion || null) } else { From bf76480c51ddb3b0233d545227f87954ff5623be Mon Sep 17 00:00:00 2001 From: mertmit Date: Fri, 15 Jul 2022 13:43:02 +0300 Subject: [PATCH 3/3] fix: remove unnecessary code Signed-off-by: mertmit --- packages/nc-gui/plugins/projectLoader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nc-gui/plugins/projectLoader.js b/packages/nc-gui/plugins/projectLoader.js index a53747b2b6..08a150e0ba 100644 --- a/packages/nc-gui/plugins/projectLoader.js +++ b/packages/nc-gui/plugins/projectLoader.js @@ -69,7 +69,7 @@ export default async({ store, redirect, $axios, $toast, $api, route }) => { versionInfo.currentVersion && !(/[^0-9.]/.test(versionInfo.currentVersion))) { store.commit('app/MutCurrentVersion', versionInfo.currentVersion) - store.commit('app/MutLatestRelease', versionInfo.releaseVersion || null) + store.commit('app/MutLatestRelease', versionInfo.releaseVersion) } else { store.commit('app/MutCurrentVersion', null) store.commit('app/MutLatestRelease', null)