vtb-appit 0.0.42 → 0.0.45

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 +41 -16
  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
  }
@@ -270,9 +273,9 @@ class Appit {
270
273
  return [];
271
274
  }
272
275
 
273
- getImages(media, crop)
276
+ async getImages(media, crop)
274
277
  {
275
- const result = {
278
+ let result = {
276
279
  file_size: [],
277
280
  file_mime_type: [],
278
281
  file_name: [],
@@ -281,12 +284,30 @@ class Appit {
281
284
  file_type: []
282
285
  };
283
286
 
284
- return new Promise((resolve, reject) => {
285
- 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) => {
286
307
  const regex = (image.url.match(/amazonaws\.com/)) ? /\.com\/(.*?)\/((?:.*?)\/(?:.*?))\//g : /\.(?:nl|com|travel|io|be)\.?\/((?:.*?)\/(?:.*?))\//g;
287
308
  const match = regex.exec(image.url);
288
309
 
289
- if(match) {
310
+ if(match && image.url.indexOf('flightdata') === -1) {
290
311
  let replace = (match.length == 3) ? match[2] : match[1];
291
312
  image.url = image.url.replace(replace, crop);
292
313
  }
@@ -296,22 +317,26 @@ class Appit {
296
317
  res.on('data', chunk => {
297
318
  body += chunk;
298
319
  })
299
-
320
+
300
321
  res.on('end', () => {
301
322
  const frags = image.url.split('/');
302
- result.file_name.push(frags[frags.length - 1]);
303
- result.file_path.push(image.url);
304
- result.file_mime_type.push(res.headers['content-type']);
305
- result.file_size.push(res.headers['content-length']);
306
- result.file_active.push(1)
307
- result.file_type.push(1);
308
-
309
- 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
+ });
310
332
  })
311
333
  });
312
334
  req.end();
313
- });
314
- })
335
+ }));
336
+ });
337
+
338
+
339
+ return Promise.all(promises);
315
340
  }
316
341
 
317
342
  async mediaToBase64(media)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtb-appit",
3
- "version": "0.0.42",
3
+ "version": "0.0.45",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {