From 123bda888f1912a28ff40ea920d1fb26933e8eb5 Mon Sep 17 00:00:00 2001 From: Danil Nikolaev Date: Mon, 12 Jan 2026 19:41:40 +0300 Subject: [PATCH] move max_photo_size to environment variable --- src/commands/ollama-chat.ts | 2 +- src/common/environment.ts | 4 ++++ src/util/utils.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/commands/ollama-chat.ts b/src/commands/ollama-chat.ts index b7ad58a..7546fe0 100644 --- a/src/commands/ollama-chat.ts +++ b/src/commands/ollama-chat.ts @@ -34,7 +34,7 @@ export class OllamaChat extends ChatCommand { let imageFilePath: string | null = null; - const maxSize = await getPhotoMaxSize(msg.photo, 600); + const maxSize = await getPhotoMaxSize(msg.photo); if (maxSize) { const res = await axios.get(maxSize.url, {responseType: "arraybuffer"}); const src = Buffer.from(res.data); diff --git a/src/common/environment.ts b/src/common/environment.ts index 7fb14a0..865a536 100644 --- a/src/common/environment.ts +++ b/src/common/environment.ts @@ -22,6 +22,8 @@ export class Environment { static OLLAMA_API_KEY?: string; static SYSTEM_PROMPT?: string; + static MAX_PHOTO_SIZE: number; + static GEMINI_API_KEY?: string; static waitText = "⏳ Дайте-ка подумать..."; @@ -45,6 +47,8 @@ export class Environment { Environment.OLLAMA_API_KEY = process.env.OLLAMA_API_KEY; Environment.SYSTEM_PROMPT = process.env.SYSTEM_PROMPT?.trim(); + Environment.MAX_PHOTO_SIZE = Number(process.env.MAX_PHOTO_SIZE || "1280"); + Environment.GEMINI_API_KEY = process.env.GEMINI_API_KEY; } diff --git a/src/util/utils.ts b/src/util/utils.ts index 8151c6d..fe52627 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -754,7 +754,7 @@ export function getRuntimeInfo(): RuntimeInfo { export type PhotoMaxSize = { width: number, height: number, url: string; unique_file_id: string; }; -export async function getPhotoMaxSize(photos: PhotoSize[], target: number = 1280): Promise { +export async function getPhotoMaxSize(photos: PhotoSize[], target: number = Environment.MAX_PHOTO_SIZE): Promise { if (!photos) return null; photos = photos.filter(p => Math.max(p.width, p.height) <= target);