feat(29-01): extract dominant color in image upload endpoints
Both POST /api/images and POST /api/images/from-url now return dominantColor in their response body. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,10 @@ import { randomUUID } from "node:crypto";
|
|||||||
import { zValidator } from "@hono/zod-validator";
|
import { zValidator } from "@hono/zod-validator";
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { fetchImageFromUrl } from "../services/image.service";
|
import {
|
||||||
|
extractDominantColor,
|
||||||
|
fetchImageFromUrl,
|
||||||
|
} from "../services/image.service";
|
||||||
import { uploadImage } from "../services/storage.service";
|
import { uploadImage } from "../services/storage.service";
|
||||||
|
|
||||||
const ALLOWED_TYPES = ["image/jpeg", "image/png", "image/webp"];
|
const ALLOWED_TYPES = ["image/jpeg", "image/png", "image/webp"];
|
||||||
@@ -59,7 +62,10 @@ app.post("/", async (c) => {
|
|||||||
const buffer = await file.arrayBuffer();
|
const buffer = await file.arrayBuffer();
|
||||||
await uploadImage(Buffer.from(buffer), filename, file.type);
|
await uploadImage(Buffer.from(buffer), filename, file.type);
|
||||||
|
|
||||||
return c.json({ filename }, 201);
|
// Extract dominant color for adaptive background fill
|
||||||
|
const dominantColor = await extractDominantColor(buffer);
|
||||||
|
|
||||||
|
return c.json({ filename, dominantColor }, 201);
|
||||||
});
|
});
|
||||||
|
|
||||||
export { app as imageRoutes };
|
export { app as imageRoutes };
|
||||||
|
|||||||
Reference in New Issue
Block a user