Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- }
- })
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement