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

@@ -19,7 +19,7 @@ export const imageToolDefinitions = [
{
name: "upload_image_from_url",
description:
"Fetch an image from a URL and save it locally. Returns the filename to use with create_item or add_candidate.",
"Fetch an image from a URL and upload it to storage. Returns the filename to use with create_item or add_candidate.",
inputSchema: {
url: z
.string()

View File

@@ -7,6 +7,7 @@ import {
getItemById,
updateItem,
} from "../../services/item.service.ts";
import { withImageUrl, withImageUrls } from "../../services/storage.service.ts";
type Db = typeof prodDb;
@@ -95,13 +96,11 @@ export function registerItemTools(db: Db, userId: number) {
return {
list_items: async (args: { categoryId?: number }): Promise<ToolResult> => {
try {
const items = await getAllItems(db, userId);
let items = await getAllItems(db, userId);
if (args.categoryId) {
return textResult(
items.filter((i) => i.categoryId === args.categoryId),
);
items = items.filter((i) => i.categoryId === args.categoryId);
}
return textResult(items);
return textResult(await withImageUrls(items));
} catch (err) {
return errorResult((err as Error).message);
}
@@ -111,7 +110,7 @@ export function registerItemTools(db: Db, userId: number) {
try {
const item = await getItemById(db, userId, args.id);
if (!item) return errorResult(`Item ${args.id} not found`);
return textResult(item);
return textResult(await withImageUrl(item));
} catch (err) {
return errorResult((err as Error).message);
}

View File

@@ -1,5 +1,6 @@
import { z } from "zod";
import type { db as prodDb } from "../../../db/index.ts";
import { withImageUrls } from "../../services/storage.service.ts";
import {
createCandidate,
createThread,
@@ -134,7 +135,8 @@ export function registerThreadTools(db: Db, userId: number) {
try {
const thread = await getThreadWithCandidates(db, userId, args.id);
if (!thread) return errorResult(`Thread ${args.id} not found`);
return textResult(thread);
const enrichedCandidates = await withImageUrls(thread.candidates);
return textResult({ ...thread, candidates: enrichedCandidates });
} catch (err) {
return errorResult((err as Error).message);
}