Created
March 19, 2019 02:25
-
-
Save sebbean/b2fd35f4cd8e1556aff15dcb21d75619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function shopfifyImagesToAssetList(cfEnv, shopifyProduct) { | |
return await Promise.all( | |
shopifyProduct.images.map(async shopImg => { | |
try { | |
let asset = await cfEnv.getAsset(shopImg.id.toString()) | |
asset.fields.description['en-US'] = shopImg.alt | |
return await asset.update() | |
} catch { | |
const imageData = { | |
fields: { | |
title: { | |
'en-US': shopifyProduct.handle + ' Shopify Product Image' | |
}, | |
description: { | |
'en-US': shopImg.alt | |
}, | |
file: { | |
'en-US': { | |
contentType: | |
'image/' + | |
shopImg.src | |
.split('?') | |
.shift() | |
.split('.') | |
.pop(), | |
fileName: shopImg.src | |
.split('?') | |
.shift() | |
.split('/') | |
.pop(), | |
upload: shopImg.src.split('?').shift() | |
} | |
} | |
} | |
} | |
return await (await cfEnv.createAssetWithId( | |
shopImg.id.toString(), | |
imageData | |
)).processForAllLocales() | |
} | |
}) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment