You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
875 B
27 lines
875 B
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 };
|
|
},
|
|
});
|
|
|