Browse Source

Merge pull request #2686 from nocodb/refactor/version

refactor: version api
pull/2693/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
f579907d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      packages/nc-gui/components/ReleaseInfo.vue
  2. 17
      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() {

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

@ -68,13 +68,15 @@ 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 &&
if (releaseInfo && latestRelease && releaseInfo.version) { versionInfo.releaseVersion &&
store.commit('app/MutReleaseVersion', releaseInfo.version) versionInfo.currentVersion &&
store.commit('app/MutLatestRelease', latestRelease.releaseVersion || null) !(/[^0-9.]/.test(versionInfo.currentVersion))) {
store.commit('app/MutCurrentVersion', versionInfo.currentVersion)
store.commit('app/MutLatestRelease', versionInfo.releaseVersion)
} 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) {
@ -82,8 +84,7 @@ export default async({ store, redirect, $axios, $toast, $api, route }) => {
} }
} }
fetchReleaseInfo().then(() => { fetchReleaseInfo()
})
setInterval(fetchReleaseInfo, 10 * 60 * 1000) setInterval(fetchReleaseInfo, 10 * 60 * 1000)
handleFeedbackForm({ store, $axios }) handleFeedbackForm({ store, $axios })
} }

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/',
'' ''
@ -153,7 +154,7 @@ 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));
router.get('/api/v1/feedback_form', catchError(feedbackFormGet)); router.get('/api/v1/feedback_form', catchError(feedbackFormGet));
}; };

Loading…
Cancel
Save