fix: plugin list not updated after upgrade (#2545)

This commit is contained in:
chenos 2023-08-28 00:18:46 +08:00 committed by GitHub
parent 176d380331
commit c65507606a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,6 +69,9 @@ export class PresetNocoBase extends Plugin {
plugin: this,
},
});
this.app.on('beforeUpgrade', async () => {
await this.createIfNotExist();
});
}
get allPlugins() {
@ -79,6 +82,14 @@ export class PresetNocoBase extends Plugin {
.concat(this.localPlugins.map((name) => ({ name })));
}
async createIfNotExist() {
const repository = this.app.db.getRepository<any>('applicationPlugins');
const existPlugins = await repository.find();
const existPluginNames = existPlugins.map((item) => item.name);
const plugins = this.allPlugins.filter((item) => !existPluginNames.includes(item.name));
await repository.create({ values: plugins });
}
async install() {
const repository = this.app.db.getRepository<any>('applicationPlugins');
const existPlugins = await repository.find();