check if photo already downloaded
This commit is contained in:
@@ -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
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user