Browse Source

Merge pull request #3543 from nocodb/fix/version-api-block

fix: version info implement timeout and cache
pull/3547/head
navi 2 years ago committed by GitHub
parent
commit
c888c18c6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/nc-gui/components.d.ts
  2. 1
      packages/nc-gui/components/smartsheet-toolbar/ViewActions.vue
  3. 43
      packages/nocodb/src/lib/meta/api/utilApis.ts

1
packages/nc-gui/components.d.ts vendored

@ -107,6 +107,7 @@ declare module '@vue/runtime-core' {
MdiAccountPlus: typeof import('~icons/mdi/account-plus')['default']
MdiAccountPlusOutline: typeof import('~icons/mdi/account-plus-outline')['default']
MdiAccountSupervisorOutline: typeof import('~icons/mdi/account-supervisor-outline')['default']
MdiAlpha: typeof import('~icons/mdi/alpha')['default']
MdiAlphaA: typeof import('~icons/mdi/alpha-a')['default']
MdiApi: typeof import('~icons/mdi/api')['default']
MdiArrowExpand: typeof import('~icons/mdi/arrow-expand')['default']

1
packages/nc-gui/components/smartsheet-toolbar/ViewActions.vue

@ -171,6 +171,7 @@ const { isSqlView } = useSmartsheetStoreOrThrow()
<MdiUploadOutline class="text-gray-500" />
<!-- Upload CSV -->
{{ $t('activity.uploadCSV') }}
<div class="flex items-center text-gray-400"><MdiAlpha />version</div>
</div>
</a-menu-item>
</a-sub-menu>

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

@ -4,11 +4,18 @@ import { Request, Response } from 'express';
import { packageVersion } from 'nc-help';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import SqlMgrv2 from '../../db/sql-mgr/v2/SqlMgrv2';
import NcConfigFactory, { defaultConnectionConfig } from '../../utils/NcConfigFactory';
import NcConfigFactory, {
defaultConnectionConfig,
} from '../../utils/NcConfigFactory';
import User from '../../models/User';
import catchError from '../helpers/catchError';
import axios from 'axios';
const versionCache = {
releaseVersion: null,
lastFetched: null,
};
export async function testConnection(req: Request, res: Response) {
res.json(await SqlMgrv2.testConnection(req.body));
}
@ -46,19 +53,31 @@ export async function appInfo(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(
if (
!versionCache.lastFetched ||
(versionCache.lastFetched &&
versionCache.lastFetched < Date.now() - 1000 * 60 * 60)
) {
versionCache.releaseVersion = await axios
.get('https://github.com/nocodb/nocodb/releases/latest', {
timeout: 5000,
})
.then((response) =>
response.request.res.responseUrl.replace(
'https://github.com/nocodb/nocodb/releases/tag/',
''
),
};
});
)
)
.catch(() => null);
versionCache.lastFetched = Date.now();
}
res.json(result);
const response = {
currentVersion: packageVersion,
releaseVersion: versionCache.releaseVersion,
};
res.json(response);
}
export async function feedbackFormGet(_req: Request, res: Response) {
@ -154,7 +173,7 @@ export async function urlToDbConfig(req: Request, res: Response) {
connectionConfig = NcConfigFactory.extractXcUrlFromJdbc(url, true);
return res.json(connectionConfig);
} catch (error) {
return res.sendStatus(500)
return res.sendStatus(500);
}
}

Loading…
Cancel
Save