Remove unattached_media table, replace with LRUCache, fix media upload order problem

This commit is contained in:
Alex Gleason
2024-09-07 10:24:56 -05:00
parent 85000cd00e
commit 8efd6fbb20
10 changed files with 100 additions and 139 deletions

View File

@@ -2,7 +2,7 @@ import { HTTPException } from '@hono/hono/http-exception';
import { AppContext } from '@/app.ts';
import { Conf } from '@/config.ts';
import { insertUnattachedMedia, UnattachedMedia } from '@/db/unattached-media.ts';
import { DittoUpload, dittoUploads } from '@/DittoUploads.ts';
interface FileMeta {
pubkey: string;
@@ -15,7 +15,7 @@ export async function uploadFile(
file: File,
meta: FileMeta,
signal?: AbortSignal,
): Promise<UnattachedMedia> {
): Promise<DittoUpload> {
const uploader = c.get('uploader');
if (!uploader) {
throw new HTTPException(500, {
@@ -36,11 +36,15 @@ export async function uploadFile(
tags.push(['alt', description]);
}
return insertUnattachedMedia({
const upload = {
id: crypto.randomUUID(),
pubkey,
url,
data: tags,
uploaded_at: Date.now(),
});
tags,
pubkey,
uploadedAt: new Date(),
};
dittoUploads.set(upload.id, upload);
return upload;
}