@@ -26,32 +26,33 @@ const Home = ({
2626
2727 /** UTILS */
2828 const elimanateNotFoundImages = ( url ) => {
29- const optimisedURL = url . replace ( '1080x720' , '100x100' ) ;
3029 return new Promise ( ( resolve ) => {
31- if ( url . includes ( "http" ) ) {
30+ if ( url . includes ( "http" ) ) {
3231 const xhr = new XMLHttpRequest ( ) ;
33- xhr . open ( "GET" , optimisedURL ) ;
32+ xhr . open ( "GET" , url ) ;
3433 xhr . onerror = ( error ) => {
35- console . warn ( 'provided URL is not a valid image' , error ) ;
34+ console . warn ( 'Provided URL is not a valid image' , error ) ;
3635 resolve ( { isValid : false , newURL : null } ) ;
37- }
36+ } ;
3837 xhr . onload = ( ) => {
3938 if ( xhr . responseURL . includes ( 'source-404' ) || xhr . status == 404 ) {
40- return resolve ( { isValid : false , newURL : null } ) ;
39+ resolve ( { isValid : false , newURL : null } ) ;
4140 } else {
42- return resolve ( { isValid : true , newURL : xhr . responseURL . replace ( 'h=100' , 'h=720' ) . replace ( 'w=100' , 'w=1080' ) } ) ;
41+ resolve ( { isValid : true , newURL : xhr . responseURL } ) ;
4342 }
4443 } ;
4544 xhr . send ( ) ;
46- } else resolve ( false ) ;
47- } ) ;
45+ } else {
46+ resolve ( { isValid : false , newURL : null } ) ;
47+ }
48+ } ) ;
4849 } ;
4950 /** UTILS END */
5051
5152 const seeder = new buildfire . components . aiStateSeeder ( {
5253 generateOptions : {
5354 userMessage : 'Provide me with images that relate to [Traveling]' ,
54- systemMessage : 'Use source.unsplash .com for image URLs, image should be 1080x720, use different image for each entry, URL should not have premium_photo or source.unsplash.com/random. Do not remove white spaces in the subject string. ' ,
55+ systemMessage : 'Use https://app.buildfire .com/api/stockImages/?topic={topic}&imageType=medium for image URLs, and use "random" as a default, A maximum of 2 comma-separated topic can be used for each URL, make sure to generate 10 images ' ,
5556 hintText : 'Replace values between brackets to match your requirements.' ,
5657 maxRecords : 10 ,
5758 jsonTemplate : {
@@ -85,17 +86,15 @@ const Home = ({
8586 } ) ;
8687 }
8788 const promises = imageList . map (
88- item =>
89+ item =>
8990 {
90- return new Promise ( ( resolve , reject ) => {
91- elimanateNotFoundImages ( item . url ) . then ( result => {
91+ return elimanateNotFoundImages ( item . url ) . then ( result => {
9292 if ( result . isValid ) {
93- resolve ( result . newURL + `?v= ${ generateRandomNumber ( ) } ` ) ;
93+ return result . newURL ;
9494 } else {
95- reject ( 'image URL is not valid' ) ;
95+ throw new Error ( 'image URL not valid' ) ;
9696 }
9797 } )
98- } )
9998 }
10099 ) ;
101100 if ( ! promises . length ) {
@@ -132,7 +131,7 @@ const Home = ({
132131 images : processedImages ,
133132 folders : processedFolders ,
134133 } ;
135-
134+
136135 saveAIData ( data , true ) ;
137136 seeder . requestResult . complete ( ) ;
138137 } ) ;
@@ -142,9 +141,9 @@ const Home = ({
142141 jsonTemplate : {
143142 folders : [ { name : '' , images : [ { url : '' } ] } ]
144143 } ,
145- sampleCSV : 'Weather, https://source.unsplash .com/featured/? sunny\n'
146- + 'Weather, https://source.unsplash .com/featured/? rainy\n'
147- + 'City, https://source.unsplash .com/featured/?street ' ,
144+ sampleCSV : 'Weather, https://app.buildfire .com/api/stockImages/?topic= sunny&imageType=medium \n'
145+ + 'Weather, https://app.buildfire .com/api/stockImages/?topic= rainy&imageType=medium \n'
146+ + 'City, https://app.buildfire .com/api/stockImages/?topic=city&imageType=medium ' ,
148147 systemMessage : 'Each row contains a folder name and image URL that should belong to. if nothing provided or no URLs provided then return null' ,
149148 maxRecords : 5 ,
150149 hintText : 'You may repeat a folder name on multiple lines to assign multiple images to the same folder.' ,
@@ -201,7 +200,7 @@ const Home = ({
201200 } ) ;
202201 processedImages . push ( image ) ;
203202 const folder = processedFolders . find ( f => f . name === item . value . getAttribute ( 'data-folder' ) ) ;
204-
203+
205204 if ( ! folder ) {
206205 processedFolders . push ( new Folder ( { name : item . value . getAttribute ( 'data-folder' ) , images : [ image ] } ) ) ;
207206 } else {
0 commit comments