Browse Source

feat: Add latest release info spi

Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
pull/362/head
Pranav C 3 years ago
parent
commit
68ef936b4b
  1. 8
      packages/nocodb/package-lock.json
  2. 2
      packages/nocodb/package.json
  3. 84
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
  4. 4
      packages/nocodb/src/lib/noco/plugins/adapters/cache/XcCache.ts

8
packages/nocodb/package-lock.json generated

@ -1,6 +1,6 @@
{ {
"name": "nocodb", "name": "nocodb",
"version": "0.10.5", "version": "0.10.6",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -11800,9 +11800,9 @@
"integrity": "sha512-3AryS9uwa5NfISLxMciUonrH7YfXp+nlahB9T7girXIsLQrmwX4MdnuKs32akduCOGpKmjTJSWmATULbuMkbfw==" "integrity": "sha512-3AryS9uwa5NfISLxMciUonrH7YfXp+nlahB9T7girXIsLQrmwX4MdnuKs32akduCOGpKmjTJSWmATULbuMkbfw=="
}, },
"nc-help": { "nc-help": {
"version": "0.2.4", "version": "0.2.7",
"resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.4.tgz", "resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.7.tgz",
"integrity": "sha512-kwNlE+2U1ZLIp+ct3yh5ihQO81dXqiqUpJ5JezzJ00y5pu6P5R9gdY1LiVTrLawZoHXxsNlFQVTWw67P07Y5AQ==", "integrity": "sha512-31wxoJmfZHJ4aP/YiI+GgZRqwulyB6Z5BamcCUw/NDdNVoze+zHX0CtmoxfSlyi/U4zUOG9rhennKPv6QmmsMQ==",
"requires": { "requires": {
"axios": "^0.21.1", "axios": "^0.21.1",
"boxen": "^4.2.0", "boxen": "^4.2.0",

2
packages/nocodb/package.json

@ -144,7 +144,7 @@
"mysql2": "^2.2.5", "mysql2": "^2.2.5",
"nanoid": "^3.1.20", "nanoid": "^3.1.20",
"nc-common": "0.0.6", "nc-common": "0.0.6",
"nc-help": "^0.2.4", "nc-help": "^0.2.7",
"nc-lib-gui": "^0.2.7", "nc-lib-gui": "^0.2.7",
"nc-plugin": "^0.1.1", "nc-plugin": "^0.1.1",
"nodemailer": "^6.4.10", "nodemailer": "^6.4.10",

84
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -34,17 +34,12 @@ import EmailFactory from "../plugins/adapters/email/EmailFactory";
import Twilio from "../plugins/adapters/twilio/Twilio"; import Twilio from "../plugins/adapters/twilio/Twilio";
import {RestApiBuilder} from "../rest/RestApiBuilder"; import {RestApiBuilder} from "../rest/RestApiBuilder";
import RestAuthCtrl from "../rest/RestAuthCtrlEE"; import RestAuthCtrl from "../rest/RestAuthCtrlEE";
import {packageVersion} from 'nc-help';
import NcMetaIO, {META_TABLES} from "./NcMetaIO"; import NcMetaIO, {META_TABLES} from "./NcMetaIO";
const XC_PLUGIN_DET = 'XC_PLUGIN_DET'; const XC_PLUGIN_DET = 'XC_PLUGIN_DET';
const NOCO_RELEASE = 'NOCO_RELEASE';
let packageInfo: any = {};
try {
packageInfo = JSON.parse(fs.readFileSync('package.json', 'utf8'));
} catch (_e) {
}
export default class NcMetaMgr { export default class NcMetaMgr {
public projectConfigs = {}; public projectConfigs = {};
@ -60,7 +55,7 @@ export default class NcMetaMgr {
protected projectMgr: any; protected projectMgr: any;
// @ts-ignore // @ts-ignore
protected isEe = false; protected isEe = false;
4
constructor(app: Noco, config: NcConfig, xcMeta: NcMetaIO) { constructor(app: Noco, config: NcConfig, xcMeta: NcMetaIO) {
this.app = app; this.app = app;
@ -78,8 +73,6 @@ export default class NcMetaMgr {
await this.pluginMgr?.init(); await this.pluginMgr?.init();
await this.initStorage();
await this.initEmail();
await this.initTwilio(); await this.initTwilio();
await this.initCache(); await this.initCache();
this.eeVerify(); this.eeVerify();
@ -223,7 +216,7 @@ export default class NcMetaMgr {
githubAuthEnabled: !!(process.env.NC_GITHUB_CLIENT_ID && process.env.NC_GITHUB_CLIENT_SECRET), githubAuthEnabled: !!(process.env.NC_GITHUB_CLIENT_ID && process.env.NC_GITHUB_CLIENT_SECRET),
oneClick: !!process.env.NC_ONE_CLICK, oneClick: !!process.env.NC_ONE_CLICK,
connectToExternalDB: !process.env.NC_CONNECT_TO_EXTERNAL_DB_DISABLED, connectToExternalDB: !process.env.NC_CONNECT_TO_EXTERNAL_DB_DISABLED,
version: packageInfo?.version version: packageVersion
}) })
} }
if (this.config.auth.masterKey) { if (this.config.auth.masterKey) {
@ -964,28 +957,6 @@ export default class NcMetaMgr {
} }
} }
protected async initStorage(_overwrite = false): Promise<void> {
//
// const activeStorage = await this.xcMeta.metaGet(null, null, 'nc_plugins', {
// active: true,
// category: 'Storage'
// });
//
// this.storageAdapter = StorageFactory.create(activeStorage, overwrite);
// await this.storageAdapter?.init();
}
protected async initEmail(_overwrite = false): Promise<void> {
// const activeStorage = await this.xcMeta.metaGet(null, null, 'nc_plugins', {
// active: true,
// category: 'Email'
// });
//
// this.emailAdapter = EmailFactory.create(activeStorage, overwrite);
// await this.emailAdapter?.init();
}
protected async initTwilio(overwrite = false): Promise<void> { protected async initTwilio(overwrite = false): Promise<void> {
const activeStorage = await this.xcMeta.metaGet(null, null, 'nc_plugins', { const activeStorage = await this.xcMeta.metaGet(null, null, 'nc_plugins', {
@ -1018,6 +989,9 @@ export default class NcMetaMgr {
case 'getSharedViewData': case 'getSharedViewData':
result = await this.getSharedViewData(req, args); result = await this.getSharedViewData(req, args);
break; break;
case 'xcRelease':
result = await this.xcRelease();
break;
default: default:
return next(); return next();
@ -3475,7 +3449,7 @@ export default class NcMetaMgr {
Database: config.envs?.[process.env.NODE_ENV || 'dev']?.db?.[0]?.client, Database: config.envs?.[process.env.NODE_ENV || 'dev']?.db?.[0]?.client,
'ProjectOnRootDB': !!config?.prefix, 'ProjectOnRootDB': !!config?.prefix,
'RootDB': this.config?.meta?.db?.client, 'RootDB': this.config?.meta?.db?.client,
'PackageVersion': packageInfo?.version 'PackageVersion': packageVersion
} }
} }
@ -3576,6 +3550,48 @@ export default class NcMetaMgr {
return this.pluginMgr?.webhookNotificationAdapters; return this.pluginMgr?.webhookNotificationAdapters;
} }
private async xcRelease() {
const cachedResult = XcCache.get(NOCO_RELEASE);
if (cachedResult) {
return cachedResult;
}
const result: any = {
current: packageVersion,
isDocker: isDocker()
};
try {
const dockerTags = (await axios({
url: 'https://registry.hub.docker.com/v1/repositories/nocodb/nocodb/tags'
})).data;
const verPattern = /^(\d+)\.(\d+)\.(\d+)$/;
result.docker = dockerTags.sort((a, b): any => {
const m1: any = a.name.match(verPattern);
const m2: any = b.name.match(verPattern);
if (m1 && m2) {
return (m2[1] - m1[1]) || (m2[2] - m1[2]) || (m2[3] - m1[3]);
} else if (m1) {
return -Infinity
} else if (m2) {
return Infinity
}
return 0;
})?.[0];
result.docker.name = '0.10.7'
if (result.docker && result.docker.name !== packageVersion) {
result.docker.upgrade = true;
}
XcCache.set(NOCO_RELEASE, result, 60 * 60 * 1000);
} catch (e) {
console.log(e);
}
return result;
}
} }

4
packages/nocodb/src/lib/noco/plugins/adapters/cache/XcCache.ts vendored

@ -27,8 +27,8 @@ export default class XcCache {
return this.instance?.get(key); return this.instance?.get(key);
} }
public static set(key, val): boolean { public static set(key, val, maxAge = 1000 * 60 * 60): boolean {
return this.instance?.set(key, val); return this.instance?.set(key, val, maxAge);
} }
public static del(key): void { public static del(key): void {

Loading…
Cancel
Save