feat: initial refactor to use marka as backend

This commit is contained in:
Max Richter
2025-10-28 20:15:23 +01:00
parent 0beb3b1071
commit f680b5f832
39 changed files with 245 additions and 1012 deletions

View File

@@ -1,8 +1,6 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
import { getImageContent } from "@lib/image.ts";
import { SILVERBULLET_SERVER } from "@lib/env.ts";
import { createLogger } from "@lib/log/index.ts";
import { isLocalImage } from "@lib/string.ts";
const log = createLogger("api/image");
@@ -64,11 +62,10 @@ function parseParams(reqUrl: URL): ImageParams | string {
// Helper function to generate ETag
async function generateETag(content: ArrayBuffer): Promise<string> {
const hashBuffer = await crypto.subtle.digest("SHA-256", content);
return `"${
Array.from(new Uint8Array(hashBuffer))
.map((b) => b.toString(16).padStart(2, "0"))
.join("")
}"`;
return `"${Array.from(new Uint8Array(hashBuffer))
.map((b) => b.toString(16).padStart(2, "0"))
.join("")
}"`;
}
async function GET(req: Request, _ctx: FreshContext): Promise<Response> {
@@ -83,8 +80,8 @@ async function GET(req: Request, _ctx: FreshContext): Promise<Response> {
});
}
const imageUrl = isLocalImage(params.image)
? `${SILVERBULLET_SERVER}/${params.image.replace(/^\//, "")}`
const imageUrl = params.image.startsWith("resources")
? `https://marka.max-richter.dev/${params.image.replace(/^\//, "")}`
: params.image;
log.debug("Processing image request:", { imageUrl, params });