mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
fix: adjust the license copy when installing the plugin (#7135)
* fix: license text * fix: prompt when the plugin version cannot be downloaded
This commit is contained in:
parent
54d3867551
commit
0278e09fef
@ -143,6 +143,17 @@ class Package {
|
|||||||
});
|
});
|
||||||
console.log(chalk.greenBright(`Downloaded: ${this.packageName}@${version}`));
|
console.log(chalk.greenBright(`Downloaded: ${this.packageName}@${version}`));
|
||||||
} catch (error) {
|
} 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}`));
|
console.log(chalk.redBright(`Download failed: ${this.packageName}`));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,7 +263,13 @@ module.exports = (cli) => {
|
|||||||
NOCOBASE_PKG_USERNAME,
|
NOCOBASE_PKG_USERNAME,
|
||||||
NOCOBASE_PKG_PASSWORD,
|
NOCOBASE_PKG_PASSWORD,
|
||||||
} = process.env;
|
} = 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)) {
|
if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD) && !(accessKeyId && accessKeySecret)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ const fs = require('fs-extra');
|
|||||||
const os = require('os');
|
const os = require('os');
|
||||||
const moment = require('moment-timezone');
|
const moment = require('moment-timezone');
|
||||||
const { keyDecrypt, getEnvAsync } = require('@nocobase/license-kit');
|
const { keyDecrypt, getEnvAsync } = require('@nocobase/license-kit');
|
||||||
const _ = require('lodash');
|
const omit = require('lodash/omit');
|
||||||
|
|
||||||
exports.isPackageValid = (pkg) => {
|
exports.isPackageValid = (pkg) => {
|
||||||
try {
|
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 () {
|
exports.getAccessKeyPair = async function () {
|
||||||
const keyFile = resolve(process.cwd(), 'storage/.license/license-key');
|
const keyFile = resolve(process.cwd(), 'storage/.license/license-key');
|
||||||
if (!fs.existsSync(keyFile)) {
|
if (!fs.existsSync(keyFile)) {
|
||||||
// showLicenseInfo(LicenseKeyError.notExist);
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,13 +515,13 @@ exports.getAccessKeyPair = async function () {
|
|||||||
keyData = JSON.parse(keyDataStr);
|
keyData = JSON.parse(keyDataStr);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showLicenseInfo(LicenseKeyError.parseFailed);
|
showLicenseInfo(LicenseKeyError.parseFailed);
|
||||||
return {};
|
throw new Error(LicenseKeyError.parseFailed.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentEnv = await getEnvAsync();
|
const isEnvMatched = await isEnvMatch(keyData);
|
||||||
if (!_.isEqual(_.omit(keyData?.instanceData, ['timestamp']), _.omit(currentEnv, ['timestamp']))) {
|
if (!isEnvMatched) {
|
||||||
showLicenseInfo(LicenseKeyError.notMatch);
|
showLicenseInfo(LicenseKeyError.notMatch);
|
||||||
return {};
|
throw new Error(LicenseKeyError.notMatch.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { accessKeyId, accessKeySecret } = keyData;
|
const { accessKeyId, accessKeySecret } = keyData;
|
||||||
@ -520,21 +530,21 @@ exports.getAccessKeyPair = async function () {
|
|||||||
|
|
||||||
const LicenseKeyError = {
|
const LicenseKeyError = {
|
||||||
notExist: {
|
notExist: {
|
||||||
title: 'License key not exist',
|
title: 'License key not found',
|
||||||
content:
|
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.',
|
'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: {
|
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.',
|
content: 'Please check your license key, or regenerate the license key on the service platform.',
|
||||||
},
|
},
|
||||||
notMatch: {
|
notMatch: {
|
||||||
title: 'License key not matched',
|
title: 'License key mismatch',
|
||||||
content:
|
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.',
|
'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: {
|
notValid: {
|
||||||
title: 'License key not valid',
|
title: 'Invalid license key',
|
||||||
content:
|
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.',
|
'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.',
|
||||||
},
|
},
|
||||||
|
@ -63,7 +63,7 @@ const useSubmitProps = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
setLoading(false);
|
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) {
|
} catch (e) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
@ -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",
|
"License settings": "License settings",
|
||||||
"Instance ID": "Instance ID",
|
"Instance ID": "Instance ID",
|
||||||
"License key": "License key",
|
"License key": "License key",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"License key saved successfully, please restart the server": "授权密钥保存成功,请重启服务器",
|
"License key saved successfully, please re-run the plugin installation.": "授权密钥保存成功,请重新执行插件安装操作",
|
||||||
"License settings": "授权设置",
|
"License settings": "授权设置",
|
||||||
"Instance ID": "实例 ID",
|
"Instance ID": "实例 ID",
|
||||||
"License key": "授权密钥",
|
"License key": "授权密钥",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user