Archived
Add project closing action menu
This commit is contained in:
@@ -28,6 +28,15 @@ app.post<{ Body: { name?: string; path: string; create?: boolean } }>("/api/proj
|
||||
}
|
||||
});
|
||||
|
||||
app.delete<{ Params: { projectId: string } }>("/api/projects/:projectId", async (request, reply) => {
|
||||
try {
|
||||
await projects.close(request.params.projectId);
|
||||
return { closed: true };
|
||||
} catch (error) {
|
||||
return reply.code(404).send({ error: error instanceof Error ? error.message : String(error) });
|
||||
}
|
||||
});
|
||||
|
||||
app.get<{ Querystring: { q?: string } }>("/api/project-directories", async (request, reply) => {
|
||||
try {
|
||||
return await listDirectorySuggestions(request.query.q ?? "");
|
||||
|
||||
@@ -19,6 +19,10 @@ export class ProjectService {
|
||||
return this.store.add(input.name === undefined ? { path: resolved } : { name: input.name, path: resolved });
|
||||
}
|
||||
|
||||
async close(id: string): Promise<void> {
|
||||
if (!(await this.store.remove(id))) throw new Error("Project not found");
|
||||
}
|
||||
|
||||
async requireProject(id: string): Promise<Project> {
|
||||
const project = await this.store.get(id);
|
||||
if (!project) throw new Error("Project not found");
|
||||
|
||||
@@ -61,6 +61,14 @@ export class ProjectStore {
|
||||
return (await this.list()).find((p) => p.id === id);
|
||||
}
|
||||
|
||||
async remove(id: string): Promise<boolean> {
|
||||
const data = await this.read();
|
||||
const projects = data.projects.filter((p) => p.id !== id);
|
||||
if (projects.length === data.projects.length) return false;
|
||||
await this.write({ projects });
|
||||
return true;
|
||||
}
|
||||
|
||||
private async read(): Promise<ProjectFile> {
|
||||
try {
|
||||
const value: unknown = JSON.parse(await readFile(this.filePath, "utf8"));
|
||||
|
||||
Reference in New Issue
Block a user