add /api/file/random

This commit is contained in:
2023-06-19 10:15:11 +08:00
parent 3561c30587
commit 4684e16c82
3 changed files with 28 additions and 6 deletions

12
routes/api/file/random.ts Normal file
View File

@@ -0,0 +1,12 @@
import { Handlers } from "$fresh/server.ts";
import { get_task_manager } from "../../../server.ts";
export const handler: Handlers = {
GET(req, _ctx) {
const m = get_task_manager();
const f = m.db.get_random_file();
if (!f) return new Response("File not found.", { status: 404 });
const u = new URL(req.url);
return Response.redirect(`${u.origin}/api/file/${f.id}`);
}
}