2 changed files with 33 additions and 0 deletions
@ -0,0 +1,27 @@ |
|||||
|
import { getGlobalConfigValue } from "#server/service/config"; |
||||
|
import { purgeAllDeletableOrphansGlobally } from "#server/service/media"; |
||||
|
|
||||
|
let lastRunAt = 0; |
||||
|
|
||||
|
export default defineTask({ |
||||
|
meta: { |
||||
|
name: "media:orphan-sweep", |
||||
|
description: "Delete deletable orphan media when admin global switch is on", |
||||
|
}, |
||||
|
async run() { |
||||
|
const enabled = await getGlobalConfigValue("mediaOrphanAutoSweepEnabled"); |
||||
|
if (!enabled) { |
||||
|
return { result: "skipped: disabled" }; |
||||
|
} |
||||
|
|
||||
|
const intervalMinutes = await getGlobalConfigValue("mediaOrphanAutoSweepIntervalMinutes"); |
||||
|
const intervalMs = intervalMinutes * 60_000; |
||||
|
if (Date.now() - lastRunAt < intervalMs) { |
||||
|
return { result: "skipped: throttle" }; |
||||
|
} |
||||
|
|
||||
|
lastRunAt = Date.now(); |
||||
|
const deletedCount = await purgeAllDeletableOrphansGlobally(50); |
||||
|
return { result: "ok", deletedCount }; |
||||
|
}, |
||||
|
}); |
||||
Loading…
Reference in new issue