This commit is contained in:
seb
2026-07-06 01:31:11 +02:00
commit 917930d0fa
34 changed files with 2912 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
import { sendBinary, sendJson } from '../http.js';
import { resizeImage } from '../image-resize.js';
import { getImageByHash } from '../queries/image.js';
export function createImageHandler() {
return async function handle(_req, res, { url }) {
const path = url.searchParams.get('path');
if (!path) {
return sendJson(res, 400, { Message: "Missing required query parameter 'path'." });
}
const image = await getImageByHash(path, '200');
if (!image) {
return sendJson(res, 404, { Message: `No image was found for path '${path}'.` });
}
const buffer = await resizeImage(image.buffer);
return sendBinary(res, 200, buffer, image.contentType);
};
}