This commit is contained in:
seb
2026-10-18 16:24:37 +02:00
parent 7445a573ab
commit 69a9781cb6
2 changed files with 11 additions and 48 deletions

View File

@@ -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<Buffer>}
*/
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;
}
/**