Skip to content

Instantly share code, notes, and snippets.

@sebbean
Created March 19, 2019 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebbean/b2fd35f4cd8e1556aff15dcb21d75619 to your computer and use it in GitHub Desktop.
Save sebbean/b2fd35f4cd8e1556aff15dcb21d75619 to your computer and use it in GitHub Desktop.
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