Import source: backend/src/worker
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { store } from './services/store.js';
|
||||
import { deleteFile } from './utils/gdrive.js';
|
||||
|
||||
async function expireFiles() {
|
||||
const now = Date.now();
|
||||
await store.update(async (db) => {
|
||||
const toExpire = db.files.filter(
|
||||
(f) => f.status === 'uploaded' && new Date(f.expiresAt).getTime() <= now,
|
||||
);
|
||||
await Promise.allSettled(toExpire.map((f) => deleteFile(f.gdriveId)));
|
||||
for (const file of toExpire) {
|
||||
file.status = 'expired';
|
||||
file.deletedAt = new Date().toISOString();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await expireFiles();
|
||||
setInterval(expireFiles, 60_000);
|
||||
Reference in New Issue
Block a user