From 69a9781cb61d73832275750a79d79073d88c70e0 Mon Sep 17 00:00:00 2001 From: seb Date: Sun, 18 Oct 2026 16:24:37 +0200 Subject: [PATCH] u --- src/tools/analyze-image.js | 31 ++++++------------------------- src/tools/edit-image.js | 28 +++++----------------------- 2 files changed, 11 insertions(+), 48 deletions(-) diff --git a/src/tools/analyze-image.js b/src/tools/analyze-image.js index 5f231f9..936b891 100644 --- a/src/tools/analyze-image.js +++ b/src/tools/analyze-image.js @@ -1,7 +1,6 @@ import fs from 'fs'; import path from 'path'; import sharp from 'sharp'; -import jwt from 'jsonwebtoken'; import { defineTool, ToolError, OpenRouterProvider } from 'libllmorbiter'; import env from '../config/env.js'; import { getImageByHash } from '../db/pic.js'; @@ -23,7 +22,7 @@ import { * - 1 image → resized to fit 400×400 and sent as a single WebP. * - 2-9 → composited into a labelled grid (2x1/3x1/2x2/3x2/3x3) with the file name * printed under each cell, so one cheap call can compare many candidates. - * - Database images are addressed as `image/` and fetched from `/image/:hash`. + * - Database images are addressed as `image/`. * * The prompt is assembled from the caller's `prompt` plus a layout summary, so the model * knows which cell is which file. @@ -41,7 +40,6 @@ const GRID_CONFIGS = { const MAX_IMAGES = 9; const SINGLE_BOX = 400; const WEBP_QUALITY = 80; -const IMAGE_TIMEOUT_MS = 10_000; const LABEL_HEIGHT = 26; const LABEL_PAD = 5; @@ -241,34 +239,17 @@ function extractImageInputs(args = {}) { } /** - * Fetches a database image by its content hash using store or authenticated local endpoint. + * Fetches a database image by its content hash using the database store. * @param {string} hash 8-char SHA-256 Base62 * @param {number} googleAuthId * @returns {Promise} */ async function fetchDatabaseImage(hash, googleAuthId) { - try { - const image = await getImageByHash(googleAuthId, hash); - if (image?.buffer) { - return image.buffer; - } - } catch (dbErr) { - try { - const url = `http://127.0.0.1:${env.port}/api/image/${hash}`; - const token = jwt.sign({ id: googleAuthId }, env.jwtSecret, { expiresIn: '5m' }); - const res = await fetch(url, { - headers: { Cookie: `token=${token}` }, - signal: AbortSignal.timeout(IMAGE_TIMEOUT_MS), - }); - if (res.ok) { - return Buffer.from(await res.arrayBuffer()); - } - } catch { - // fallback error ignored - } - throw dbErr; + const image = await getImageByHash(googleAuthId, hash); + if (!image?.buffer) { + throw new Error('Image not found'); } - throw new Error('Image not found'); + return image.buffer; } /** diff --git a/src/tools/edit-image.js b/src/tools/edit-image.js index 44aee6e..1971303 100644 --- a/src/tools/edit-image.js +++ b/src/tools/edit-image.js @@ -1,7 +1,6 @@ import fs from 'fs'; import path from 'path'; import sharp from 'sharp'; -import jwt from 'jsonwebtoken'; import { defineTool, ToolError } from 'libllmorbiter'; import env from '../config/env.js'; import { getImageByHash } from '../db/pic.js'; @@ -135,34 +134,17 @@ function resolveImagesApiUrl() { } /** - * Fetches a database image by its 8-char content hash using store or authenticated local endpoint. + * Fetches a database image by its content hash using the database store. * @param {string} hash * @param {number} googleAuthId * @returns {Promise} */ async function fetchDatabaseImage(hash, googleAuthId) { - try { - const image = await getImageByHash(googleAuthId, hash); - if (image?.buffer) { - return image.buffer; - } - } catch (dbErr) { - try { - const url = `http://127.0.0.1:${env.port}/api/image/${hash}`; - const token = jwt.sign({ id: googleAuthId }, env.jwtSecret, { expiresIn: '5m' }); - const res = await fetch(url, { - headers: { Cookie: `token=${token}` }, - signal: AbortSignal.timeout(IMAGE_FETCH_TIMEOUT_MS), - }); - if (res.ok) { - return Buffer.from(await res.arrayBuffer()); - } - } catch { - // fallback error ignored - } - throw dbErr; + const image = await getImageByHash(googleAuthId, hash); + if (!image?.buffer) { + throw new Error('Image not found'); } - throw new Error('Image not found'); + return image.buffer; } /**