feat: add license info in getAutomatischInfo query (#1202)
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
import appConfig from '../../config/app';
|
||||
import { getLicense } from '../../helpers/license.ee';
|
||||
|
||||
const getAutomatischInfo = async () => {
|
||||
const license = await getLicense();
|
||||
|
||||
const computedLicense = {
|
||||
id: license ? license.id : null,
|
||||
name: license ? license.name : null,
|
||||
expireAt: license ? license.expireAt : null,
|
||||
verified: license ? true : false,
|
||||
};
|
||||
|
||||
return {
|
||||
isCloud: appConfig.isCloud,
|
||||
license: computedLicense,
|
||||
};
|
||||
};
|
||||
|
||||
|
@@ -593,6 +593,14 @@ type AppHealth {
|
||||
|
||||
type GetAutomatischInfo {
|
||||
isCloud: Boolean
|
||||
license: License
|
||||
}
|
||||
|
||||
type License {
|
||||
id: String
|
||||
name: String
|
||||
expireAt: String
|
||||
verified: Boolean
|
||||
}
|
||||
|
||||
type GetTrialStatus {
|
||||
|
@@ -5,7 +5,13 @@ import memoryCache from 'memory-cache';
|
||||
|
||||
const CACHE_DURATION = 1000 * 60 * 60 * 24; // 24 hours in milliseconds
|
||||
|
||||
const checkLicense = async () => {
|
||||
const hasValidLicense = async () => {
|
||||
const license = await getLicense();
|
||||
|
||||
return license ? true : false;
|
||||
};
|
||||
|
||||
const getLicense = async () => {
|
||||
const licenseKey = appConfig.licenseKey;
|
||||
|
||||
if (!licenseKey) {
|
||||
@@ -20,13 +26,13 @@ const checkLicense = async () => {
|
||||
} else {
|
||||
try {
|
||||
const { data } = await axios.post(url, { licenseKey });
|
||||
memoryCache.put(url, data.verified, CACHE_DURATION);
|
||||
memoryCache.put(url, data, CACHE_DURATION);
|
||||
|
||||
return data.verified;
|
||||
return data;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default checkLicense;
|
||||
export { getLicense, hasValidLicense };
|
@@ -4,7 +4,7 @@ import crypto from 'node:crypto';
|
||||
import { ModelOptions, QueryContext } from 'objection';
|
||||
|
||||
import appConfig from '../config/app';
|
||||
import checkLicense from '../helpers/check-license.ee';
|
||||
import { hasValidLicense } from '../helpers/license.ee';
|
||||
import userAbility from '../helpers/user-ability';
|
||||
import Base from './base';
|
||||
import Connection from './connection';
|
||||
@@ -289,9 +289,7 @@ class User extends Base {
|
||||
}
|
||||
|
||||
async $afterFind(): Promise<any> {
|
||||
const hasValidLicense = await checkLicense();
|
||||
|
||||
if (hasValidLicense) return this;
|
||||
if (await hasValidLicense()) return this;
|
||||
|
||||
if (Array.isArray(this.permissions)) {
|
||||
this.permissions = this.permissions.filter((permission) => {
|
||||
|
Reference in New Issue
Block a user