diff --git a/.gitignore b/.gitignore index d0ef245..d23d9c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ /node_modules bun.lock .env -logs/ \ No newline at end of file diff --git a/package.json b/package.json index 7d18b41..c272712 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,13 @@ "cleanup": "rm -rf logs node_modules bun.lockdb" }, "devDependencies": { - "@eslint/js": "^9.24.0", - "@types/bun": "^1.2.8", + "@eslint/js": "^9.23.0", + "@types/bun": "^1.2.6", "@types/ejs": "^3.1.5", - "@typescript-eslint/eslint-plugin": "^8.29.0", - "@typescript-eslint/parser": "^8.29.0", - "eslint": "^9.24.0", - "eslint-plugin-prettier": "^5.2.6", + "@typescript-eslint/eslint-plugin": "^8.28.0", + "@typescript-eslint/parser": "^8.28.0", + "eslint": "^9.23.0", + "eslint-plugin-prettier": "^5.2.5", "eslint-plugin-promise": "^7.2.1", "eslint-plugin-simple-import-sort": "^12.1.1", "eslint-plugin-unicorn": "^56.0.1", @@ -25,11 +25,10 @@ "prettier": "^3.5.3" }, "peerDependencies": { - "typescript": "^5.8.3" + "typescript": "^5.8.2" }, "dependencies": { "ejs": "^3.1.10", - "node-vibrant": "^4.0.3", "marked": "^15.0.7" } } diff --git a/src/routes/api/colors.ts b/src/routes/api/colors.ts deleted file mode 100644 index d8817ca..0000000 --- a/src/routes/api/colors.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { fetch } from "bun"; -import { Vibrant } from "node-vibrant/node"; - -type Palette = Awaited>; - -const routeDef: RouteDef = { - method: "GET", - accepts: "*/*", - returns: "application/json", -}; - -async function handler(request: ExtendedRequest): Promise { - const { url } = request.query; - - if (!url) { - return Response.json({ error: "URL is required" }, { status: 400 }); - } - - if (typeof url !== "string" || !url.startsWith("http")) { - return Response.json({ error: "Invalid URL" }, { status: 400 }); - } - - let res: Response; - try { - res = await fetch(url); - } catch { - return Response.json( - { error: "Failed to fetch image" }, - { status: 500 }, - ); - } - - if (!res.ok) { - return Response.json( - { error: "Image fetch returned error" }, - { status: res.status }, - ); - } - - const type: string | null = res.headers.get("content-type"); - if (!type?.startsWith("image/")) { - return Response.json({ error: "Not an image" }, { status: 400 }); - } - - const buffer: Buffer = Buffer.from(await res.arrayBuffer()); - const base64: string = buffer.toString("base64"); - const colors: Palette = await Vibrant.from(buffer).getPalette(); - - const payload: { - img: string; - colors: Palette; - } = { - img: `data:${type};base64,${base64}`, - colors, - }; - - const compressed: Uint8Array = Bun.gzipSync(JSON.stringify(payload)); - - return new Response(compressed, { - headers: { - "Content-Type": "application/json", - "Content-Encoding": "gzip", - "Cache-Control": "public, max-age=31536000, immutable", - "Access-Control-Allow-Origin": "*", - }, - }); -} - -export { handler, routeDef };