This commit is contained in:
@@ -99,7 +99,7 @@ async function downloadTcgImage(productId, imageUrl) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
const applyImageToItem = async (itemId, localImagePath, token) => {
|
||||
const applyImageToItem = async (itemId, localImagePath, fileName, token) => {
|
||||
try {
|
||||
console.log(`Local Image Path: ${localImagePath}`);
|
||||
|
||||
@@ -109,7 +109,7 @@ const applyImageToItem = async (itemId, localImagePath, token) => {
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append(localImagePath, fs.readFileSync(localImagePath));
|
||||
formData.append('image', fs.readFileSync(localImagePath), filename);
|
||||
const response = await fetch(`${koillectionBaseUrl}/items/${itemId}/image`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -211,7 +211,7 @@ const createCollectionFromCSV = async (name, csvFilePath) => {
|
||||
// Await each download before starting the next
|
||||
// const { destination } = await downloadTcgImage(productId, item.imageUrl);
|
||||
|
||||
item.itemIds.forEach((id) => itemIdImageLocations.push({ itemId: id, imageDest: path.join(imagesDir, `${productId}.jpg`) }));
|
||||
item.itemIds.forEach((id) => itemIdImageLocations.push({ itemId: id, imageDest: imagesDir, fileName: `${productId}.jpg` }));
|
||||
}
|
||||
|
||||
// After processing all collections, check the imagesDir
|
||||
@@ -221,7 +221,7 @@ const createCollectionFromCSV = async (name, csvFilePath) => {
|
||||
console.log(`Item ID Image Locations: ${JSON.stringify(itemIdImageLocations, null, 2)}`);
|
||||
// Process multiple images concurrently using Promise.all()
|
||||
const promises = itemIdImageLocations.map(async (item) => {
|
||||
await applyImageToItem(item.itemId, item.imageDest, token);
|
||||
await applyImageToItem(item.itemId, item.imageDest, item.fileName, token);
|
||||
});
|
||||
await Promise.all(promises);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user