jam411 пре 3 година
родитељ
комит
74a487dee3

+ 4 - 4
packages/app/src/server/routes/apiv3/plugins.ts

@@ -11,11 +11,11 @@ module.exports = (crowi: Crowi) => {
   const { pluginService } = crowi;
 
   router.post('/', async(req: PluginInstallerFormRequest, res: ApiV3Response) => {
-    try {
-      if (pluginService == null) {
-        throw new Error('pluginService is not set up');
-      }
+    if (pluginService == null) {
+      return res.apiv3Err('\'pluginService\' is not set up', 500);
+    }
 
+    try {
       await pluginService.install(req.body.pluginInstallerForm);
       return res.apiv3({});
     }

+ 1 - 3
packages/app/src/server/service/plugin.ts

@@ -116,9 +116,7 @@ export class PluginService implements IPluginService {
 
   private async deleteOldPluginDocument(path: string): Promise<void> {
     const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
-    const growiPlugin = await GrowiPlugin.findOne({ installedPath: path });
-    // if document already exists, delete old document before rename path
-    if (growiPlugin) await GrowiPlugin.findOneAndDelete({ installedPath: path });
+    await GrowiPlugin.deleteMany({ installedPath: path });
   }
 
   private async downloadPluginRepository(ghOrganizationName: string, ghReposName: string, ghBranch: string): Promise<void> {