progress indicator added

This commit is contained in:
2026-09-13 15:30:23 +05:30
parent 9c7a16b57c
commit 13c24e9db3
5 changed files with 319 additions and 69 deletions
+33
View File
@@ -0,0 +1,33 @@
import { rm } from "node:fs/promises";
type Job = {
dir: string;
zipPath: string;
createdAt: number;
};
const JOB_TTL_MS = 15 * 60 * 1000;
const jobs = new Map<string, Job>();
function sweepExpiredJobs(): void {
const cutoff = Date.now() - JOB_TTL_MS;
for (const [id, job] of jobs) {
if (job.createdAt > cutoff) continue;
jobs.delete(id);
void rm(job.dir, { recursive: true, force: true });
}
}
export function saveJob(dir: string, zipPath: string): string {
sweepExpiredJobs();
const id = crypto.randomUUID();
jobs.set(id, { dir, zipPath, createdAt: Date.now() });
return id;
}
export function takeJob(id: string): Job | null {
const job = jobs.get(id);
if (!job) return null;
jobs.delete(id);
return job;
}