|
221 | 221 | itemsList = data.data.items; |
222 | 222 | //Check image URLs |
223 | 223 | let items = itemsList.map((item, i) => { |
224 | | - return new Promise((resolve, reject) => { |
225 | | - elimanateNotFoundImages(item.listImage).then(res => { |
226 | | - if (res.isValid) { |
227 | | - item.listImage = res.newURL; |
228 | | - item.order = i; |
229 | | - orderedItems.push(item); |
230 | | - resolve(item); |
231 | | - } else { |
232 | | - reject('image URL not valid'); |
233 | | - } |
234 | | - }) |
235 | | - }) |
236 | | - }) |
| 224 | + return elimanateNotFoundImages(item.listImage).then(res => { |
| 225 | + if (res.isValid) { |
| 226 | + item.listImage = res.newURL; |
| 227 | + item.order = i; |
| 228 | + orderedItems.push(item); |
| 229 | + return item; |
| 230 | + } else { |
| 231 | + throw new Error('image URL not valid'); |
| 232 | + } |
| 233 | + }); |
| 234 | + }); |
237 | 235 |
|
238 | 236 | Promise.allSettled(items).then(results => { |
239 | 237 | itemsList = []; |
|
366 | 364 | } |
367 | 365 |
|
368 | 366 | let elimanateNotFoundImages = function(url) { |
369 | | - const optimisedURL = url.replace('1080x720', '100x100'); |
370 | 367 | return new Promise((resolve) => { |
371 | | - if (url.includes("http")){ |
| 368 | + if (url.includes("http")) { |
372 | 369 | const xhr = new XMLHttpRequest(); |
373 | | - xhr.open("GET", optimisedURL); |
| 370 | + xhr.open("GET", url); |
374 | 371 | xhr.onerror = (error) => { |
375 | | - console.warn('provided URL is not a valid image', error); |
| 372 | + console.warn('Provided URL is not a valid image', error); |
376 | 373 | resolve({isValid: false, newURL: null}); |
377 | | - } |
| 374 | + }; |
378 | 375 | xhr.onload = () => { |
379 | 376 | if (xhr.responseURL.includes('source-404') || xhr.status == 404) { |
380 | | - return resolve({isValid: false ,newURL: null}); |
| 377 | + resolve({isValid: false, newURL: null}); |
381 | 378 | } else { |
382 | | - return resolve({isValid: true, newURL: xhr.responseURL.replace('h=100', 'h=720').replace('w=100', 'w=1080') }); |
| 379 | + resolve({isValid: true, newURL: xhr.responseURL}); |
383 | 380 | } |
384 | 381 | }; |
385 | 382 | xhr.send(); |
386 | | - } else resolve(false); |
| 383 | + } else { |
| 384 | + resolve({isValid: false, newURL: null}); |
| 385 | + } |
387 | 386 | }); |
388 | 387 | }; |
389 | 388 |
|
|
428 | 427 | } |
429 | 428 |
|
430 | 429 | return { |
431 | | - initStateSeeder: function() { |
432 | | - stateSeederInstance = new buildfire.components.aiStateSeeder({ |
433 | | - generateOptions: { |
434 | | - userMessage: `Generate a sample of redeemable items for a new [business-type].`, |
435 | | - maxRecords: 5, |
436 | | - systemMessage: |
437 | | - 'listImage URL related to title and the list type. use source.unsplash.com for image URL, URL should not have premium_photo or source.unsplash.com/random, cost to redeem which is a number greater than zero and less than 100, return description as HTML.', |
438 | | - jsonTemplate: generateJSONTemplate, |
439 | | - callback: handleAIReq.bind(this, false), |
440 | | - hintText: 'Replace values between brackets to match your requirements.', |
441 | | - }, |
442 | | - importOptions: { |
443 | | - jsonTemplate: importJSONTemplate, |
444 | | - sampleCSV: "Hotel Voucher, 50, 10, Redeem this voucher for a one-night stay at a luxurious hotel of your choice, https://source.unsplash.com/featured/?hotel\nFlight Upgrade, 30, 15, Upgrade your economy class ticket to business class, https://source.unsplash.com/featured/?flight\nCity Tour, 20, 5, Explore the city with a guided tour that covers all the major attractions and landmarks, https://source.unsplash.com/featured/?city\nAdventure Activity, 80, 30, Embark on an adrenaline-pumping adventure activity such as bungee jumping or skydiving, https://source.unsplash.com/featured/?adventure", |
445 | | - maxRecords: 15, |
446 | | - hintText: 'Each row should start with a loyalty item title, cost to redeem, points earned, description, and image URL.', |
447 | | - systemMessage: ``, |
448 | | - callback: handleAIReq.bind(this, true), |
449 | | - }, |
450 | | - }).smartShowEmptyState(); |
451 | | - }, |
| 430 | + initStateSeeder: function() { |
| 431 | + stateSeederInstance = new buildfire.components.aiStateSeeder({ |
| 432 | + generateOptions: { |
| 433 | + userMessage: `Generate a sample of redeemable items for a new [business-type].`, |
| 434 | + maxRecords: 5, |
| 435 | + systemMessage: |
| 436 | + 'listImage URL related to the title or the list type. Use https://app.buildfire.com/api/stockImages/?topic={topic}&imageType=medium, A maximum of 2 comma-separated topics can be used for each URL. cost to redeem which is a number greater than zero and less than 100, return description as HTML.', |
| 437 | + jsonTemplate: generateJSONTemplate, |
| 438 | + callback: handleAIReq.bind(this, false), |
| 439 | + hintText: 'Replace values between brackets to match your requirements.', |
| 440 | + }, |
| 441 | + importOptions: { |
| 442 | + jsonTemplate: importJSONTemplate, |
| 443 | + sampleCSV: "Hotel Voucher, 50, 10, Redeem this voucher for a one-night stay at a luxurious hotel of your choice, https://app.buildfire.com/api/stockImages/?topic=hotel&imageType=medium\nFlight Upgrade, 30, 15, Upgrade your economy class ticket to business class, https://app.buildfire.com/api/stockImages/?topic=flight&imageType=medium\nCity Tour, 20, 5, Explore the city with a guided tour that covers all the major attractions and landmarks, https://app.buildfire.com/api/stockImages/?topic=city&imageType=medium\nAdventure Activity, 80, 30, Embark on an adrenaline-pumping adventure activity such as bungee jumping or skydiving, https://app.buildfire.com/api/stockImages/?topic=adventure&imageType=medium", |
| 444 | + maxRecords: 15, |
| 445 | + hintText: 'Each row should start with a loyalty item title, cost to redeem, points earned, description, and image URL.', |
| 446 | + systemMessage: ``, |
| 447 | + callback: handleAIReq.bind(this, true), |
| 448 | + }, |
| 449 | + }).smartShowEmptyState(); |
| 450 | +}, |
452 | 451 | } |
453 | 452 | }]) |
454 | 453 | })(window.angular, window.buildfire); |
0 commit comments