fix(api): 🐛 Fix local media endpoint not being correctly registered

Expected only a name, forgot about the file hash
This commit is contained in:
Jesse Wierzbinski 2024-06-13 23:54:47 -10:00
parent c764cc044d
commit 2ec7e512e0
No known key found for this signature in database
2 changed files with 6 additions and 5 deletions

View file

@ -15,7 +15,7 @@
## With Docker/Podman ## 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 1. Download the `docker-compose.yml` file from the repository

View file

@ -6,7 +6,7 @@ import { z } from "zod";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["GET"], allowedMethods: ["GET"],
route: "/media/:id", route: "/media/:id/:name",
ratelimits: { ratelimits: {
max: 100, max: 100,
duration: 60, duration: 60,
@ -18,7 +18,8 @@ export const meta = applyConfig({
export const schemas = { export const schemas = {
param: z.object({ param: z.object({
id: z.string().uuid(), id: z.string(),
name: z.string(),
}), }),
header: z.object({ header: z.object({
range: z.string().optional().default(""), range: z.string().optional().default(""),
@ -32,7 +33,7 @@ export default (app: Hono) =>
zValidator("param", schemas.param, handleZodError), zValidator("param", schemas.param, handleZodError),
zValidator("header", schemas.header, handleZodError), zValidator("header", schemas.header, handleZodError),
async (context) => { async (context) => {
const { id } = context.req.valid("param"); const { id, name } = context.req.valid("param");
const { range } = context.req.valid("header"); const { range } = context.req.valid("header");
// parse `Range` header // parse `Range` header
@ -45,7 +46,7 @@ export default (app: Hono) =>
.map(Number); // [0, 100] .map(Number); // [0, 100]
// Serve file from filesystem // Serve file from filesystem
const file = Bun.file(`./uploads/${id}`); const file = Bun.file(`./uploads/${id}/${name}`);
const buffer = await file.arrayBuffer(); const buffer = await file.arrayBuffer();