Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. async function shopfifyImagesToAssetList(cfEnv, shopifyProduct) {
  2. return await Promise.all(
  3. shopifyProduct.images.map(async shopImg => {
  4. try {
  5. let asset = await cfEnv.getAsset(shopImg.id.toString())
  6. asset.fields.description['en-US'] = shopImg.alt
  7. return await asset.update()
  8. } catch {
  9. const imageData = {
  10. fields: {
  11. title: {
  12. 'en-US': shopifyProduct.handle + ' Shopify Product Image'
  13. },
  14. description: {
  15. 'en-US': shopImg.alt
  16. },
  17. file: {
  18. 'en-US': {
  19. contentType:
  20. 'image/' +
  21. shopImg.src
  22. .split('?')
  23. .shift()
  24. .split('.')
  25. .pop(),
  26. fileName: shopImg.src
  27. .split('?')
  28. .shift()
  29. .split('/')
  30. .pop(),
  31. upload: shopImg.src.split('?').shift()
  32. }
  33. }
  34. }
  35. }
  36. return await (await cfEnv.createAssetWithId(
  37. shopImg.id.toString(),
  38. imageData
  39. )).processForAllLocales()
  40. }
  41. })
  42. )
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement