|
@@ -101,6 +101,7 @@ export class PluginService implements IPluginService {
|
|
|
|
|
|
|
|
// download github repository to local file system
|
|
// download github repository to local file system
|
|
|
await this.download(requestUrl, ghOrganizationName, ghReposName, ghBranch);
|
|
await this.download(requestUrl, ghOrganizationName, ghReposName, ghBranch);
|
|
|
|
|
+ await this.deleteOldDocument(ghOrganizationName, ghReposName);
|
|
|
|
|
|
|
|
// save plugin metadata
|
|
// save plugin metadata
|
|
|
const installedPath = `${ghOrganizationName}/${ghReposName}`;
|
|
const installedPath = `${ghOrganizationName}/${ghReposName}`;
|
|
@@ -110,6 +111,13 @@ export class PluginService implements IPluginService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private async deleteOldDocument(ghOrganizationName: string, ghReposName: string): Promise<void> {
|
|
|
|
|
+ const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
|
|
|
|
|
+ const growiPlugin = await GrowiPlugin.findOne({ installedPath: `${ghOrganizationName}/${ghReposName}` });
|
|
|
|
|
+ // if document already exists, delete old document before rename path
|
|
|
|
|
+ if (growiPlugin) await GrowiPlugin.findOneAndDelete({ installedPath: `${ghOrganizationName}/${ghReposName}` });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private async download(requestUrl: string, ghOrganizationName: string, ghReposName: string, ghBranch: string): Promise<void> {
|
|
private async download(requestUrl: string, ghOrganizationName: string, ghReposName: string, ghBranch: string): Promise<void> {
|
|
|
|
|
|
|
|
const zipFilePath = path.join(pluginStoringPath, `${ghBranch}.zip`);
|
|
const zipFilePath = path.join(pluginStoringPath, `${ghBranch}.zip`);
|
|
@@ -141,11 +149,11 @@ export class PluginService implements IPluginService {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const unzip = async(zipFilePath: fs.PathLike, unzippedPath: fs.PathLike) => {
|
|
const unzip = async(zipFilePath: fs.PathLike, unzippedPath: fs.PathLike) => {
|
|
|
- const stream = fs.createReadStream(zipFilePath);
|
|
|
|
|
- const unzipStream = stream.pipe(unzipper.Extract({ path: unzippedPath }));
|
|
|
|
|
- const deleteZipFile = (path: fs.PathLike) => fs.unlinkSync(path);
|
|
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
+ const stream = fs.createReadStream(zipFilePath);
|
|
|
|
|
+ const unzipStream = stream.pipe(unzipper.Extract({ path: unzippedPath }));
|
|
|
|
|
+ const deleteZipFile = (path: fs.PathLike) => fs.unlinkSync(path);
|
|
|
|
|
+
|
|
|
await streamToPromise(unzipStream);
|
|
await streamToPromise(unzipStream);
|
|
|
deleteZipFile(zipFilePath);
|
|
deleteZipFile(zipFilePath);
|
|
|
}
|
|
}
|
|
@@ -158,18 +166,12 @@ export class PluginService implements IPluginService {
|
|
|
try {
|
|
try {
|
|
|
// if repository already exists, delete old repository before rename path
|
|
// if repository already exists, delete old repository before rename path
|
|
|
if (fs.existsSync(newPath)) await fs.promises.rm(newPath, { recursive: true });
|
|
if (fs.existsSync(newPath)) await fs.promises.rm(newPath, { recursive: true });
|
|
|
-
|
|
|
|
|
- const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
|
|
|
|
|
- const growiPlugin = await GrowiPlugin.findOne({ installedPath: `${ghOrganizationName}/${ghReposName}` });
|
|
|
|
|
- console.log(growiPlugin);
|
|
|
|
|
- // if document already exists, delete old document before rename path
|
|
|
|
|
- if (growiPlugin) await GrowiPlugin.findOneAndDelete({ installedPath: `${ghOrganizationName}/${ghReposName}` });
|
|
|
|
|
|
|
+ // rename repository
|
|
|
|
|
+ fs.renameSync(oldPath, newPath);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
return err;
|
|
return err;
|
|
|
}
|
|
}
|
|
|
- // rename repository
|
|
|
|
|
- fs.renameSync(oldPath, newPath);
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
try {
|