Skip to content

Commit 5364659

Browse files
authored
Merge pull request #118 from BuildFire/handle-stock-images
fix(generate ai) : replace unsplash api with buildfire stock images
2 parents 894e76b + 19c20eb commit 5364659

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

control/content/app.services.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@
199199
{
200200
type: 'Location',
201201
location: result[0].formatted_address || location,
202-
location_coordinates: [result[0].geometry.location.lng(), result[0].geometry.location.lat()]
202+
location_coordinates: [result[0].geometry.location.lng(), result[0].geometry.location.lat()]
203203
});
204204
} else {
205205
resolve({
206206
type: 'Location',
207207
location: location,
208-
location_coordinates: []
208+
location_coordinates: []
209209
});
210210
};
211211
});
@@ -216,11 +216,10 @@
216216
};
217217

218218
const parseImageURL = function(url) {
219-
const optimizedURL = url.replace('1080x720', '100x100');
220219
return new Promise((resolve) => {
221220
if (url.includes("http")){
222221
const xhr = new XMLHttpRequest();
223-
xhr.open("GET", optimizedURL);
222+
xhr.open("GET", url);
224223
xhr.onerror = (error) => {
225224
console.warn('provided URL is not a valid image', error);
226225
resolve('');
@@ -229,7 +228,7 @@
229228
if (xhr.responseURL.includes('source-404') || xhr.status == 404) {
230229
return resolve('');
231230
} else {
232-
return resolve(xhr.responseURL.replace('h=100', 'h=720').replace('w=100', 'w=1080'));
231+
return resolve(xhr.responseURL);
233232
}
234233
};
235234
xhr.send();
@@ -271,7 +270,7 @@
271270
data.imagesURLs = [];
272271
}
273272

274-
// add links based on the contact info provided
273+
// add links based on the contact info provided
275274
let links = [];
276275
const emailRegex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
277276
if (data.email && data.email.match(emailRegex)) {
@@ -304,14 +303,15 @@
304303
err ||
305304
!response ||
306305
typeof response !== 'object' ||
307-
!Object.keys(response).length || !response.data
306+
!Object.keys(response).length || !response.data || !response.data.imagesURLs || !response.data.imagesURLs.length
308307
) {
308+
stateSeederInstance?.requestResult?.complete();
309309
return buildfire.dialog.toast({
310310
message: 'Bad AI request, please try changing your request.',
311311
type: 'danger',
312312
});
313313
}
314-
314+
315315
let optimizedURLs = [];
316316
let promises = response.data.imagesURLs.map(url => {
317317
return parseImageURL(url)
@@ -362,7 +362,7 @@
362362
userMessage: `Generate a contact us information related to [business-type] located in [target-region].\nFor phone number use [+1 555 555-1234].\nFor email use [${user?.email || ''}].`,
363363
maxRecords: 5,
364364
systemMessage:
365-
'images are two 1080x720 images URLs related to location, use source.unsplash.com for images, URL should not have premium_photo or source.unsplash.com/random. return description as HTML',
365+
'imagesURLs are two images related to the business type or the target region, topic should be transformed to kebab-case, use https://app.buildfire.com/api/stockImages/?topic={topic}&imageType=medium. return description as HTML',
366366
jsonTemplate: jsonTemplate,
367367
callback: handleAIReq.bind(this),
368368
hintText: 'Replace values between brackets to match your requirements.',
@@ -373,4 +373,4 @@
373373
},
374374
}
375375
}])
376-
})(window.angular, window.buildfire);
376+
})(window.angular, window.buildfire);

0 commit comments

Comments
 (0)