Remove cron.ts

This commit is contained in:
Alex Gleason 2024-05-01 09:08:36 -05:00
parent 6cc44c468e
commit caa9e47161
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 0 additions and 30 deletions

View File

@ -2,7 +2,6 @@ import { NostrEvent, NStore } from '@nostrify/nostrify';
import { type Context, Env as HonoEnv, type Handler, Hono, Input as HonoInput, type MiddlewareHandler } from 'hono';
import { cors, logger, serveStatic } from 'hono/middleware';
import '@/cron.ts';
import { type User } from '@/db/users.ts';
import { Debug } from '@/deps.ts';
import '@/firehose.ts';

View File

@ -1,29 +0,0 @@
import { deleteUnattachedMediaByUrl, getUnattachedMedia } from '@/db/unattached-media.ts';
import { cron } from '@/deps.ts';
import { Time } from '@/utils/time.ts';
import { configUploader as uploader } from '@/uploaders/config.ts';
import { cidFromUrl } from '@/utils/ipfs.ts';
/** Delete files that aren't attached to any events. */
async function cleanupMedia() {
console.info('Deleting orphaned media files...');
const until = new Date(Date.now() - Time.minutes(15));
const media = await getUnattachedMedia(until);
for (const { url } of media) {
const cid = cidFromUrl(new URL(url))!;
try {
await uploader.delete(cid);
await deleteUnattachedMediaByUrl(url);
} catch (e) {
console.error(`Failed to delete file ${url}`);
console.error(e);
}
}
console.info(`Removed ${media?.length ?? 0} orphaned media files.`);
}
cleanupMedia();
cron.every15Minute(cleanupMedia);