feat: complete TASK-WP2-07 latest exports
This commit is contained in:
@@ -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 (?, ?, ?, ?)`)
|
||||
|
||||
Reference in New Issue
Block a user