From 2ec7e512e076821296a39fadc152c7515d796be1 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Thu, 13 Jun 2024 23:54:47 -1000 Subject: [PATCH] fix(api): :bug: Fix local media endpoint not being correctly registered Expected only a name, forgot about the file hash --- docs/installation.md | 2 +- server/api/media/:id/{ => :name}/index.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) rename server/api/media/:id/{ => :name}/index.ts (89%) diff --git a/docs/installation.md b/docs/installation.md index 0c5492a2..072ef72c 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -15,7 +15,7 @@ ## With Docker/Podman -Docker is the recommended way to run Lysand (podman also works). To run Lysand with Docker, follow these steps: +Docker is the recommended way to run Lysand (Podman also works). To run Lysand with Docker, follow these steps: 1. Download the `docker-compose.yml` file from the repository diff --git a/server/api/media/:id/index.ts b/server/api/media/:id/:name/index.ts similarity index 89% rename from server/api/media/:id/index.ts rename to server/api/media/:id/:name/index.ts index ee5ff824..3bfe4e50 100644 --- a/server/api/media/:id/index.ts +++ b/server/api/media/:id/:name/index.ts @@ -6,7 +6,7 @@ import { z } from "zod"; export const meta = applyConfig({ allowedMethods: ["GET"], - route: "/media/:id", + route: "/media/:id/:name", ratelimits: { max: 100, duration: 60, @@ -18,7 +18,8 @@ export const meta = applyConfig({ export const schemas = { param: z.object({ - id: z.string().uuid(), + id: z.string(), + name: z.string(), }), header: z.object({ range: z.string().optional().default(""), @@ -32,7 +33,7 @@ export default (app: Hono) => zValidator("param", schemas.param, handleZodError), zValidator("header", schemas.header, handleZodError), async (context) => { - const { id } = context.req.valid("param"); + const { id, name } = context.req.valid("param"); const { range } = context.req.valid("header"); // parse `Range` header @@ -45,7 +46,7 @@ export default (app: Hono) => .map(Number); // [0, 100] // Serve file from filesystem - const file = Bun.file(`./uploads/${id}`); + const file = Bun.file(`./uploads/${id}/${name}`); const buffer = await file.arrayBuffer();