Initial aishare service

This commit is contained in:
Codex
2026-07-06 11:25:57 +00:00
commit e051b568ab
23 changed files with 5615 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
import { store } from "./db.js";
import { runCapture } from "./capture.js";
class CaptureQueue {
private queue: string[] = [];
private running = false;
enqueue(id: string): void {
if (!this.queue.includes(id)) this.queue.push(id);
void this.drain();
}
restorePending(): void {
for (const row of store.queuedCaptures()) {
store.updateStatus(row.id, "queued");
this.enqueue(row.id);
}
}
private async drain(): Promise<void> {
if (this.running) return;
this.running = true;
try {
while (this.queue.length) {
const id = this.queue.shift()!;
const row = store.getCapture(id);
if (!row || row.status === "ready") continue;
await runCapture(row);
}
} finally {
this.running = false;
}
}
}
export const captureQueue = new CaptureQueue();