fix: removed plugins, no longer added when upgrading (#2917)

This commit is contained in:
chenos 2023-10-26 11:01:45 +08:00 committed by GitHub
parent a845dc0937
commit e62d383bf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 20 deletions

View File

@ -110,7 +110,7 @@ export abstract class Plugin<O = any> implements PluginInterface {
async toJSON(options: any = {}) {
const { locale = 'en-US' } = options;
const { packageName, packageJson } = this.options;
const { name, packageName, packageJson } = this.options;
if (!packageName) {
return {
...this.options,
@ -127,7 +127,7 @@ export abstract class Plugin<O = any> implements PluginInterface {
lastUpdated,
file,
updatable: file.startsWith(process.env.PLUGIN_STORAGE_PATH),
displayName: packageJson[`displayName.${locale}`] || packageJson.displayName,
displayName: packageJson[`displayName.${locale}`] || packageJson.displayName || name,
description: packageJson[`description.${locale}`] || packageJson.description,
};
}

View File

@ -31,21 +31,21 @@ export class PresetNocoBase extends Plugin {
];
localPlugins = [
'audit-logs',
'sample-hello',
'multi-app-manager',
'multi-app-share-collection',
'oidc',
'saml',
'cas',
'map',
'snapshot-field',
'graph-collection-manager',
'mobile-client',
'api-keys',
'localization-management',
'theme-editor',
'api-doc',
['audit-logs', '0.7.1-alpha.4'],
['sample-hello', '0.8.0-alpha.4'],
['multi-app-manager', '0.7.0-alpha.1'],
['multi-app-share-collection', '0.9.2-alpha.1'],
['oidc', '0.9.2-alpha.1'],
['saml', '0.8.1-alpha.3'],
['cas', '0.13.0-alpha.5'],
['map', '0.8.1-alpha.3'],
['snapshot-field', '0.8.1-alpha.3'],
['graph-collection-manager', '0.9.0-alpha.1'],
['mobile-client', '0.10.0-alpha.2'],
['api-keys', '0.10.1-alpha.1'],
['localization-management', '0.11.1-alpha.1'],
['theme-editor', '0.11.1-alpha.1'],
['api-doc', '0.13.0-alpha.1'],
];
splitNames(name: string) {
@ -61,7 +61,7 @@ export class PresetNocoBase extends Plugin {
getLocalPlugins() {
const { APPEND_PRESET_LOCAL_PLUGINS } = process.env;
return _.uniq(this.splitNames(APPEND_PRESET_LOCAL_PLUGINS).concat(this.localPlugins));
return _.uniq<any>(this.splitNames(APPEND_PRESET_LOCAL_PLUGINS).concat(this.localPlugins as any));
}
beforeLoad() {
@ -85,7 +85,8 @@ export class PresetNocoBase extends Plugin {
return { name, packageName, enabled: true, builtIn: true, version: packageJson.version } as any;
})
.concat(
this.getLocalPlugins().map((name) => {
this.getLocalPlugins().map((plugin) => {
const name = typeof plugin === 'string' ? plugin : plugin[0];
const packageName = PluginManager.getPackageName(name);
const packageJson = PluginManager.getPackageJson(packageName);
return { name, packageName, version: packageJson.version };
@ -93,11 +94,32 @@ export class PresetNocoBase extends Plugin {
);
}
async getPluginToBeUpgraded() {
const plugins = this.getBuiltInPlugins().map((name) => {
const packageName = PluginManager.getPackageName(name);
const packageJson = PluginManager.getPackageJson(packageName);
return { name, packageName, enabled: true, builtIn: true, version: packageJson.version } as any;
});
for (const plugin of this.getLocalPlugins()) {
if (Array.isArray(plugin)) {
if (await this.app.version.satisfies(`>${plugin[1]}`)) {
continue;
}
const name = plugin[0];
const packageName = PluginManager.getPackageName(name);
const packageJson = PluginManager.getPackageJson(packageName);
plugins.push({ name, packageName, version: packageJson.version });
}
}
return plugins;
}
async updateOrCreatePlugins() {
const repository = this.app.db.getRepository<any>('applicationPlugins');
const plugins = await this.getPluginToBeUpgraded();
await this.db.sequelize.transaction((transaction) => {
return Promise.all(
this.allPlugins.map((values) =>
plugins.map((values) =>
repository.updateOrCreate({
transaction,
values,