فهرست منبع

update for FB

jam411 3 سال پیش
والد
کامیت
43b849f913
3فایلهای تغییر یافته به همراه20 افزوده شده و 7 حذف شده
  1. 0 3
      packages/app/src/pages/_document.page.tsx
  2. 2 0
      packages/app/src/server/crowi/index.js
  3. 18 4
      packages/app/src/server/service/plugin.ts

+ 0 - 3
packages/app/src/pages/_document.page.tsx

@@ -89,9 +89,6 @@ class GrowiDocument extends Document<GrowiDocumentInitialProps> {
     const { crowi } = ctx.req as CrowiRequest<any>;
     const { crowi } = ctx.req as CrowiRequest<any>;
     const { configManager, customizeService, pluginService } = crowi;
     const { configManager, customizeService, pluginService } = crowi;
 
 
-    // reinstall the plugins, if document exists but there is no repository
-    await (pluginService as IPluginService).reintallNotExistPluginRepositories();
-
     const theme = configManager.getConfig('crowi', 'customize:theme');
     const theme = configManager.getConfig('crowi', 'customize:theme');
     const customScript: string | null = customizeService.getCustomScript();
     const customScript: string | null = customizeService.getCustomScript();
     const customCss: string | null = customizeService.getCustomCss();
     const customCss: string | null = customizeService.getCustomCss();

+ 2 - 0
packages/app/src/server/crowi/index.js

@@ -702,6 +702,8 @@ Crowi.prototype.setupPluginService = async function() {
   if (this.pluginService == null) {
   if (this.pluginService == null) {
     this.pluginService = new PluginService(this);
     this.pluginService = new PluginService(this);
   }
   }
+  // reinstall the plugins, if document exists but there is no repository
+  await this.pluginService.reintallNotExistPluginRepositories();
 };
 };
 
 
 Crowi.prototype.setupPageService = async function() {
 Crowi.prototype.setupPageService = async function() {

+ 18 - 4
packages/app/src/server/service/plugin.ts

@@ -56,10 +56,23 @@ export class PluginService implements IPluginService {
         }
         }
         else {
         else {
           // if not exists repository, reinstall latest plugin
           // if not exists repository, reinstall latest plugin
-          // delete old document
-          await GrowiPlugin.findByIdAndDelete(growiPlugin._id);
-          // reinstall latest plugin
-          await this.install(growiPlugin.origin);
+          // download
+          const ghUrl = new URL(growiPlugin.origin.url);
+          const ghPathname = ghUrl.pathname;
+          // TODO: Branch names can be specified.
+          const ghBranch = 'main';
+
+          const match = ghPathname.match(githubReposIdPattern);
+          if (ghUrl.hostname !== 'github.com' || match == null) {
+            throw new Error('The GitHub Repository URL is invalid.');
+          }
+
+          const ghOrganizationName = match[1];
+          const ghReposName = match[2];
+          const requestUrl = `https://github.com/${ghOrganizationName}/${ghReposName}/archive/refs/heads/${ghBranch}.zip`;
+
+          // download github repository to local file system
+          await this.download(requestUrl, ghOrganizationName, ghReposName, ghBranch);
           continue;
           continue;
         }
         }
       }
       }
@@ -148,6 +161,7 @@ export class PluginService implements IPluginService {
 
 
         const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
         const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
         const growiPlugin = await GrowiPlugin.findOne({ installedPath: `${ghOrganizationName}/${ghReposName}` });
         const growiPlugin = await GrowiPlugin.findOne({ installedPath: `${ghOrganizationName}/${ghReposName}` });
+        console.log(growiPlugin);
         // if document already exists, delete old document before rename path
         // if document already exists, delete old document before rename path
         if (growiPlugin) await GrowiPlugin.findOneAndDelete({ installedPath: `${ghOrganizationName}/${ghReposName}` });
         if (growiPlugin) await GrowiPlugin.findOneAndDelete({ installedPath: `${ghOrganizationName}/${ghReposName}` });
       }
       }