mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 04:44:28 +00:00
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:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user