File sharing

This commit is contained in:
2026-10-29 20:44:26 -03:00
parent b65d8efad8
commit de1ad70068
18 changed files with 582 additions and 59 deletions
+7 -13
View File
@@ -1,7 +1,7 @@
import { define } from "@/utils.ts";
import { authenticate, unauthorized } from "@/src/auth.ts";
import { db, type FileRow } from "@/src/db.ts";
import { delete_upload, open_upload } from "@/src/storage.ts";
import { db, type FileRow, type ShareRow } from "@/src/db.ts";
import { delete_upload, upload_response } from "@/src/storage.ts";
const not_found = () => Response.json({ error: "File not found" }, { status: 404 });
@@ -17,17 +17,7 @@ export const handler = define.handlers({
if (!file || file.user_id !== user.id) {
return not_found();
}
const stored = await open_upload(file.storage_id).catch(() => undefined);
if (!stored) {
return not_found();
}
return new Response(stored.readable, {
headers: {
"Content-Type": "application/octet-stream",
"Cache-Control": "no-store",
},
});
return await upload_response(file.storage_id) ?? not_found();
},
async DELETE(ctx) {
@@ -41,6 +31,10 @@ export const handler = define.handlers({
return not_found();
}
const shares = await db.get_entries_by_index("shares", "file_id", file.id) as ShareRow[];
for (const share of shares) {
await db.delete_entry("shares", share);
}
await db.delete_entry("files", file);
await delete_upload(file.storage_id);
return new Response(null, { status: 204 });