check if photo already downloaded

This commit is contained in:
2026-01-12 19:45:19 +03:00
parent 123bda888f
commit 3264b7c6d9
2 changed files with 14 additions and 9 deletions
+9 -8
View File
@@ -36,21 +36,22 @@ export class OllamaChat extends ChatCommand {
const maxSize = await getPhotoMaxSize(msg.photo);
if (maxSize) {
const res = await axios.get<ArrayBuffer>(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<ArrayBuffer>(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;
}
}
}
+5 -1
View File
@@ -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(