Merge branch 'rm-cron' into 'main'

Remove cron.ts

See merge request soapbox-pub/ditto!201
This commit is contained in:
Alex Gleason 2024-05-01 14:11:41 +00:00
commit 9c1760bcc0
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);