feat: support removing screenshots during entry edit

This commit is contained in:
2026-05-16 17:36:06 +08:00
parent 99b89347d0
commit 1b7600a2f6
+32
View File
@@ -402,6 +402,38 @@ export const performanceVerifyRoutes = new Elysia({
.where(eq(performanceEntries.id, params.id)) .where(eq(performanceEntries.id, params.id))
.returning() .returning()
// ── Remove screenshots marked for deletion ────────────────────────
const removedIds: string[] = Array.isArray(payload.removedScreenshotIds)
? payload.removedScreenshotIds
: []
if (removedIds.length > 0) {
// Fetch storage keys before deleting rows
const toRemove = await db
.select({ id: entryScreenshots.id, storageKey: entryScreenshots.storageKey })
.from(entryScreenshots)
.where(
and(
eq(entryScreenshots.entryId, params.id),
sql`${entryScreenshots.id} = ANY(${removedIds})`,
),
)
for (const ss of toRemove) {
try { await deleteObject(ss.storageKey) } catch { /* best-effort */ }
try {
await db.delete(storageObjects).where(eq(storageObjects.key, ss.storageKey))
} catch { /* best-effort */ }
}
// Delete the screenshot rows
if (toRemove.length > 0) {
await db.delete(entryScreenshots).where(
sql`${entryScreenshots.id} = ANY(${toRemove.map((s) => s.id)})`,
)
}
}
// ── Atomic screenshot replacement ───────────────────────────────── // ── Atomic screenshot replacement ─────────────────────────────────
if (screenshotFiles.length > 0) { if (screenshotFiles.length > 0) {
// a. Upload all new screenshots to R2 FIRST (before deleting old ones) // a. Upload all new screenshots to R2 FIRST (before deleting old ones)