diff --git a/packages/core/cli/src/commands/pkg.js b/packages/core/cli/src/commands/pkg.js index b57759b34c..12dfa476ba 100644 --- a/packages/core/cli/src/commands/pkg.js +++ b/packages/core/cli/src/commands/pkg.js @@ -143,6 +143,17 @@ class Package { }); console.log(chalk.greenBright(`Downloaded: ${this.packageName}@${version}`)); } catch (error) { + if (error.response.data && typeof error.response.data.pipe === 'function') { + let errorMessageBuffer = ''; + error.response.data.on('data', (chunk) => { + errorMessageBuffer += chunk.toString('utf8'); // 收集错误信息 + }); + error.response.data.on('end', () => { + if (error.response.status === 403) { + console.error(chalk.redBright('You do not have permission to download this package version.')); + } + }); + } console.log(chalk.redBright(`Download failed: ${this.packageName}`)); } } @@ -252,7 +263,13 @@ module.exports = (cli) => { NOCOBASE_PKG_USERNAME, NOCOBASE_PKG_PASSWORD, } = process.env; - const { accessKeyId, accessKeySecret } = await getAccessKeyPair(); + let accessKeyId; + let accessKeySecret; + try { + ({ accessKeyId, accessKeySecret } = await getAccessKeyPair()); + } catch (e) { + return; + } if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD) && !(accessKeyId && accessKeySecret)) { return; } diff --git a/packages/core/cli/src/util.js b/packages/core/cli/src/util.js index 62f41efae8..91cc52cbe2 100644 --- a/packages/core/cli/src/util.js +++ b/packages/core/cli/src/util.js @@ -19,7 +19,7 @@ const fs = require('fs-extra'); const os = require('os'); const moment = require('moment-timezone'); const { keyDecrypt, getEnvAsync } = require('@nocobase/license-kit'); -const _ = require('lodash'); +const omit = require('lodash/omit'); exports.isPackageValid = (pkg) => { try { @@ -491,10 +491,20 @@ exports.generatePlugins = function () { } }; +async function isEnvMatch(keyData) { + const env = await getEnvAsync(); + if (env?.container?.id && keyData?.instanceData?.container?.id) { + return ( + JSON.stringify(omit(env, ['timestamp', 'container', 'hostname'])) === + JSON.stringify(omit(keyData?.instanceData, ['timestamp', 'container', 'hostname'])) + ); + } + return JSON.stringify(omit(env, ['timestamp'])) === JSON.stringify(omit(keyData?.instanceData, ['timestamp'])); +} + exports.getAccessKeyPair = async function () { const keyFile = resolve(process.cwd(), 'storage/.license/license-key'); if (!fs.existsSync(keyFile)) { - // showLicenseInfo(LicenseKeyError.notExist); return {}; } @@ -505,13 +515,13 @@ exports.getAccessKeyPair = async function () { keyData = JSON.parse(keyDataStr); } catch (error) { showLicenseInfo(LicenseKeyError.parseFailed); - return {}; + throw new Error(LicenseKeyError.parseFailed.title); } - const currentEnv = await getEnvAsync(); - if (!_.isEqual(_.omit(keyData?.instanceData, ['timestamp']), _.omit(currentEnv, ['timestamp']))) { + const isEnvMatched = await isEnvMatch(keyData); + if (!isEnvMatched) { showLicenseInfo(LicenseKeyError.notMatch); - return {}; + throw new Error(LicenseKeyError.notMatch.title); } const { accessKeyId, accessKeySecret } = keyData; @@ -520,21 +530,21 @@ exports.getAccessKeyPair = async function () { const LicenseKeyError = { notExist: { - title: 'License key not exist', + title: 'License key not found', content: 'Please go to the license settings page to obtain the Instance ID for the current environment, and then generate the license key on the service platform.', }, parseFailed: { - title: 'License key parse failed', + title: 'Invalid license key format', content: 'Please check your license key, or regenerate the license key on the service platform.', }, notMatch: { - title: 'License key not matched', + title: 'License key mismatch', content: 'Please go to the license settings page to obtain the Instance ID for the current environment, and then regenerate the license key on the service platform.', }, notValid: { - title: 'License key not valid', + title: 'Invalid license key', content: 'Please go to the license settings page to obtain the Instance ID for the current environment, and then regenerate the license key on the service platform.', }, diff --git a/packages/plugins/@nocobase/plugin-license/src/client/LicenseSetting.tsx b/packages/plugins/@nocobase/plugin-license/src/client/LicenseSetting.tsx index 7c1eb01019..9cb28585ef 100644 --- a/packages/plugins/@nocobase/plugin-license/src/client/LicenseSetting.tsx +++ b/packages/plugins/@nocobase/plugin-license/src/client/LicenseSetting.tsx @@ -63,7 +63,7 @@ const useSubmitProps = () => { }, }); setLoading(false); - message.success(t('License key saved successfully, please restart the server')); + message.success(t('License key saved successfully, please re-run the plugin installation.')); } catch (e) { setLoading(false); } diff --git a/packages/plugins/@nocobase/plugin-license/src/locale/en-US.json b/packages/plugins/@nocobase/plugin-license/src/locale/en-US.json index e0b63104e9..e25d7efe26 100644 --- a/packages/plugins/@nocobase/plugin-license/src/locale/en-US.json +++ b/packages/plugins/@nocobase/plugin-license/src/locale/en-US.json @@ -1,5 +1,5 @@ { - "License key saved successfully, please restart the server": "License key saved successfully, please restart the server", + "License key saved successfully, please re-run the plugin installation.": "License key saved successfully, please re-run the plugin installation.", "License settings": "License settings", "Instance ID": "Instance ID", "License key": "License key", diff --git a/packages/plugins/@nocobase/plugin-license/src/locale/zh-CN.json b/packages/plugins/@nocobase/plugin-license/src/locale/zh-CN.json index 93cf47beae..93ea35a6cf 100644 --- a/packages/plugins/@nocobase/plugin-license/src/locale/zh-CN.json +++ b/packages/plugins/@nocobase/plugin-license/src/locale/zh-CN.json @@ -1,5 +1,5 @@ { - "License key saved successfully, please restart the server": "授权密钥保存成功,请重启服务器", + "License key saved successfully, please re-run the plugin installation.": "授权密钥保存成功,请重新执行插件安装操作", "License settings": "授权设置", "Instance ID": "实例 ID", "License key": "授权密钥",