feat(17-02): wire storage service into all routes and MCP tools, remove static /uploads/*

- Replace unlink() with deleteImage() in items and threads routes
- Add withImageUrl/withImageUrls to item, thread, setup GET responses
- Enrich MCP tool responses with presigned image URLs
- Remove /uploads/* static file serving from server index
- Update MCP image tool description (local -> storage)
This commit is contained in:
2026-04-05 12:22:41 +02:00
parent 5ce3f92a78
commit f5d79072f2
7 changed files with 34 additions and 28 deletions

View File

@@ -1,5 +1,3 @@
import { unlink } from "node:fs/promises";
import { join } from "node:path";
import { zValidator } from "@hono/zod-validator";
import { Hono } from "hono";
import { createItemSchema, updateItemSchema } from "../../shared/schemas.ts";
@@ -13,6 +11,11 @@ import {
getItemById,
updateItem,
} from "../services/item.service.ts";
import {
deleteImage,
withImageUrl,
withImageUrls,
} from "../services/storage.service.ts";
type Env = { Variables: { db?: any; userId?: number } };
@@ -45,7 +48,7 @@ app.get("/", async (c) => {
const db = c.get("db");
const userId = c.get("userId")!;
const items = await getAllItems(db, userId);
return c.json(items);
return c.json(await withImageUrls(items));
});
app.get("/:id", async (c) => {
@@ -55,7 +58,7 @@ app.get("/:id", async (c) => {
if (!id) return c.json({ error: "Invalid item ID" }, 400);
const item = await getItemById(db, userId, id);
if (!item) return c.json({ error: "Item not found" }, 404);
return c.json(item);
return c.json(await withImageUrl(item));
});
app.post("/", zValidator("json", createItemSchema), async (c) => {
@@ -99,12 +102,12 @@ app.delete("/:id", async (c) => {
const deleted = await deleteItem(db, userId, id);
if (!deleted) return c.json({ error: "Item not found" }, 404);
// Clean up image file if exists
// Clean up image from object storage if exists
if (deleted.imageFilename) {
try {
await unlink(join("uploads", deleted.imageFilename));
await deleteImage(deleted.imageFilename);
} catch {
// File missing is not an error worth failing the delete over
// Missing object is not an error worth failing the delete over
}
}

View File

@@ -7,6 +7,7 @@ import {
updateSetupSchema,
} from "../../shared/schemas.ts";
import { parseId } from "../lib/params.ts";
import { withImageUrls } from "../services/storage.service.ts";
import {
createSetup,
deleteSetup,
@@ -46,7 +47,8 @@ app.get("/:id", async (c) => {
if (!id) return c.json({ error: "Invalid setup ID" }, 400);
const setup = await getSetupWithItems(db, userId, id);
if (!setup) return c.json({ error: "Setup not found" }, 404);
return c.json(setup);
const enrichedItems = await withImageUrls(setup.items);
return c.json({ ...setup, items: enrichedItems });
});
app.put("/:id", zValidator("json", updateSetupSchema), async (c) => {

View File

@@ -1,5 +1,3 @@
import { unlink } from "node:fs/promises";
import { join } from "node:path";
import { zValidator } from "@hono/zod-validator";
import { Hono } from "hono";
import {
@@ -11,6 +9,10 @@ import {
updateThreadSchema,
} from "../../shared/schemas.ts";
import { parseId } from "../lib/params.ts";
import {
deleteImage,
withImageUrls,
} from "../services/storage.service.ts";
import {
createCandidate,
createThread,
@@ -53,7 +55,8 @@ app.get("/:id", async (c) => {
if (!id) return c.json({ error: "Invalid thread ID" }, 400);
const thread = await getThreadWithCandidates(db, userId, id);
if (!thread) return c.json({ error: "Thread not found" }, 404);
return c.json(thread);
const enrichedCandidates = await withImageUrls(thread.candidates);
return c.json({ ...thread, candidates: enrichedCandidates });
});
app.put("/:id", zValidator("json", updateThreadSchema), async (c) => {
@@ -75,12 +78,12 @@ app.delete("/:id", async (c) => {
const deleted = await deleteThread(db, userId, id);
if (!deleted) return c.json({ error: "Thread not found" }, 404);
// Clean up candidate image files
// Clean up candidate images from object storage
for (const filename of deleted.candidateImages) {
try {
await unlink(join("uploads", filename));
await deleteImage(filename);
} catch {
// File missing is not an error worth failing the delete over
// Missing object is not an error worth failing the delete over
}
}
@@ -131,12 +134,12 @@ app.delete("/:threadId/candidates/:candidateId", async (c) => {
const deleted = await deleteCandidate(db, userId, candidateId);
if (!deleted) return c.json({ error: "Candidate not found" }, 404);
// Clean up image file if exists
// Clean up image from object storage if exists
if (deleted.imageFilename) {
try {
await unlink(join("uploads", deleted.imageFilename));
await deleteImage(deleted.imageFilename);
} catch {
// File missing is not an error
// Missing object is not an error
}
}