refactors

This commit is contained in:
Chad Curtis committed 2025-09-20 05:47:17 +00:00
1 parent 6f4aa264eb
commit f4ccc2d924
6 files changed
+349 -45

No files matched your search

+24 -2
View File
@@ -95,7 +95,20 @@ export class ProjectsManager {
async importProjectFromZip(zipFile: File, customId?: string, overwrite = false): Promise<Project> {
// Generate a project ID based on the zip file name or use custom ID
const baseName = zipFile.name.replace(/\.zip$/i, '');
const id = customId || await this.generateUniqueProjectId(baseName);
const generatedId = baseName
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '');
// Determine the project ID to use
let id: string;
if (customId) {
// Use the provided custom ID (for overwrite scenarios)
id = customId;
} else {
// If no custom ID, generate a unique ID (for new projects)
id = await this.generateUniqueProjectId(generatedId);
}
const projectPath = `${this.dir}/${id}`;
const projectExists = await this.projectExists(id);
@@ -105,6 +118,15 @@ export class ProjectsManager {
throw new Error(`Project with ID "${id}" already exists`);
}
// Get original project name if overwriting, otherwise use formatted name
let projectName: string;
if (overwrite && projectExists) {
const existingProject = await this.getProject(id);
projectName = existingProject?.name || this.formatProjectName(id);
} else {
projectName = this.formatProjectName(id);
}
try {
// Create project directory (or ensure it exists for overwrite)
await this.fs.mkdir(projectPath, { recursive: true });
@@ -230,7 +252,7 @@ export class ProjectsManager {
return {
id,
name: this.formatProjectName(id),
name: projectName,
path: projectPath,
lastModified: timestamp,
};