add global config

This commit is contained in:
hsueh chiahao
2025-10-30 09:48:14 +08:00
committed by xuejiahao
parent 393c637163
commit 7d8e318e9a
4 changed files with 73 additions and 14 deletions

View File

@@ -7,12 +7,12 @@ import { MobileNotification } from 'kintone-ui-component/lib/mobile/notification
import manifestJson from '@/manifest.json';
import { KJUR } from 'jsrsasign';
import rsaPublicKey from '../../rsa_public.pem?raw';
import config from '@/config.json';
const { t: $t } = i18n.global;
export class LicenseService {
// 常量定义
private static readonly WARNING_DAYS_BEFORE_EXPIRY = 7;
private static PLUGIN_ID: string = '';
// ============ 基础工具函数 ============
@@ -97,6 +97,12 @@ export class LicenseService {
* 许可证验证
*/
static async checkLicense(): Promise<LicenseCheckResult> {
if (!config.license.enabled || rsaPublicKey.trim() === '') {
return {
isLicenseValid: true,
license: undefined,
};
}
const localLicense = this.getLocalLicenseInfo() || undefined;
if (localLicense) {
return {
@@ -111,13 +117,13 @@ export class LicenseService {
* 调用远程许可证API
*/
private static async callRemoteLicenseAPI(domain: string, pluginId: string): Promise<string | null> {
const url = 'https://kintone.alicorns.co.jp/api/license/check';
const url = config.license.api.checkUrl;
const method = 'POST';
const headers = { 'Content-Type': 'application/json' };
const body = {
domain,
pluginId,
pluginKey: 'kintone-vue-template',
pluginKey: config.license.api.pluginKey,
};
const proxyResponse = await kintone.proxy(url, method, headers, body);
if (proxyResponse[1] !== 200) {
@@ -180,7 +186,7 @@ export class LicenseService {
*/
static isExpiringSoon(expiryTimestamp: number): boolean {
const now = Date.now();
const warningTime = expiryTimestamp - this.WARNING_DAYS_BEFORE_EXPIRY * 24 * 60 * 60 * 1000;
const warningTime = expiryTimestamp - config.license.warningDaysBeforeExpiry * 24 * 60 * 60 * 1000;
return now >= warningTime && expiryTimestamp > now;
}
@@ -247,6 +253,12 @@ export class LicenseService {
static async loadPluginIfAuthorized(pluginId: string, callback: () => void | Promise<void>) {
this.PLUGIN_ID = pluginId;
try {
if (!config.license.enabled) {
// 许可证功能未启用,直接加载插件
await callback();
return;
}
// 检查许可证(内部已经包含本地检查无效时自动获取远程的逻辑)
const licenseCheck = await this.checkLicense();