From ec8215170d75ef63171ec3561d26c87f62f88c9f Mon Sep 17 00:00:00 2001 From: Dong Lei Date: Mon, 20 Apr 2020 08:20:16 +0000 Subject: [PATCH] clean project registry before create new project --- Composer/packages/server/src/controllers/project.ts | 1 + Composer/packages/server/src/services/project.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/Composer/packages/server/src/controllers/project.ts b/Composer/packages/server/src/controllers/project.ts index ca8a3b5c48..fb479348e6 100644 --- a/Composer/packages/server/src/controllers/project.ts +++ b/Composer/packages/server/src/controllers/project.ts @@ -44,6 +44,7 @@ async function createProject(req: Request, res: Response) { log('Attempting to create project at %s', path); try { + await BotProjectService.cleanProject(locationRef); const newProjRef = await AssectService.manager.copyProjectTemplateTo(templateId, locationRef, user); const id = await BotProjectService.openProject(newProjRef, user); const currentProject = await BotProjectService.getProjectById(id, user); diff --git a/Composer/packages/server/src/services/project.ts b/Composer/packages/server/src/services/project.ts index 9ed8b01756..089f2c09d2 100644 --- a/Composer/packages/server/src/services/project.ts +++ b/Composer/packages/server/src/services/project.ts @@ -159,6 +159,16 @@ export class BotProjectService { return projectId.toString(); }; + // clean project registry based on path to avoid reuseing the same id + public static cleanProject = async (location: LocationRef): Promise => { + for (const key in BotProjectService.projectLocationMap) { + if (BotProjectService.projectLocationMap[key] === location.path) { + delete BotProjectService.projectLocationMap[key]; + } + } + Store.set('projectLocationMap', BotProjectService.projectLocationMap); + }; + public static generateProjectId = async (path: string): Promise => { const projectId = (Math.random() * 100000).toString(); BotProjectService.projectLocationMap[projectId] = path;