mirror of
https://github.com/xtrll/MusicMetaFinder.git
synced 2026-04-18 00:03:28 +02:00
24 lines
597 B
JavaScript
24 lines
597 B
JavaScript
import axios from 'axios';
|
|
import fs from 'fs';
|
|
|
|
// This function needs to be something like downloadImageToFile
|
|
export default async function downloadImageToFile(url, downloadPath) {
|
|
try {
|
|
const response = await axios.get(url, {
|
|
responseType: 'stream',
|
|
});
|
|
|
|
const writer = fs.createWriteStream(downloadPath);
|
|
|
|
response.data.pipe(writer);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
writer.on('finish', () => resolve(downloadPath));
|
|
writer.on('error', reject);
|
|
});
|
|
} catch (e) {
|
|
console.error('Error downloading the image:', e);
|
|
throw e;
|
|
}
|
|
}
|