feat(trash): add recently-deleted banner and empty trash option for admin

- Added emptyTrash method in AssetService to purge trashed assets from DB and S3

- Added POST /projects/:projectId/empty-trash endpoint in project API

- Implemented unit and integration tests for service and API

- Prevented double click redirect in recently deleted folder

- Added top banner with Delete Now option in recently-deleted folder with confirmation dialog
This commit is contained in:
yiling
2026-06-11 16:19:35 +08:00
parent 4d0972391c
commit f093b490c6
6 changed files with 247 additions and 4 deletions
+30
View File
@@ -1033,6 +1033,36 @@ export class AssetService {
}
}
async emptyTrash(projectId: string): Promise<void> {
const trashedRoots = await this.prismaClient.asset.findMany({
where: {
projectId,
status: 'trashed',
isDeleted: true,
},
select: { id: true },
})
for (const root of trashedRoots) {
await this.prismaClient.$transaction(async (tx) => {
// Use recursive CTE to find all descendants and mark them all as pending_purge
await tx.$executeRaw`
WITH RECURSIVE descendant AS (
SELECT id FROM assets WHERE id = ${root.id}
UNION ALL
SELECT a.id FROM assets a
INNER JOIN descendant d ON a.parent_id = d.id
)
UPDATE assets SET status = 'pending_purge', updated_at = NOW()
WHERE id IN (SELECT id FROM descendant);
`
})
}
await this.purgePendingAssets()
await this.purgeUnreferencedStorageKeys()
}
private cleanupJobsRunning = false
async startCleanupJob() {