jam411 3 лет назад
Родитель
Сommit
07c5d99e80
1 измененных файлов с 16 добавлено и 16 удалено
  1. 16 16
      packages/app/src/server/service/plugin.ts

+ 16 - 16
packages/app/src/server/service/plugin.ts

@@ -48,17 +48,9 @@ export class PluginService {
   async download(url: string, ghOrganizationName: string, ghReposName: string): Promise<void> {
   async download(url: string, ghOrganizationName: string, ghReposName: string): Promise<void> {
 
 
     const zipFilePath = path.join(pluginStoringPath, 'main.zip');
     const zipFilePath = path.join(pluginStoringPath, 'main.zip');
-    const unzipFolderPath = path.join(pluginStoringPath, ghOrganizationName);
-    const unzippedFolderPath = `${unzipFolderPath}/${ghReposName}-main`;
-    const newFolderPath = `${unzipFolderPath}/${ghReposName}`;
+    const unzippedPath = path.join(pluginStoringPath, ghOrganizationName);
 
 
-    const deleteFile = (path: fs.PathLike) => {
-      fs.unlink(path, (err) => {
-        if (err) throw err;
-      });
-    };
-
-    const downloadRepository = () => {
+    const downloadZipFile = () => {
       const writeStream = fs.createWriteStream(zipFilePath);
       const writeStream = fs.createWriteStream(zipFilePath);
 
 
       return new Promise<void>((resolve, reject) => {
       return new Promise<void>((resolve, reject) => {
@@ -73,24 +65,32 @@ export class PluginService {
 
 
     const unzip = () => {
     const unzip = () => {
       const stream = fs.createReadStream(zipFilePath);
       const stream = fs.createReadStream(zipFilePath);
+      const deleteZipFile = (path: fs.PathLike) => {
+        fs.unlink(path, (err) => {
+          if (err) throw err;
+        });
+      };
 
 
       return new Promise<void>((resolve, reject) => {
       return new Promise<void>((resolve, reject) => {
-        stream.pipe(unzipper.Extract({ path: unzipFolderPath }))
+        stream.pipe(unzipper.Extract({ path: unzippedPath }))
           .on('finish', () => {
           .on('finish', () => {
-            deleteFile(zipFilePath);
+            deleteZipFile(zipFilePath);
             resolve();
             resolve();
           })
           })
           .on('error', (error: any) => reject(error));
           .on('error', (error: any) => reject(error));
       });
       });
     };
     };
 
 
-    const rename = async() => {
-      fs.renameSync(unzippedFolderPath, newFolderPath);
+    const renameUnzipFolderPath = async() => {
+      const oldPath = `${unzippedPath}/${ghReposName}-main`;
+      const newPath = `${unzippedPath}/${ghReposName}`;
+
+      fs.renameSync(oldPath, newPath);
     };
     };
 
 
-    await downloadRepository();
+    await downloadZipFile();
     await unzip();
     await unzip();
-    await rename();
+    await renameUnzipFolderPath();
 
 
     return;
     return;
   }
   }