fix modeltester attachment replay and add proxy file retention

This commit is contained in:
cita
2026-03-21 00:04:06 +08:00
parent 94b6cac871
commit 95bf8df499
11 changed files with 676 additions and 43 deletions
+15 -1
View File
@@ -1,4 +1,4 @@
import { and, desc, eq, isNull, or } from 'drizzle-orm';
import { and, desc, eq, isNull, lt, or } from 'drizzle-orm';
import { createHash } from 'node:crypto';
import { db, schema } from '../db/index.js';
import type { ProxyResourceOwner } from '../middleware/auth.js';
@@ -204,3 +204,17 @@ export async function softDeleteProxyFile(publicId: string): Promise<boolean> {
.run();
return Number(result?.changes || 0) > 0;
}
export async function purgeExpiredProxyFiles(cutoffUtc: string): Promise<number> {
const normalizedCutoff = cutoffUtc.trim();
if (!normalizedCutoff) return 0;
const result = await db.delete(schema.proxyFiles)
.where(or(
lt(schema.proxyFiles.createdAt, normalizedCutoff),
and(isNull(schema.proxyFiles.createdAt), lt(schema.proxyFiles.updatedAt, normalizedCutoff)),
))
.run();
return Number(result?.changes || 0);
}