@crystaldesign/media-upload 24.13.0-beta.2 → 24.13.0-beta.21
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.
- package/build/cjs/index.js +446 -178
- package/build/esm/index.js +446 -178
- package/build/types/media-upload/src/DivaFile.d.ts +11 -2
- package/build/types/media-upload/src/DivaFile.d.ts.map +1 -1
- package/build/types/media-upload/src/index.d.ts.map +1 -1
- package/build/types/media-upload/src/types.d.ts +4 -2
- package/build/types/media-upload/src/types.d.ts.map +1 -1
- package/build/umd/266.media-upload.umd.min.js +1 -1
- package/build/umd/721.media-upload.umd.min.js +5 -5
- package/build/umd/944.media-upload.umd.min.js +1 -1
- package/build/umd/media-upload.umd.min.js +1 -1
- package/build/umd/report.html +4 -5
- package/package.json +2 -2
package/build/esm/index.js
CHANGED
|
@@ -179,6 +179,24 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
179
179
|
this._state = 'CHANGED';
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
+
}, {
|
|
183
|
+
key: "setMediaItemAndRef",
|
|
184
|
+
value: function setMediaItemAndRef(_ref) {
|
|
185
|
+
var item = _ref.item,
|
|
186
|
+
ref = _ref.ref;
|
|
187
|
+
this._state = 'SAVED';
|
|
188
|
+
this.itemRef = ref;
|
|
189
|
+
this._url = ref.url;
|
|
190
|
+
this._organizationId = ref.organizationId;
|
|
191
|
+
this._mediaType = ref.mediaType;
|
|
192
|
+
this._functionType = ref.functionType;
|
|
193
|
+
this._ref = ref._id;
|
|
194
|
+
this.item = item;
|
|
195
|
+
this._description = item.description;
|
|
196
|
+
this._borderPercentage = item.borderPercentage;
|
|
197
|
+
this._fileName = item.fileName;
|
|
198
|
+
this._classes = item.classes;
|
|
199
|
+
}
|
|
182
200
|
}, {
|
|
183
201
|
key: "fileName",
|
|
184
202
|
get: function get() {
|
|
@@ -241,49 +259,56 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
241
259
|
}, {
|
|
242
260
|
key: "save",
|
|
243
261
|
value: function () {
|
|
244
|
-
var _save = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
245
|
-
var _this$fileObject, _this$itemRef, _this$itemRef$url, _this$itemRef2, _file2, _url, response, blob, formData, mediaitem, _url2, mediaitemref,
|
|
246
|
-
return _regeneratorRuntime.wrap(function
|
|
247
|
-
while (1) switch (
|
|
262
|
+
var _save = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
|
|
263
|
+
var mediaItemRef, _refUrl, _this$fileObject, _this$itemRef, _this$itemRef$url, _this$itemRef2, _file2, _url, response, blob, formData, mediaitem, _url2, mediaitemref, refs, data, _mediaitemref, media, _media, ref, item, _this$item, _params$refIds, _refs, _this$itemRef3, _this$itemRef4, result;
|
|
264
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
265
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
248
266
|
case 0:
|
|
249
267
|
if (!(!this.itemRef && this._state != 'NEW')) {
|
|
250
|
-
|
|
268
|
+
_context5.next = 22;
|
|
251
269
|
break;
|
|
252
270
|
}
|
|
253
271
|
if (this._ref) {
|
|
254
|
-
|
|
272
|
+
_context5.next = 3;
|
|
255
273
|
break;
|
|
256
274
|
}
|
|
257
275
|
throw new Error('If state is not NEW, there must be a ref present');
|
|
258
276
|
case 3:
|
|
259
|
-
|
|
277
|
+
_context5.next = 5;
|
|
260
278
|
return this.getMediaItemRef(this._ref, (params === null || params === void 0 ? void 0 : params.organizationId) || this._organizationId);
|
|
261
279
|
case 5:
|
|
280
|
+
mediaItemRef = _context5.sent;
|
|
281
|
+
this.itemRef = mediaItemRef;
|
|
282
|
+
if (!this._functionType) this._functionType = this.itemRef.functionType;
|
|
283
|
+
if (!this._description) this._description = this.itemRef.description;
|
|
284
|
+
if (!this._fileName) this._fileName = this.itemRef.fileName;
|
|
285
|
+
this._mediaType = this.itemRef.mediaType;
|
|
286
|
+
if (!(this._organizationId && this._organizationId != this.itemRef.organizationId)) {
|
|
287
|
+
_context5.next = 13;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
throw new Error('The existing mediaItemRef belongs to a different organization');
|
|
291
|
+
case 13:
|
|
292
|
+
this._organizationId = this.itemRef.organizationId;
|
|
293
|
+
this._url = this.itemRef.url;
|
|
294
|
+
this._ref = this.itemRef._id;
|
|
262
295
|
if (this.item) {
|
|
263
|
-
|
|
296
|
+
_context5.next = 22;
|
|
264
297
|
break;
|
|
265
298
|
}
|
|
266
299
|
if (this.itemRef) {
|
|
267
|
-
|
|
300
|
+
_context5.next = 19;
|
|
268
301
|
break;
|
|
269
302
|
}
|
|
270
303
|
throw new Error('If state is not NEW, there must be a url present');
|
|
271
|
-
case
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return this.getMediaItem(this.itemRef.refUrl, (params === null || params === void 0 ? void 0 : params.organizationId) || this._organizationId);
|
|
278
|
-
case 11:
|
|
279
|
-
_context3.next = 15;
|
|
280
|
-
break;
|
|
281
|
-
case 13:
|
|
282
|
-
_context3.next = 15;
|
|
283
|
-
return this.getMediaItem(this.itemRef.url, (params === null || params === void 0 ? void 0 : params.organizationId) || this._organizationId);
|
|
284
|
-
case 15:
|
|
304
|
+
case 19:
|
|
305
|
+
_context5.next = 21;
|
|
306
|
+
return this.getMediaItem((_refUrl = this.itemRef.refUrl) !== null && _refUrl !== void 0 ? _refUrl : this.itemRef.url, (params === null || params === void 0 ? void 0 : params.organizationId) || this._organizationId);
|
|
307
|
+
case 21:
|
|
308
|
+
this.item = _context5.sent;
|
|
309
|
+
case 22:
|
|
285
310
|
if (!(this._state == 'NEW' && !this.isExternalVid(this._url))) {
|
|
286
|
-
|
|
311
|
+
_context5.next = 70;
|
|
287
312
|
break;
|
|
288
313
|
}
|
|
289
314
|
// create the mediaItem
|
|
@@ -291,39 +316,39 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
291
316
|
// for this type we only support url
|
|
292
317
|
_file2 = (_this$fileObject = this.fileObject) === null || _this$fileObject === void 0 ? void 0 : _this$fileObject.file;
|
|
293
318
|
if (!(!_file2 && !this._spinFiles)) {
|
|
294
|
-
|
|
319
|
+
_context5.next = 38;
|
|
295
320
|
break;
|
|
296
321
|
}
|
|
297
322
|
if (this._url) {
|
|
298
|
-
|
|
323
|
+
_context5.next = 27;
|
|
299
324
|
break;
|
|
300
325
|
}
|
|
301
326
|
throw new Error('Either file or url must be specified');
|
|
302
|
-
case
|
|
327
|
+
case 27:
|
|
303
328
|
// if only a url is providied get the actual file
|
|
304
329
|
_url = new URL(this._url);
|
|
305
330
|
if (_url.protocol.startsWith('http')) {
|
|
306
331
|
// add a dummy query to avoid the browser cache (cached response is missing cors headers)
|
|
307
332
|
_url.searchParams.set('dt', Date.now().toString());
|
|
308
333
|
}
|
|
309
|
-
|
|
334
|
+
_context5.next = 31;
|
|
310
335
|
return fetch(_url.toString());
|
|
311
|
-
case
|
|
312
|
-
response =
|
|
336
|
+
case 31:
|
|
337
|
+
response = _context5.sent;
|
|
313
338
|
if (!(response.status === 400)) {
|
|
314
|
-
|
|
339
|
+
_context5.next = 34;
|
|
315
340
|
break;
|
|
316
341
|
}
|
|
317
342
|
throw new Error('Error on saving media.');
|
|
318
|
-
case
|
|
319
|
-
|
|
343
|
+
case 34:
|
|
344
|
+
_context5.next = 36;
|
|
320
345
|
return response.blob();
|
|
321
|
-
case
|
|
322
|
-
blob =
|
|
346
|
+
case 36:
|
|
347
|
+
blob = _context5.sent;
|
|
323
348
|
_file2 = new File([blob], this._fileName, {
|
|
324
349
|
type: blob.type
|
|
325
350
|
});
|
|
326
|
-
case
|
|
351
|
+
case 38:
|
|
327
352
|
formData = new FormData();
|
|
328
353
|
mediaitem = {
|
|
329
354
|
fileName: this._fileName,
|
|
@@ -341,45 +366,26 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
341
366
|
if (this._borderPercentage) {
|
|
342
367
|
mediaitem.borderPercentage = this._borderPercentage;
|
|
343
368
|
}
|
|
344
|
-
if (!this._spinFiles) {
|
|
345
|
-
_context3.next = 44;
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
formData.append('mediaItems', JSON.stringify(mediaitem));
|
|
349
|
-
this._spinFiles.forEach(function (sf) {
|
|
350
|
-
return formData.append('files', sf.file);
|
|
351
|
-
});
|
|
352
|
-
_url2 = "".concat(this.config.url, "/v1/mediaitems/bulk?spin=true");
|
|
353
|
-
if (this.createRef) {
|
|
354
|
-
mediaitemref = {
|
|
355
|
-
functionType: this._functionType
|
|
356
|
-
};
|
|
357
|
-
formData.append('mediaItemRefs', JSON.stringify(mediaitemref));
|
|
358
|
-
_url2 = _url2 + '&ref=true';
|
|
359
|
-
}
|
|
360
|
-
_context3.next = 52;
|
|
361
|
-
break;
|
|
362
|
-
case 44:
|
|
363
369
|
if (!_file2) {
|
|
364
|
-
|
|
370
|
+
_context5.next = 51;
|
|
365
371
|
break;
|
|
366
372
|
}
|
|
367
373
|
formData.append('mediaItem', JSON.stringify(mediaitem));
|
|
368
374
|
formData.append('file', _file2);
|
|
369
375
|
_url2 = "".concat(this.config.url, "/v1/mediaitems");
|
|
370
|
-
if (this.createRef) {
|
|
371
|
-
|
|
376
|
+
if (this.createRef && !(params !== null && params !== void 0 && params.refCount)) {
|
|
377
|
+
mediaitemref = {
|
|
372
378
|
functionType: this._functionType
|
|
373
379
|
};
|
|
374
|
-
formData.append('mediaItemRef', JSON.stringify(
|
|
380
|
+
formData.append('mediaItemRef', JSON.stringify(mediaitemref));
|
|
375
381
|
_url2 = _url2 + '?ref=true';
|
|
376
382
|
}
|
|
377
|
-
|
|
383
|
+
_context5.next = 52;
|
|
378
384
|
break;
|
|
379
385
|
case 51:
|
|
380
386
|
throw new Error('Either file or url must be specified');
|
|
381
387
|
case 52:
|
|
382
|
-
|
|
388
|
+
_context5.next = 54;
|
|
383
389
|
return fetch(_url2, {
|
|
384
390
|
method: 'POST',
|
|
385
391
|
body: formData,
|
|
@@ -387,7 +393,7 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
387
393
|
Authorization: "Bearer ".concat(this.config.jwt)
|
|
388
394
|
} : {}
|
|
389
395
|
}).then(/*#__PURE__*/function () {
|
|
390
|
-
var
|
|
396
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(r) {
|
|
391
397
|
var error, err;
|
|
392
398
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
393
399
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -419,30 +425,79 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
419
425
|
}, _callee, null, [[1, 8]]);
|
|
420
426
|
}));
|
|
421
427
|
return function (_x2) {
|
|
422
|
-
return
|
|
428
|
+
return _ref2.apply(this, arguments);
|
|
423
429
|
};
|
|
424
430
|
}());
|
|
425
431
|
case 54:
|
|
426
|
-
data =
|
|
427
|
-
if (this.
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
} else {
|
|
431
|
-
media = data;
|
|
432
|
+
data = _context5.sent;
|
|
433
|
+
if (!(this.createRef && params !== null && params !== void 0 && params.refCount)) {
|
|
434
|
+
_context5.next = 61;
|
|
435
|
+
break;
|
|
432
436
|
}
|
|
437
|
+
_mediaitemref = {
|
|
438
|
+
functionType: this._functionType
|
|
439
|
+
};
|
|
440
|
+
_url2 = "".concat(this.config.url, "/v1/mediaitems/").concat(data._id, "/refs/").concat(params.refCount);
|
|
441
|
+
_context5.next = 60;
|
|
442
|
+
return fetch(_url2, {
|
|
443
|
+
method: 'POST',
|
|
444
|
+
body: JSON.stringify(_mediaitemref),
|
|
445
|
+
headers: this.config.jwt ? {
|
|
446
|
+
'Content-Type': 'application/json',
|
|
447
|
+
Authorization: "Bearer ".concat(this.config.jwt)
|
|
448
|
+
} : {}
|
|
449
|
+
}).then(/*#__PURE__*/function () {
|
|
450
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(r) {
|
|
451
|
+
var error, err;
|
|
452
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
453
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
454
|
+
case 0:
|
|
455
|
+
if (r.ok) {
|
|
456
|
+
_context2.next = 12;
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
_context2.prev = 1;
|
|
460
|
+
_context2.next = 4;
|
|
461
|
+
return r.json();
|
|
462
|
+
case 4:
|
|
463
|
+
err = _context2.sent;
|
|
464
|
+
error = err.error;
|
|
465
|
+
_context2.next = 11;
|
|
466
|
+
break;
|
|
467
|
+
case 8:
|
|
468
|
+
_context2.prev = 8;
|
|
469
|
+
_context2.t0 = _context2["catch"](1);
|
|
470
|
+
throw new Error('Error while saving');
|
|
471
|
+
case 11:
|
|
472
|
+
throw new Error(error);
|
|
473
|
+
case 12:
|
|
474
|
+
return _context2.abrupt("return", r.json());
|
|
475
|
+
case 13:
|
|
476
|
+
case "end":
|
|
477
|
+
return _context2.stop();
|
|
478
|
+
}
|
|
479
|
+
}, _callee2, null, [[1, 8]]);
|
|
480
|
+
}));
|
|
481
|
+
return function (_x3) {
|
|
482
|
+
return _ref3.apply(this, arguments);
|
|
483
|
+
};
|
|
484
|
+
}());
|
|
485
|
+
case 60:
|
|
486
|
+
refs = _context5.sent;
|
|
487
|
+
case 61:
|
|
488
|
+
media = data;
|
|
433
489
|
_media = media, ref = _media.ref, item = _objectWithoutProperties(_media, _excluded);
|
|
434
490
|
this.item = item;
|
|
435
|
-
this.itemRef = ref;
|
|
491
|
+
this.itemRef = ref !== null && ref !== void 0 ? ref : refs[0];
|
|
436
492
|
this._ref = (_this$itemRef = this.itemRef) === null || _this$itemRef === void 0 ? void 0 : _this$itemRef._id;
|
|
437
493
|
this._url = (_this$itemRef$url = (_this$itemRef2 = this.itemRef) === null || _this$itemRef2 === void 0 ? void 0 : _this$itemRef2.url) !== null && _this$itemRef$url !== void 0 ? _this$itemRef$url : this.item.url;
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
case 63:
|
|
494
|
+
return _context5.abrupt("return", refs);
|
|
495
|
+
case 70:
|
|
441
496
|
if (!(this._state == 'CHANGED')) {
|
|
442
|
-
|
|
497
|
+
_context5.next = 83;
|
|
443
498
|
break;
|
|
444
499
|
}
|
|
445
|
-
|
|
500
|
+
_context5.next = 73;
|
|
446
501
|
return fetch("".concat(this.config.url, "/v1/mediaitems/").concat((_this$item = this.item) === null || _this$item === void 0 ? void 0 : _this$item._id), {
|
|
447
502
|
method: 'PATCH',
|
|
448
503
|
body: JSON.stringify({
|
|
@@ -470,48 +525,115 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
470
525
|
Authorization: "Bearer ".concat(this.config.jwt)
|
|
471
526
|
} : {})
|
|
472
527
|
}).then(/*#__PURE__*/function () {
|
|
473
|
-
var
|
|
528
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(r) {
|
|
474
529
|
var error, err;
|
|
475
|
-
return _regeneratorRuntime.wrap(function
|
|
476
|
-
while (1) switch (
|
|
530
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
531
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
477
532
|
case 0:
|
|
478
533
|
if (r.ok) {
|
|
479
|
-
|
|
534
|
+
_context3.next = 12;
|
|
480
535
|
break;
|
|
481
536
|
}
|
|
482
|
-
|
|
483
|
-
|
|
537
|
+
_context3.prev = 1;
|
|
538
|
+
_context3.next = 4;
|
|
484
539
|
return r.json();
|
|
485
540
|
case 4:
|
|
486
|
-
err =
|
|
541
|
+
err = _context3.sent;
|
|
487
542
|
error = err.error;
|
|
488
|
-
|
|
543
|
+
_context3.next = 11;
|
|
489
544
|
break;
|
|
490
545
|
case 8:
|
|
491
|
-
|
|
492
|
-
|
|
546
|
+
_context3.prev = 8;
|
|
547
|
+
_context3.t0 = _context3["catch"](1);
|
|
493
548
|
throw new Error('Error while saving');
|
|
494
549
|
case 11:
|
|
495
550
|
throw new Error(error);
|
|
496
551
|
case 12:
|
|
497
|
-
return
|
|
552
|
+
return _context3.abrupt("return", r.json());
|
|
498
553
|
case 13:
|
|
499
554
|
case "end":
|
|
500
|
-
return
|
|
555
|
+
return _context3.stop();
|
|
501
556
|
}
|
|
502
|
-
},
|
|
557
|
+
}, _callee3, null, [[1, 8]]);
|
|
503
558
|
}));
|
|
504
|
-
return function (
|
|
505
|
-
return
|
|
559
|
+
return function (_x4) {
|
|
560
|
+
return _ref4.apply(this, arguments);
|
|
561
|
+
};
|
|
562
|
+
}());
|
|
563
|
+
case 73:
|
|
564
|
+
this.item = _context5.sent;
|
|
565
|
+
_refs = (_params$refIds = params === null || params === void 0 ? void 0 : params.refIds) !== null && _params$refIds !== void 0 ? _params$refIds : [this.ref];
|
|
566
|
+
if (!(_refs !== null && _refs !== void 0 && _refs.length)) {
|
|
567
|
+
_context5.next = 83;
|
|
568
|
+
break;
|
|
569
|
+
}
|
|
570
|
+
_context5.next = 78;
|
|
571
|
+
return fetch("".concat(this.config.url, "/v1/mediaitems/refs/bulk"), {
|
|
572
|
+
method: 'PATCH',
|
|
573
|
+
body: JSON.stringify({
|
|
574
|
+
ids: _refs,
|
|
575
|
+
patch: [{
|
|
576
|
+
op: 'replace',
|
|
577
|
+
path: '/functionType',
|
|
578
|
+
value: this._functionType
|
|
579
|
+
}]
|
|
580
|
+
}),
|
|
581
|
+
headers: _objectSpread$1({
|
|
582
|
+
'Content-Type': 'application/json'
|
|
583
|
+
}, this.config.jwt ? {
|
|
584
|
+
Authorization: "Bearer ".concat(this.config.jwt)
|
|
585
|
+
} : {})
|
|
586
|
+
}).then(/*#__PURE__*/function () {
|
|
587
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(r) {
|
|
588
|
+
var error, err;
|
|
589
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
590
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
591
|
+
case 0:
|
|
592
|
+
if (r.ok) {
|
|
593
|
+
_context4.next = 12;
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
_context4.prev = 1;
|
|
597
|
+
_context4.next = 4;
|
|
598
|
+
return r.json();
|
|
599
|
+
case 4:
|
|
600
|
+
err = _context4.sent;
|
|
601
|
+
error = err.error;
|
|
602
|
+
_context4.next = 11;
|
|
603
|
+
break;
|
|
604
|
+
case 8:
|
|
605
|
+
_context4.prev = 8;
|
|
606
|
+
_context4.t0 = _context4["catch"](1);
|
|
607
|
+
throw new Error('Error while saving');
|
|
608
|
+
case 11:
|
|
609
|
+
throw new Error(error);
|
|
610
|
+
case 12:
|
|
611
|
+
return _context4.abrupt("return", r.json());
|
|
612
|
+
case 13:
|
|
613
|
+
case "end":
|
|
614
|
+
return _context4.stop();
|
|
615
|
+
}
|
|
616
|
+
}, _callee4, null, [[1, 8]]);
|
|
617
|
+
}));
|
|
618
|
+
return function (_x5) {
|
|
619
|
+
return _ref5.apply(this, arguments);
|
|
506
620
|
};
|
|
507
621
|
}());
|
|
508
|
-
case
|
|
509
|
-
|
|
510
|
-
|
|
622
|
+
case 78:
|
|
623
|
+
result = _context5.sent;
|
|
624
|
+
this.itemRef = result[0];
|
|
625
|
+
this._ref = (_this$itemRef3 = this.itemRef) === null || _this$itemRef3 === void 0 ? void 0 : _this$itemRef3._id;
|
|
626
|
+
this._url = (_this$itemRef4 = this.itemRef) === null || _this$itemRef4 === void 0 ? void 0 : _this$itemRef4.url;
|
|
627
|
+
return _context5.abrupt("return", result.map(function (r) {
|
|
628
|
+
return r._id;
|
|
629
|
+
}));
|
|
630
|
+
case 83:
|
|
631
|
+
return _context5.abrupt("return", []);
|
|
632
|
+
case 84:
|
|
511
633
|
case "end":
|
|
512
|
-
return
|
|
634
|
+
return _context5.stop();
|
|
513
635
|
}
|
|
514
|
-
},
|
|
636
|
+
}, _callee5, this);
|
|
515
637
|
}));
|
|
516
638
|
function save(_x) {
|
|
517
639
|
return _save.apply(this, arguments);
|
|
@@ -521,60 +643,104 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
521
643
|
}, {
|
|
522
644
|
key: "load",
|
|
523
645
|
value: function () {
|
|
524
|
-
var _load = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
646
|
+
var _load = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
|
|
647
|
+
var _mediaItemRef$refUrl;
|
|
525
648
|
var mediaItemRef;
|
|
526
|
-
return _regeneratorRuntime.wrap(function
|
|
527
|
-
while (1) switch (
|
|
649
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
650
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
528
651
|
case 0:
|
|
529
652
|
if (!(!this.ref || !(params !== null && params !== void 0 && params.organizationId) && !this._organizationId)) {
|
|
530
|
-
|
|
653
|
+
_context6.next = 2;
|
|
531
654
|
break;
|
|
532
655
|
}
|
|
533
656
|
throw new Error('Ref or OrganizationId must be set to load data form server');
|
|
534
657
|
case 2:
|
|
535
658
|
if (!this.itemRef) {
|
|
536
|
-
|
|
659
|
+
_context6.next = 4;
|
|
537
660
|
break;
|
|
538
661
|
}
|
|
539
|
-
return
|
|
662
|
+
return _context6.abrupt("return");
|
|
540
663
|
case 4:
|
|
541
|
-
|
|
664
|
+
_context6.next = 6;
|
|
542
665
|
return this.getMediaItemRef(this.ref, (params === null || params === void 0 ? void 0 : params.organizationId) || this._organizationId);
|
|
543
666
|
case 6:
|
|
544
|
-
mediaItemRef =
|
|
667
|
+
mediaItemRef = _context6.sent;
|
|
668
|
+
this.itemRef = mediaItemRef;
|
|
669
|
+
if (!(this._organizationId && this._organizationId != this.itemRef.organizationId)) {
|
|
670
|
+
_context6.next = 10;
|
|
671
|
+
break;
|
|
672
|
+
}
|
|
673
|
+
throw new Error('The existing mediaItemRef belongs to a different organization');
|
|
674
|
+
case 10:
|
|
675
|
+
this._ref = mediaItemRef._id;
|
|
545
676
|
this._url = mediaItemRef.url;
|
|
546
677
|
this._organizationId = mediaItemRef.organizationId;
|
|
547
678
|
this._mediaType = mediaItemRef.mediaType;
|
|
548
679
|
this._functionType = mediaItemRef.functionType;
|
|
549
680
|
this._state = 'SAVED';
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
_context4.next = 15;
|
|
555
|
-
return this.getMediaItem(mediaItemRef.refUrl, (params === null || params === void 0 ? void 0 : params.organizationId) || this._organizationId);
|
|
556
|
-
case 15:
|
|
557
|
-
_context4.next = 19;
|
|
558
|
-
break;
|
|
559
|
-
case 17:
|
|
560
|
-
_context4.next = 19;
|
|
561
|
-
return this.getMediaItem(mediaItemRef.url, (params === null || params === void 0 ? void 0 : params.organizationId) || this._organizationId);
|
|
562
|
-
case 19:
|
|
681
|
+
_context6.next = 18;
|
|
682
|
+
return this.getMediaItem((_mediaItemRef$refUrl = mediaItemRef.refUrl) !== null && _mediaItemRef$refUrl !== void 0 ? _mediaItemRef$refUrl : mediaItemRef.url, (params === null || params === void 0 ? void 0 : params.organizationId) || this._organizationId);
|
|
683
|
+
case 18:
|
|
684
|
+
this.item = _context6.sent;
|
|
563
685
|
this._description = this.item.description;
|
|
564
686
|
this._borderPercentage = this.item.borderPercentage;
|
|
565
687
|
this._fileName = this.item.fileName;
|
|
566
688
|
this._classes = this.item.classes;
|
|
567
689
|
case 23:
|
|
568
690
|
case "end":
|
|
569
|
-
return
|
|
691
|
+
return _context6.stop();
|
|
570
692
|
}
|
|
571
|
-
},
|
|
693
|
+
}, _callee6, this);
|
|
572
694
|
}));
|
|
573
|
-
function load(
|
|
695
|
+
function load(_x6) {
|
|
574
696
|
return _load.apply(this, arguments);
|
|
575
697
|
}
|
|
576
698
|
return load;
|
|
577
699
|
}()
|
|
700
|
+
}, {
|
|
701
|
+
key: "loadMany",
|
|
702
|
+
value: function () {
|
|
703
|
+
var _loadMany = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
|
|
704
|
+
var _params$refIds2, _params$organizationI, _refs$0$refUrl;
|
|
705
|
+
var refs, mediaItem;
|
|
706
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
707
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
708
|
+
case 0:
|
|
709
|
+
if (params !== null && params !== void 0 && (_params$refIds2 = params.refIds) !== null && _params$refIds2 !== void 0 && _params$refIds2.length) {
|
|
710
|
+
_context7.next = 2;
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
throw new Error('refs are undefined');
|
|
714
|
+
case 2:
|
|
715
|
+
if (!(!(params !== null && params !== void 0 && params.organizationId) && !this._organizationId)) {
|
|
716
|
+
_context7.next = 4;
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
throw new Error('Ref or OrganizationId must be set to load data form server');
|
|
720
|
+
case 4:
|
|
721
|
+
_context7.next = 6;
|
|
722
|
+
return this.getMediaItemRefs(params.refIds, (_params$organizationI = params === null || params === void 0 ? void 0 : params.organizationId) !== null && _params$organizationI !== void 0 ? _params$organizationI : this._organizationId);
|
|
723
|
+
case 6:
|
|
724
|
+
refs = _context7.sent;
|
|
725
|
+
_context7.next = 9;
|
|
726
|
+
return this.getMediaItem((_refs$0$refUrl = refs[0].refUrl) !== null && _refs$0$refUrl !== void 0 ? _refs$0$refUrl : refs[0].url, (params === null || params === void 0 ? void 0 : params.organizationId) || this._organizationId);
|
|
727
|
+
case 9:
|
|
728
|
+
mediaItem = _context7.sent;
|
|
729
|
+
return _context7.abrupt("return", {
|
|
730
|
+
mediaItem: mediaItem,
|
|
731
|
+
refs: refs
|
|
732
|
+
});
|
|
733
|
+
case 11:
|
|
734
|
+
case "end":
|
|
735
|
+
return _context7.stop();
|
|
736
|
+
}
|
|
737
|
+
}, _callee7, this);
|
|
738
|
+
}));
|
|
739
|
+
function loadMany(_x7) {
|
|
740
|
+
return _loadMany.apply(this, arguments);
|
|
741
|
+
}
|
|
742
|
+
return loadMany;
|
|
743
|
+
}()
|
|
578
744
|
}, {
|
|
579
745
|
key: "clone",
|
|
580
746
|
value: function clone() {
|
|
@@ -583,10 +749,10 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
583
749
|
}, {
|
|
584
750
|
key: "getMediaItem",
|
|
585
751
|
value: function () {
|
|
586
|
-
var _getMediaItem = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
752
|
+
var _getMediaItem = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(imageUrl, organizationId) {
|
|
587
753
|
var url, filter, mediaItem;
|
|
588
|
-
return _regeneratorRuntime.wrap(function
|
|
589
|
-
while (1) switch (
|
|
754
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
755
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
590
756
|
case 0:
|
|
591
757
|
url = new URL("".concat(this.config.url, "/v1/mediaitems"));
|
|
592
758
|
filter = "{url,eq,".concat(imageUrl, "}");
|
|
@@ -595,7 +761,7 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
595
761
|
}
|
|
596
762
|
url.searchParams.append('limit', '1');
|
|
597
763
|
url.searchParams.append('filter', encodeURIComponent("[".concat(filter, "]")));
|
|
598
|
-
|
|
764
|
+
_context8.next = 7;
|
|
599
765
|
return fetch(url.toString(), {
|
|
600
766
|
method: 'GET',
|
|
601
767
|
headers: this.config.jwt ? {
|
|
@@ -605,18 +771,18 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
605
771
|
return r.json();
|
|
606
772
|
});
|
|
607
773
|
case 7:
|
|
608
|
-
|
|
609
|
-
return
|
|
774
|
+
_context8.next = 9;
|
|
775
|
+
return _context8.sent;
|
|
610
776
|
case 9:
|
|
611
|
-
mediaItem =
|
|
612
|
-
|
|
777
|
+
mediaItem = _context8.sent;
|
|
778
|
+
return _context8.abrupt("return", mediaItem === null || mediaItem === void 0 ? void 0 : mediaItem.data[0]);
|
|
613
779
|
case 11:
|
|
614
780
|
case "end":
|
|
615
|
-
return
|
|
781
|
+
return _context8.stop();
|
|
616
782
|
}
|
|
617
|
-
},
|
|
783
|
+
}, _callee8, this);
|
|
618
784
|
}));
|
|
619
|
-
function getMediaItem(
|
|
785
|
+
function getMediaItem(_x8, _x9) {
|
|
620
786
|
return _getMediaItem.apply(this, arguments);
|
|
621
787
|
}
|
|
622
788
|
return getMediaItem;
|
|
@@ -624,10 +790,10 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
624
790
|
}, {
|
|
625
791
|
key: "getMediaItemRef",
|
|
626
792
|
value: function () {
|
|
627
|
-
var _getMediaItemRef = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
793
|
+
var _getMediaItemRef = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(ref, organizationId) {
|
|
628
794
|
var url, filter, mediaItemRef;
|
|
629
|
-
return _regeneratorRuntime.wrap(function
|
|
630
|
-
while (1) switch (
|
|
795
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
796
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
631
797
|
case 0:
|
|
632
798
|
url = new URL("".concat(this.config.url, "/v1/mediaitems/refs"));
|
|
633
799
|
filter = "{_id,eq,".concat(ref, "}");
|
|
@@ -636,7 +802,7 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
636
802
|
}
|
|
637
803
|
url.searchParams.append('limit', '1');
|
|
638
804
|
url.searchParams.append('filter', encodeURIComponent("[".concat(filter, "]")));
|
|
639
|
-
|
|
805
|
+
_context9.next = 7;
|
|
640
806
|
return fetch(url.toString(), {
|
|
641
807
|
method: 'GET',
|
|
642
808
|
headers: this.config.jwt ? {
|
|
@@ -646,35 +812,63 @@ var DivaFile = /*#__PURE__*/function () {
|
|
|
646
812
|
return r.json();
|
|
647
813
|
});
|
|
648
814
|
case 7:
|
|
649
|
-
|
|
650
|
-
return
|
|
815
|
+
_context9.next = 9;
|
|
816
|
+
return _context9.sent;
|
|
651
817
|
case 9:
|
|
652
|
-
mediaItemRef =
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
if (!this._description) this._description = this.itemRef.description;
|
|
656
|
-
if (!this._fileName) this._fileName = this.itemRef.fileName;
|
|
657
|
-
this._mediaType = this.itemRef.mediaType;
|
|
658
|
-
if (!(this._organizationId && this._organizationId != this.itemRef.organizationId)) {
|
|
659
|
-
_context6.next = 17;
|
|
660
|
-
break;
|
|
661
|
-
}
|
|
662
|
-
throw new Error('The existing mediaItemRef belongs to a different organization');
|
|
663
|
-
case 17:
|
|
664
|
-
this._organizationId = this.itemRef.organizationId;
|
|
665
|
-
this._url = this.itemRef.url;
|
|
666
|
-
this._ref = this.itemRef._id;
|
|
667
|
-
case 20:
|
|
818
|
+
mediaItemRef = _context9.sent;
|
|
819
|
+
return _context9.abrupt("return", mediaItemRef === null || mediaItemRef === void 0 ? void 0 : mediaItemRef.data[0]);
|
|
820
|
+
case 11:
|
|
668
821
|
case "end":
|
|
669
|
-
return
|
|
822
|
+
return _context9.stop();
|
|
670
823
|
}
|
|
671
|
-
},
|
|
824
|
+
}, _callee9, this);
|
|
672
825
|
}));
|
|
673
|
-
function getMediaItemRef(
|
|
826
|
+
function getMediaItemRef(_x10, _x11) {
|
|
674
827
|
return _getMediaItemRef.apply(this, arguments);
|
|
675
828
|
}
|
|
676
829
|
return getMediaItemRef;
|
|
677
830
|
}()
|
|
831
|
+
}, {
|
|
832
|
+
key: "getMediaItemRefs",
|
|
833
|
+
value: function () {
|
|
834
|
+
var _getMediaItemRefs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10(refs, organizationId) {
|
|
835
|
+
var url, filter, mediaItemRef;
|
|
836
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
837
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
838
|
+
case 0:
|
|
839
|
+
url = new URL("".concat(this.config.url, "/v1/mediaitems/refs"));
|
|
840
|
+
filter = "{_id,in,".concat(refs.join(','), "}");
|
|
841
|
+
if (organizationId) {
|
|
842
|
+
filter = filter + ",{organizationId,eq,".concat(organizationId, "}");
|
|
843
|
+
}
|
|
844
|
+
url.searchParams.append('limit', refs.length.toString());
|
|
845
|
+
url.searchParams.append('filter', encodeURIComponent("[".concat(filter, "]")));
|
|
846
|
+
_context10.next = 7;
|
|
847
|
+
return fetch(url.toString(), {
|
|
848
|
+
method: 'GET',
|
|
849
|
+
headers: this.config.jwt ? {
|
|
850
|
+
Authorization: "Bearer ".concat(this.config.jwt)
|
|
851
|
+
} : {}
|
|
852
|
+
}).then(function (r) {
|
|
853
|
+
return r.json();
|
|
854
|
+
});
|
|
855
|
+
case 7:
|
|
856
|
+
_context10.next = 9;
|
|
857
|
+
return _context10.sent;
|
|
858
|
+
case 9:
|
|
859
|
+
mediaItemRef = _context10.sent;
|
|
860
|
+
return _context10.abrupt("return", mediaItemRef === null || mediaItemRef === void 0 ? void 0 : mediaItemRef.data);
|
|
861
|
+
case 11:
|
|
862
|
+
case "end":
|
|
863
|
+
return _context10.stop();
|
|
864
|
+
}
|
|
865
|
+
}, _callee10, this);
|
|
866
|
+
}));
|
|
867
|
+
function getMediaItemRefs(_x12, _x13) {
|
|
868
|
+
return _getMediaItemRefs.apply(this, arguments);
|
|
869
|
+
}
|
|
870
|
+
return getMediaItemRefs;
|
|
871
|
+
}()
|
|
678
872
|
}, {
|
|
679
873
|
key: "getMediaTypeFromFile",
|
|
680
874
|
value: function getMediaTypeFromFile(file) {
|
|
@@ -795,9 +989,9 @@ function index (_ref) {
|
|
|
795
989
|
var initState = /*#__PURE__*/function () {
|
|
796
990
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(data) {
|
|
797
991
|
var _newState$0$classes;
|
|
798
|
-
var newState, files, i,
|
|
799
|
-
return _regeneratorRuntime.wrap(function _callee$(
|
|
800
|
-
while (1) switch (
|
|
992
|
+
var newState, files, groupedFiles, _loop, i, _i, group, _yield$group$files$0$, mediaItem, refs, _loop2, j, fileEndingIndex;
|
|
993
|
+
return _regeneratorRuntime.wrap(function _callee$(_context3) {
|
|
994
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
801
995
|
case 0:
|
|
802
996
|
newState = [];
|
|
803
997
|
setLoading(true);
|
|
@@ -806,33 +1000,107 @@ function index (_ref) {
|
|
|
806
1000
|
} else {
|
|
807
1001
|
files = [data];
|
|
808
1002
|
}
|
|
1003
|
+
groupedFiles = [];
|
|
1004
|
+
_loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
|
|
1005
|
+
var file, newFile, _group;
|
|
1006
|
+
return _regeneratorRuntime.wrap(function _loop$(_context2) {
|
|
1007
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1008
|
+
case 0:
|
|
1009
|
+
file = files[i];
|
|
1010
|
+
if (file instanceof DivaFile) {
|
|
1011
|
+
newState.push(file);
|
|
1012
|
+
} else {
|
|
1013
|
+
newFile = new DivaFile(config, file, createRef);
|
|
1014
|
+
_group = groupedFiles.find(function (g) {
|
|
1015
|
+
return g.url === newFile.url && g.files.length <= 250;
|
|
1016
|
+
});
|
|
1017
|
+
if (!_group) {
|
|
1018
|
+
groupedFiles.push({
|
|
1019
|
+
files: [newFile],
|
|
1020
|
+
url: newFile.url
|
|
1021
|
+
});
|
|
1022
|
+
} else {
|
|
1023
|
+
_group.files.push(newFile);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
case 2:
|
|
1027
|
+
case "end":
|
|
1028
|
+
return _context2.stop();
|
|
1029
|
+
}
|
|
1030
|
+
}, _loop);
|
|
1031
|
+
});
|
|
809
1032
|
i = 0;
|
|
810
|
-
case
|
|
1033
|
+
case 6:
|
|
811
1034
|
if (!(i < files.length)) {
|
|
812
|
-
|
|
1035
|
+
_context3.next = 11;
|
|
813
1036
|
break;
|
|
814
1037
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
1038
|
+
return _context3.delegateYield(_loop(), "t0", 8);
|
|
1039
|
+
case 8:
|
|
1040
|
+
i++;
|
|
1041
|
+
_context3.next = 6;
|
|
1042
|
+
break;
|
|
1043
|
+
case 11:
|
|
1044
|
+
_i = 0;
|
|
1045
|
+
case 12:
|
|
1046
|
+
if (!(_i < groupedFiles.length)) {
|
|
1047
|
+
_context3.next = 29;
|
|
818
1048
|
break;
|
|
819
1049
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
return newFile.load({
|
|
1050
|
+
group = groupedFiles[_i];
|
|
1051
|
+
_context3.next = 16;
|
|
1052
|
+
return group.files[0].loadMany({
|
|
1053
|
+
refIds: group.files.map(function (f) {
|
|
1054
|
+
return f.ref;
|
|
1055
|
+
}),
|
|
827
1056
|
organizationId: organizationId
|
|
828
1057
|
});
|
|
829
|
-
case
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1058
|
+
case 16:
|
|
1059
|
+
_yield$group$files$0$ = _context3.sent;
|
|
1060
|
+
mediaItem = _yield$group$files$0$.mediaItem;
|
|
1061
|
+
refs = _yield$group$files$0$.refs;
|
|
1062
|
+
_loop2 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop2() {
|
|
1063
|
+
var ref, file;
|
|
1064
|
+
return _regeneratorRuntime.wrap(function _loop2$(_context) {
|
|
1065
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1066
|
+
case 0:
|
|
1067
|
+
ref = refs[j];
|
|
1068
|
+
file = group.files.find(function (f) {
|
|
1069
|
+
return f.ref === ref._id;
|
|
1070
|
+
});
|
|
1071
|
+
if (file) {
|
|
1072
|
+
_context.next = 4;
|
|
1073
|
+
break;
|
|
1074
|
+
}
|
|
1075
|
+
throw new Error('file with refid ' + ref._id + ' not found');
|
|
1076
|
+
case 4:
|
|
1077
|
+
file.setMediaItemAndRef({
|
|
1078
|
+
item: mediaItem,
|
|
1079
|
+
ref: ref
|
|
1080
|
+
});
|
|
1081
|
+
newState.push(file);
|
|
1082
|
+
case 6:
|
|
1083
|
+
case "end":
|
|
1084
|
+
return _context.stop();
|
|
1085
|
+
}
|
|
1086
|
+
}, _loop2);
|
|
1087
|
+
});
|
|
1088
|
+
j = 0;
|
|
1089
|
+
case 21:
|
|
1090
|
+
if (!(j < refs.length)) {
|
|
1091
|
+
_context3.next = 26;
|
|
1092
|
+
break;
|
|
1093
|
+
}
|
|
1094
|
+
return _context3.delegateYield(_loop2(), "t1", 23);
|
|
1095
|
+
case 23:
|
|
1096
|
+
j++;
|
|
1097
|
+
_context3.next = 21;
|
|
1098
|
+
break;
|
|
1099
|
+
case 26:
|
|
1100
|
+
_i++;
|
|
1101
|
+
_context3.next = 12;
|
|
834
1102
|
break;
|
|
835
|
-
case
|
|
1103
|
+
case 29:
|
|
836
1104
|
setState(newState);
|
|
837
1105
|
if (newState[0].fileName) {
|
|
838
1106
|
fileEndingIndex = newState[0].fileName.lastIndexOf('.');
|
|
@@ -844,9 +1112,9 @@ function index (_ref) {
|
|
|
844
1112
|
setClasses((_newState$0$classes = newState[0].classes) !== null && _newState$0$classes !== void 0 ? _newState$0$classes : []);
|
|
845
1113
|
setType(newState[0].mediaType == 'SPIN' ? 'spin' : 'standard');
|
|
846
1114
|
setLoading(false);
|
|
847
|
-
case
|
|
1115
|
+
case 37:
|
|
848
1116
|
case "end":
|
|
849
|
-
return
|
|
1117
|
+
return _context3.stop();
|
|
850
1118
|
}
|
|
851
1119
|
}, _callee);
|
|
852
1120
|
}));
|