mirror of
https://github.com/versia-pub/server.git
synced 2026-01-26 20:26:01 +01:00
Enable serving files using local uploads
This commit is contained in:
parent
ef459c5b95
commit
b099e40c60
32
server/api/media/[id]/index.ts
Normal file
32
server/api/media/[id]/index.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { errorResponse } from "@response";
|
||||
import { applyConfig } from "@api";
|
||||
import type { MatchedRoute } from "bun";
|
||||
|
||||
export const meta = applyConfig({
|
||||
allowedMethods: ["GET"],
|
||||
route: "/media/:id",
|
||||
ratelimits: {
|
||||
max: 100,
|
||||
duration: 60,
|
||||
},
|
||||
auth: {
|
||||
required: false,
|
||||
},
|
||||
});
|
||||
|
||||
export default async (
|
||||
req: Request,
|
||||
matchedRoute: MatchedRoute
|
||||
): Promise<Response> => {
|
||||
// TODO: Add checks for disabled or not email verified accounts
|
||||
|
||||
const id = matchedRoute.params.id;
|
||||
|
||||
// Serve file from filesystem
|
||||
const file = Bun.file(`./uploads/${id}`);
|
||||
|
||||
if (!(await file.exists())) return errorResponse("File not found", 404);
|
||||
|
||||
// @ts-expect-error Bun allows this
|
||||
return new Response(file);
|
||||
};
|
||||
Loading…
Reference in a new issue