feat: complete TASK-WP2-07 latest exports

This commit is contained in:
suyx
2026-08-03 01:43:09 +08:00
parent 2bb4f86d04
commit 1b0a05bbcf
20 changed files with 1791 additions and 18 deletions
+20
View File
@@ -645,6 +645,26 @@ export class ManagedStorage {
return row ? resolvePathWithinRoot(this.dataRoot, row.relative_path) : undefined;
}
retireManagedFile(fileId: string, reason: "compensation" | "purge" = "compensation") {
const transaction = this.database.transaction(() => {
const file = this.database.prepare(`
SELECT file_id, relative_path, byte_size FROM managed_files
WHERE file_id = ? AND status = 'committed'
`).get(fileId) as { byte_size: number; file_id: string; relative_path: string } | undefined;
if (!file) return;
const retiredAt = now();
this.database.prepare("DELETE FROM project_asset_refs WHERE managed_file_id = ?").run(fileId);
this.database.prepare("UPDATE managed_files SET status = 'purged', purged_at = ? WHERE file_id = ?").run(retiredAt, fileId);
this.database.prepare(`
INSERT OR IGNORE INTO file_cleanup_queue (
cleanup_id, managed_file_id, relative_path, byte_size, counts_toward_managed,
reason, status, created_at, completed_at, last_error
) VALUES (?, ?, ?, ?, 1, ?, 'pending', ?, NULL, NULL)
`).run(randomUUID(), fileId, file.relative_path, file.byte_size, reason, retiredAt);
});
transaction.immediate();
}
addAssetReference(fileId: string, referenceType: "project" | "release") {
if (this.inspectAction("project_json_write") !== "allow") throw new StorageUnavailableError();
this.database.prepare(`INSERT INTO project_asset_refs (reference_id, managed_file_id, reference_type, created_at) VALUES (?, ?, ?, ?)`)