vtb-appit 0.0.41 → 0.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/appit.js +49 -22
  2. package/package.json +1 -1
package/appit.js CHANGED
@@ -102,6 +102,9 @@ class Appit {
102
102
  let model = await this.createExcursion({...excursion, ...images, workspace_id: this.transformer.workspace_id});
103
103
  this.history.excursionId = model.data.id;
104
104
  } else {
105
+ if(excursion.hasOwnProperty('code'))
106
+ delete excursion.code;
107
+
105
108
  await this.updateExcursion(this.history.excursionId, {...excursion, ...images, workspace_id: this.transformer.workspace_id});
106
109
  }
107
110
  }
@@ -113,12 +116,15 @@ class Appit {
113
116
  for(let i = 0; i < places.length; i++) {
114
117
  let place = this.clean(JSON.parse(JSON.stringify(places[i])));
115
118
 
119
+ const images = (place.images.length) ? await this.getImages(place.images, 'original/lg') : {};
120
+ delete place.images;
121
+
116
122
  let id = this.findId('places', places[i].object_id);
117
123
  if(!id) {
118
- let model = await this.createPlace({...place, excursion_id: this.history.excursionId});
124
+ let model = await this.createPlace({...place, ...images, excursion_id: this.history.excursionId});
119
125
  this.history.places[places[i].object_id] = model.data.id;
120
126
  } else {
121
- await this.updatePlace(id, {...place, excursion_id: this.history.excursionId});
127
+ await this.updatePlace(id, {...place, ...images, excursion_id: this.history.excursionId});
122
128
  }
123
129
  }
124
130
  }
@@ -203,16 +209,15 @@ class Appit {
203
209
  let accommodation = this.clean(JSON.parse(JSON.stringify(accommodations[i])));
204
210
  let labels = this.getLabels(accommodations[i]);
205
211
 
206
- if(accommodation.images && accommodation.images.length) {
207
- accommodation.images = await this.mediaToBase64(accommodation.images);
208
- }
212
+ const images = (accommodation.images.length) ? await this.getImages(accommodation.images, 'original/lg') : {};
213
+ delete accommodation.images;
209
214
 
210
215
  let id = this.findId('accommodations', accommodations[i].object_id);
211
216
  if(!id) {
212
- let model = await this.createAccommodation({...accommodation, labels: labels, excursion_id: this.history.excursionId});
217
+ let model = await this.createAccommodation({...accommodation, ...images, labels: labels, excursion_id: this.history.excursionId});
213
218
  this.history.accommodations[accommodations[i].object_id] = model.data.id;
214
219
  } else {
215
- await this.updateAccommodation(id, {...accommodation, labels: labels, excursion_id: this.history.excursionId});
220
+ await this.updateAccommodation(id, {...accommodation, ...images, labels: labels, excursion_id: this.history.excursionId});
216
221
  }
217
222
  }
218
223
  }
@@ -268,9 +273,9 @@ class Appit {
268
273
  return [];
269
274
  }
270
275
 
271
- getImages(media, crop)
276
+ async getImages(media, crop)
272
277
  {
273
- const result = {
278
+ let result = {
274
279
  file_size: [],
275
280
  file_mime_type: [],
276
281
  file_name: [],
@@ -279,8 +284,26 @@ class Appit {
279
284
  file_type: []
280
285
  };
281
286
 
282
- return new Promise((resolve, reject) => {
283
- media.forEach(image => {
287
+ const parsed = await this.getImageParsed(media, crop);
288
+
289
+ parsed.forEach(image => {
290
+ result.file_name.push(image.file_name);
291
+ result.file_path.push(image.file_path);
292
+ result.file_mime_type.push(image.file_mime_type);
293
+ result.file_size.push(image.file_size);
294
+ result.file_active.push(image.file_active);
295
+ result.file_type.push(image.file_type);
296
+ });
297
+
298
+ return result;
299
+ }
300
+
301
+ getImageParsed(media, crop)
302
+ {
303
+ let promises = []
304
+
305
+ media.forEach(image => {
306
+ promises.push(new Promise((resolve, reject) => {
284
307
  const regex = (image.url.match(/amazonaws\.com/)) ? /\.com\/(.*?)\/((?:.*?)\/(?:.*?))\//g : /\.(?:nl|com|travel|io|be)\.?\/((?:.*?)\/(?:.*?))\//g;
285
308
  const match = regex.exec(image.url);
286
309
 
@@ -294,22 +317,26 @@ class Appit {
294
317
  res.on('data', chunk => {
295
318
  body += chunk;
296
319
  })
297
-
320
+
298
321
  res.on('end', () => {
299
322
  const frags = image.url.split('/');
300
- result.file_name.push(frags[frags.length - 1]);
301
- result.file_path.push(image.url);
302
- result.file_mime_type.push(res.headers['content-type']);
303
- result.file_size.push(res.headers['content-length']);
304
- result.file_active.push(1)
305
- result.file_type.push(1);
306
-
307
- resolve(result);
323
+
324
+ resolve({
325
+ file_name: frags[frags.length - 1],
326
+ file_path: image.url,
327
+ file_mime_type: res.headers['content-type'],
328
+ file_size: res.headers['content-length'],
329
+ file_active: 1,
330
+ file_type: 1
331
+ });
308
332
  })
309
333
  });
310
334
  req.end();
311
- });
312
- })
335
+ }));
336
+ });
337
+
338
+
339
+ return Promise.all(promises);
313
340
  }
314
341
 
315
342
  async mediaToBase64(media)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtb-appit",
3
- "version": "0.0.41",
3
+ "version": "0.0.44",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {