mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Remove cron.ts
This commit is contained in:
parent
6cc44c468e
commit
caa9e47161
2 changed files with 0 additions and 30 deletions
|
|
@ -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 { type Context, Env as HonoEnv, type Handler, Hono, Input as HonoInput, type MiddlewareHandler } from 'hono';
|
||||||
import { cors, logger, serveStatic } from 'hono/middleware';
|
import { cors, logger, serveStatic } from 'hono/middleware';
|
||||||
|
|
||||||
import '@/cron.ts';
|
|
||||||
import { type User } from '@/db/users.ts';
|
import { type User } from '@/db/users.ts';
|
||||||
import { Debug } from '@/deps.ts';
|
import { Debug } from '@/deps.ts';
|
||||||
import '@/firehose.ts';
|
import '@/firehose.ts';
|
||||||
|
|
|
||||||
29
src/cron.ts
29
src/cron.ts
|
|
@ -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);
|
|
||||||
Loading…
Add table
Reference in a new issue