From 3264b7c6d99f15673671c920678bba2d49e4a06b Mon Sep 17 00:00:00 2001 From: Danil Nikolaev Date: Mon, 12 Jan 2026 19:45:19 +0300 Subject: [PATCH] check if photo already downloaded --- src/commands/ollama-chat.ts | 17 +++++++++-------- src/index.ts | 6 +++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/commands/ollama-chat.ts b/src/commands/ollama-chat.ts index 7546fe0..099caec 100644 --- a/src/commands/ollama-chat.ts +++ b/src/commands/ollama-chat.ts @@ -36,21 +36,22 @@ export class OllamaChat extends ChatCommand { const maxSize = await getPhotoMaxSize(msg.photo); if (maxSize) { - const res = await axios.get(maxSize.url, {responseType: "arraybuffer"}); - const src = Buffer.from(res.data); - const imagePath = path.join(Environment.DATA_PATH, "temp"); if (!fs.existsSync(imagePath)) { fs.mkdirSync(imagePath); } imageFilePath = path.join(imagePath, maxSize.unique_file_id + ".jpg"); + if (!fs.existsSync(imageFilePath)) { + const res = await axios.get(maxSize.url, {responseType: "arraybuffer"}); + const src = Buffer.from(res.data); - try { - fs.writeFileSync(imageFilePath, src); - } catch (e) { - console.error(e); - imageFilePath = null; + try { + fs.writeFileSync(imageFilePath, src); + } catch (e) { + console.error(e); + imageFilePath = null; + } } } diff --git a/src/index.ts b/src/index.ts index 87fa369..11ff5c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -126,7 +126,11 @@ if (Environment.GEMINI_API_KEY) { } async function main() { - console.log(`TEST_ENVIRONMENT: ${Environment.TEST_ENVIRONMENT}\nDATA_PATH: ${Environment.DATA_PATH}`); + console.log( + `TEST_ENVIRONMENT: ${Environment.TEST_ENVIRONMENT}\n` + + `DATA_PATH: ${Environment.DATA_PATH}\n` + ` + MAX_PHOTO_SIZE: ${Environment.MAX_PHOTO_SIZE}` + ); try { const results = await Promise.all(