My script downloads images and it works correctly on Windows, but when I upload it to the build, I get broken links
Links in an array have a path like the one in the picture.
What should be the correct path if I download on the server?
My function download:
async function downloadAndSaveImages(cleanLinks, folderPath) {
const arr = []
try {
await fs.mkdir(folderPath, { recursive: true });
let command = `cd ${folderPath} && curl `
+ Array(cleanLinks.length).fill('-O').join(' ')
+ ' '
+ Array(cleanLinks.length).fill(null).map((_, i) => {
return cleanLinks[i].split('?')[0]
}).join(' ')
+ ' --parallel'
for (let i = 0; i < cleanLinks.length; i++) {
const imageUrl = cleanLinks[i].replace(/?.*/, '');
const imageFileName = path.basename(imageUrl);
const imagePath = path.join(folderPath, imageFileName).replace(/\/g, '/')
console.log(`image save: ${imagePath}`);
arr.push(imagePath.replace(/.*?images/, '/images'))
}
await exec(command, { timeout: 5000 })
return arr;
} catch (error) {
console.error('erroe for download image:', error);
return arr
}
}
const cleanLinksNew = await downloadAndSaveImages(cleanLinks, photoFolderPath);
on DB save : img: {
set: cleanLinksNew
}