Browse Source

refactor: version api

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/2686/head
mertmit 2 years ago
parent
commit
bade983b27
  1. 6
      packages/nc-gui/components/ReleaseInfo.vue
  2. 14
      packages/nc-gui/plugins/projectLoader.js
  3. 6
      packages/nc-gui/store/app.js
  4. 5
      packages/nocodb/src/lib/meta/api/utilApis.ts

6
packages/nc-gui/components/ReleaseInfo.vue

@ -42,9 +42,9 @@ export default {
get() { get() {
return ( return (
!this.loading && !this.loading &&
this.$store.state.app.releaseVersion && this.$store.state.app.currentVersion &&
this.$store.state.app.latestRelease && 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 this.$store.state.app.latestRelease !== this.$store.state.app.hiddenRelease
); );
}, },
@ -53,7 +53,7 @@ export default {
}, },
}, },
releaseVersion() { releaseVersion() {
return this.$store.state.app.releaseVersion; return this.$store.state.app.latestRelease;
}, },
}, },
mounted() { mounted() {

14
packages/nc-gui/plugins/projectLoader.js

@ -63,13 +63,12 @@ export default async({ store, redirect, $axios, $toast, $api, route }) => {
// fetch latest release info // fetch latest release info
const fetchReleaseInfo = async() => { const fetchReleaseInfo = async() => {
try { try {
const releaseInfo = await $api.utils.appInfo() const versionInfo = await $api.utils.appVersion()
const latestRelease = await $api.utils.appVersion() if (versionInfo && versionInfo.releaseVersion && versionInfo.currentVersion) {
if (releaseInfo && latestRelease && releaseInfo.version) { store.commit('app/MutCurrentVersion', versionInfo.currentVersion)
store.commit('app/MutReleaseVersion', releaseInfo.version) store.commit('app/MutLatestRelease', versionInfo.releaseVersion || null)
store.commit('app/MutLatestRelease', latestRelease.releaseVersion || null)
} else { } else {
store.commit('app/MutReleaseVersion', null) store.commit('app/MutCurrentVersion', null)
store.commit('app/MutLatestRelease', null) store.commit('app/MutLatestRelease', null)
} }
} catch (e) { } catch (e) {
@ -77,8 +76,7 @@ export default async({ store, redirect, $axios, $toast, $api, route }) => {
} }
} }
fetchReleaseInfo().then(() => { fetchReleaseInfo()
})
setInterval(fetchReleaseInfo, 10 * 60 * 1000) setInterval(fetchReleaseInfo, 10 * 60 * 1000)
} }
/** /**

6
packages/nc-gui/store/app.js

@ -1,12 +1,12 @@
export const state = () => ({ export const state = () => ({
releaseVersion: null, currentVersion: null,
hiddenRelease: null, hiddenRelease: null,
latestRelease: null latestRelease: null
}) })
export const mutations = { export const mutations = {
MutReleaseVersion(state, releaseVersion) { MutCurrentVersion(state, currentVersion) {
state.releaseVersion = releaseVersion state.currentVersion = currentVersion
}, },
MutHiddenRelease(state, hiddenRelease) { MutHiddenRelease(state, hiddenRelease) {
state.hiddenRelease = hiddenRelease state.hiddenRelease = hiddenRelease

5
packages/nocodb/src/lib/meta/api/utilApis.ts

@ -45,11 +45,12 @@ export async function appInfo(req: Request, res: Response) {
res.json(result); res.json(result);
} }
export async function releaseVersion(_req: Request, res: Response) { export async function versionInfo(_req: Request, res: Response) {
const result = await axios const result = await axios
.get('https://github.com/nocodb/nocodb/releases/latest') .get('https://github.com/nocodb/nocodb/releases/latest')
.then((response) => { .then((response) => {
return { return {
currentVersion: packageVersion,
releaseVersion: response.request.res.responseUrl.replace( releaseVersion: response.request.res.responseUrl.replace(
'https://github.com/nocodb/nocodb/releases/tag/', '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.get('/api/v1/db/meta/nocodb/info', catchError(appInfo));
router.post('/api/v1/db/meta/axiosRequestMake', catchError(axiosRequestMake)); 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)); router.get('/api/v1/health', catchError(appHealth));
}; };

Loading…
Cancel
Save