cozy-client 25.0.2 → 26.0.1

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.
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.normalize = normalize;
9
9
  exports.ensureFilePath = ensureFilePath;
10
10
  exports.getParentFolderId = getParentFolderId;
11
- exports.hasMetadataAttribute = exports.isReferencedByAlbum = exports.fetchFilesByQualificationRules = exports.saveFileQualification = exports.isSharingShorcutNew = exports.isSharingShortcutNew = exports.isSharingShorcut = exports.isSharingShortcut = exports.getSharingShortcutTargetDoctype = exports.getSharingShortcutTargetMime = exports.getSharingShortcutStatus = exports.isShortcut = exports.shouldBeOpenedByOnlyOffice = exports.isOnlyOfficeFile = exports.isNote = exports.isDirectory = exports.isFile = exports.splitFilename = exports.ALBUMS_DOCTYPE = void 0;
11
+ exports.doMobileUpload = exports.readMobileFile = exports.uploadFileWithConflictStrategy = exports.generateFileNameForRevision = exports.generateNewFileNameOnConflict = exports.overrideFileForPath = exports.move = exports.getFullpath = exports.hasMetadataAttribute = exports.isReferencedByAlbum = exports.fetchFilesByQualificationRules = exports.saveFileQualification = exports.isSharingShorcutNew = exports.isSharingShortcutNew = exports.isSharingShorcut = exports.isSharingShortcut = exports.getSharingShortcutTargetDoctype = exports.getSharingShortcutTargetMime = exports.getSharingShortcutStatus = exports.isShortcut = exports.shouldBeOpenedByOnlyOffice = exports.isOnlyOfficeFile = exports.isNote = exports.isDirectory = exports.isFile = exports.splitFilename = exports.ALBUMS_DOCTYPE = void 0;
12
12
 
13
13
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
14
 
@@ -22,6 +22,8 @@ var _isString = _interopRequireDefault(require("lodash/isString"));
22
22
 
23
23
  var _has = _interopRequireDefault(require("lodash/has"));
24
24
 
25
+ var _trimEnd = _interopRequireDefault(require("lodash/trimEnd"));
26
+
25
27
  var _document = require("./document");
26
28
 
27
29
  var _dsl = require("../queries/dsl");
@@ -137,7 +139,7 @@ var shouldBeOpenedByOnlyOffice = function shouldBeOpenedByOnlyOffice(file) {
137
139
  };
138
140
  /**
139
141
  *
140
- * @param {IOCozyFile} file io.cozy.files
142
+ * @param {IOCozyFile} file - io.cozy.files document
141
143
  * @returns {boolean} true if the file is a shortcut
142
144
  */
143
145
 
@@ -202,7 +204,7 @@ function getParentFolderId(file) {
202
204
  /**
203
205
  * Returns the status of a sharing shortcut.
204
206
  *
205
- * @param {IOCozyFile} file - io.cozy.files document
207
+ * @param {IOCozyFile} file - io.cozy.files document
206
208
  *
207
209
  * @returns {string} A description of the status
208
210
  */
@@ -228,7 +230,7 @@ var getSharingShortcutTargetMime = function getSharingShortcutTargetMime(file) {
228
230
  /**
229
231
  * Returns the doctype of the target of the sharing shortcut.
230
232
  *
231
- * @param {IOCozyFile} file - io.cozy.files document
233
+ * @param {IOCozyFile} file - io.cozy.files document
232
234
  *
233
235
  * @returns {string} A doctype
234
236
  */
@@ -242,7 +244,7 @@ var getSharingShortcutTargetDoctype = function getSharingShortcutTargetDoctype(f
242
244
  /**
243
245
  * Returns whether the file is a shortcut to a sharing
244
246
  *
245
- * @param {IOCozyFile} file - io.cozy.files document
247
+ * @param {IOCozyFile} file - io.cozy.files document
246
248
  *
247
249
  * @returns {boolean}
248
250
  */
@@ -257,7 +259,7 @@ var isSharingShortcut = function isSharingShortcut(file) {
257
259
  * Returns whether the file is a shortcut to a sharing
258
260
  *
259
261
  * @deprecated Prefer to use isSharingShortcut.
260
- * @param {IOCozyFile} file - io.cozy.files document
262
+ * @param {IOCozyFile} file - io.cozy.files document
261
263
  *
262
264
  * @returns {boolean}
263
265
  */
@@ -272,7 +274,7 @@ var isSharingShorcut = function isSharingShorcut(file) {
272
274
  /**
273
275
  * Returns whether the sharing shortcut is new
274
276
  *
275
- * @param {IOCozyFile} file - io.cozy.files document
277
+ * @param {IOCozyFile} file - io.cozy.files document
276
278
  *
277
279
  * @returns {boolean}
278
280
  */
@@ -287,7 +289,7 @@ var isSharingShortcutNew = function isSharingShortcutNew(file) {
287
289
  * Returns whether the sharing shortcut is new
288
290
  *
289
291
  * @deprecated Prefer to use isSharingShortcutNew.
290
- * @param {object} file - io.cozy.files document
292
+ * @param {object} file - io.cozy.files document
291
293
  *
292
294
  * @returns {boolean}
293
295
  */
@@ -305,7 +307,7 @@ var isSharingShorcutNew = function isSharingShorcutNew(file) {
305
307
  * @param {CozyClient} client - The CozyClient instance
306
308
  * @param {IOCozyFile} file - The file to qualify
307
309
  * @param {object} qualification - The file qualification
308
- * @returns {Promise<IOCozyFile>} - The saved file
310
+ * @returns {Promise<IOCozyFile>} The saved file
309
311
  */
310
312
 
311
313
 
@@ -338,7 +340,7 @@ var saveFileQualification = /*#__PURE__*/function () {
338
340
  *
339
341
  * @param {object} client - The CozyClient instance
340
342
  * @param {object} docRules - the rules containing the searched qualification and the count
341
- * @returns {Promise<QueryResult>} - The files found by the rules
343
+ * @returns {Promise<QueryResult>} The files found by the rules
342
344
  */
343
345
 
344
346
 
@@ -427,5 +429,553 @@ var hasMetadataAttribute = function hasMetadataAttribute(_ref3) {
427
429
  attribute = _ref3.attribute;
428
430
  return (0, _has.default)(file, "metadata.".concat(attribute));
429
431
  };
432
+ /**
433
+ * async getFullpath - Gets a file's path
434
+ *
435
+ * @param {CozyClient} client - The CozyClient instance
436
+ * @param {string} dirId - The id of the parent directory
437
+ * @param {string} name - The file's name
438
+ * @returns {Promise<string>} The full path of the file in the cozy
439
+ **/
440
+
441
+
442
+ exports.hasMetadataAttribute = hasMetadataAttribute;
443
+
444
+ var getFullpath = /*#__PURE__*/function () {
445
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(client, dirId, name) {
446
+ var _yield$client$query, parentDir, parentDirectoryPath;
447
+
448
+ return _regenerator.default.wrap(function _callee3$(_context3) {
449
+ while (1) {
450
+ switch (_context3.prev = _context3.next) {
451
+ case 0:
452
+ if (dirId) {
453
+ _context3.next = 2;
454
+ break;
455
+ }
456
+
457
+ throw new Error('You must provide a dirId');
458
+
459
+ case 2:
460
+ _context3.next = 4;
461
+ return client.query((0, _dsl.Q)(_const.DOCTYPE_FILES).getById(dirId));
462
+
463
+ case 4:
464
+ _yield$client$query = _context3.sent;
465
+ parentDir = _yield$client$query.data;
466
+ parentDirectoryPath = (0, _trimEnd.default)(parentDir.path, '/');
467
+ return _context3.abrupt("return", "".concat(parentDirectoryPath, "/").concat(name));
468
+
469
+ case 8:
470
+ case "end":
471
+ return _context3.stop();
472
+ }
473
+ }
474
+ }, _callee3);
475
+ }));
476
+
477
+ return function getFullpath(_x6, _x7, _x8) {
478
+ return _ref4.apply(this, arguments);
479
+ };
480
+ }();
481
+ /**
482
+ * Move file to destination.
483
+ *
484
+ * @param {CozyClient} client - The CozyClient instance
485
+ * @param {string} fileId - The file's id (required)
486
+ * @param {object} destination
487
+ * @param {string} destination.folderId - The destination folder's id (required)
488
+ * @param {string} destination.path - The file's path after the move (optional, used to optimize performance in case of conflict)
489
+ * @param {boolean} force - Whether we should overwrite, i.e. put to trash, the destination in case of conflict (defaults to false).
490
+ * @returns {Promise} - A promise that returns the move action response and the deleted file id (if any) if resolved or an Error if rejected
491
+ *
492
+ */
493
+
494
+
495
+ exports.getFullpath = getFullpath;
496
+
497
+ var move = /*#__PURE__*/function () {
498
+ var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(client, fileId, destination) {
499
+ var force,
500
+ folderId,
501
+ path,
502
+ resp,
503
+ destinationPath,
504
+ _yield$client$query2,
505
+ movedFile,
506
+ filename,
507
+ conflictResp,
508
+ _resp,
509
+ _args4 = arguments;
510
+
511
+ return _regenerator.default.wrap(function _callee4$(_context4) {
512
+ while (1) {
513
+ switch (_context4.prev = _context4.next) {
514
+ case 0:
515
+ force = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : false;
516
+ folderId = destination.folderId, path = destination.path;
517
+ _context4.prev = 2;
518
+ _context4.next = 5;
519
+ return client.collection(_const.DOCTYPE_FILES).updateFileMetadata(fileId, {
520
+ dir_id: folderId
521
+ });
522
+
523
+ case 5:
524
+ resp = _context4.sent;
525
+ return _context4.abrupt("return", {
526
+ moved: resp.data,
527
+ deleted: null
528
+ });
529
+
530
+ case 9:
531
+ _context4.prev = 9;
532
+ _context4.t0 = _context4["catch"](2);
533
+
534
+ if (!(_context4.t0.status === 409 && force)) {
535
+ _context4.next = 35;
536
+ break;
537
+ }
538
+
539
+ if (!path) {
540
+ _context4.next = 16;
541
+ break;
542
+ }
543
+
544
+ destinationPath = path;
545
+ _context4.next = 24;
546
+ break;
547
+
548
+ case 16:
549
+ _context4.next = 18;
550
+ return client.query((0, _dsl.Q)(_const.DOCTYPE_FILES).getById(fileId));
551
+
552
+ case 18:
553
+ _yield$client$query2 = _context4.sent;
554
+ movedFile = _yield$client$query2.data;
555
+ filename = movedFile.name;
556
+ _context4.next = 23;
557
+ return getFullpath(client, folderId, filename);
558
+
559
+ case 23:
560
+ destinationPath = _context4.sent;
561
+
562
+ case 24:
563
+ _context4.next = 26;
564
+ return client.collection(_const.DOCTYPE_FILES).statByPath(destinationPath);
565
+
566
+ case 26:
567
+ conflictResp = _context4.sent;
568
+ _context4.next = 29;
569
+ return client.collection(_const.DOCTYPE_FILES).destroy(conflictResp.data);
570
+
571
+ case 29:
572
+ _context4.next = 31;
573
+ return client.collection(_const.DOCTYPE_FILES).updateFileMetadata(fileId, {
574
+ dir_id: folderId
575
+ });
576
+
577
+ case 31:
578
+ _resp = _context4.sent;
579
+ return _context4.abrupt("return", {
580
+ moved: _resp.data,
581
+ deleted: conflictResp.data.id
582
+ });
583
+
584
+ case 35:
585
+ throw _context4.t0;
586
+
587
+ case 36:
588
+ case "end":
589
+ return _context4.stop();
590
+ }
591
+ }
592
+ }, _callee4, null, [[2, 9]]);
593
+ }));
594
+
595
+ return function move(_x9, _x10, _x11) {
596
+ return _ref5.apply(this, arguments);
597
+ };
598
+ }();
599
+ /**
600
+ *
601
+ * Method to upload a file even if a file with the same name already exists.
602
+ *
603
+ * @param {CozyClient} client - The CozyClient instance
604
+ * @param {string} dirPath - Fullpath of directory to upload to ex: path/to/
605
+ * @param {object} file - HTML Object file
606
+ * @param {object} metadata - An object containing the wanted metadata to attach
607
+ * @returns {Promise<IOCozyFile>} The overrided file
608
+ */
609
+
610
+
611
+ exports.move = move;
612
+
613
+ var overrideFileForPath = /*#__PURE__*/function () {
614
+ var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(client, dirPath, file, metadata) {
615
+ var path, filesCollection, existingFile, _existingFile$data, fileId, dirId, resp, _dirId, createdFile;
616
+
617
+ return _regenerator.default.wrap(function _callee5$(_context5) {
618
+ while (1) {
619
+ switch (_context5.prev = _context5.next) {
620
+ case 0:
621
+ path = dirPath;
622
+ if (!path.endsWith('/')) path = path + '/';
623
+ filesCollection = client.collection(_const.DOCTYPE_FILES);
624
+ _context5.prev = 3;
625
+ _context5.next = 6;
626
+ return filesCollection.statByPath(path + file.name);
627
+
628
+ case 6:
629
+ existingFile = _context5.sent;
630
+ _existingFile$data = existingFile.data, fileId = _existingFile$data.id, dirId = _existingFile$data.dir_id;
631
+ _context5.next = 10;
632
+ return filesCollection.updateFile(file, {
633
+ dirId: dirId,
634
+ fileId: fileId,
635
+ metadata: metadata
636
+ });
637
+
638
+ case 10:
639
+ resp = _context5.sent;
640
+ return _context5.abrupt("return", resp);
641
+
642
+ case 14:
643
+ _context5.prev = 14;
644
+ _context5.t0 = _context5["catch"](3);
645
+
646
+ if (!/Not Found/.test(_context5.t0)) {
647
+ _context5.next = 24;
648
+ break;
649
+ }
650
+
651
+ _context5.next = 19;
652
+ return filesCollection.ensureDirectoryExists(path);
653
+
654
+ case 19:
655
+ _dirId = _context5.sent;
656
+ _context5.next = 22;
657
+ return filesCollection.createFile(file, {
658
+ dirId: _dirId,
659
+ metadata: metadata
660
+ });
661
+
662
+ case 22:
663
+ createdFile = _context5.sent;
664
+ return _context5.abrupt("return", createdFile);
665
+
666
+ case 24:
667
+ throw _context5.t0;
668
+
669
+ case 25:
670
+ case "end":
671
+ return _context5.stop();
672
+ }
673
+ }
674
+ }, _callee5, null, [[3, 14]]);
675
+ }));
676
+
677
+ return function overrideFileForPath(_x12, _x13, _x14, _x15) {
678
+ return _ref6.apply(this, arguments);
679
+ };
680
+ }();
681
+ /**
682
+ * Method to generate a new filename if there is a conflict
683
+ *
684
+ * @param {string} filenameWithoutExtension - A filename without the extension
685
+ * @returns {string} A filename with the right suffix
686
+ */
687
+
688
+
689
+ exports.overrideFileForPath = overrideFileForPath;
690
+
691
+ var generateNewFileNameOnConflict = function generateNewFileNameOnConflict(filenameWithoutExtension) {
692
+ //Check if the string ends by _1
693
+ var regex = new RegExp('(?<=_)([0-9]+)$'); // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Assertions#other_assertions
694
+
695
+ var matches = filenameWithoutExtension.match(regex);
696
+
697
+ if (matches) {
698
+ var versionNumber = parseInt(matches[1]); //increment versionNumber
699
+
700
+ versionNumber++;
701
+ var newFilenameWithoutExtension = filenameWithoutExtension.replace(regex, "".concat(versionNumber));
702
+ return newFilenameWithoutExtension;
703
+ } else {
704
+ return "".concat(filenameWithoutExtension, "_1");
705
+ }
706
+ };
707
+ /**
708
+ * Generate a file name for a revision
709
+ *
710
+ * @param {IOCozyFile} file - io.cozy.files document
711
+ * @param {object} revision - The revision containing the updated_at
712
+ * @param {function} f - A function taking a a date and a format as arguments to generate the name.
713
+ */
714
+
715
+
716
+ exports.generateNewFileNameOnConflict = generateNewFileNameOnConflict;
717
+
718
+ var generateFileNameForRevision = function generateFileNameForRevision(file, revision, f) {
719
+ var _splitFilename = splitFilename(file),
720
+ filename = _splitFilename.filename,
721
+ extension = _splitFilename.extension;
722
+
723
+ return "".concat(filename, "_").concat(f(revision.updated_at, 'DD MMMM - HH[h]mm')).concat(extension);
724
+ };
725
+ /**
726
+ * @typedef FileUploadOptions
727
+ * @property {string} [name] - The file name to upload
728
+ * @property {string} [dirId] - The dirId to upload the file to
729
+ * @property {object} [metadata] - An object containing the metadata to attach
730
+ * @property {string} [contentType] - The file Content-Type
731
+ * @property {string} [conflictStrategy] - Erase / rename
732
+ */
733
+
734
+ /**
735
+ * The goal of this method is to upload a file based on a conflict strategy.
736
+ * Be careful: We need to check if the file exists by doing a statByPath query
737
+ * before trying to upload the file since if we post and the stack return a
738
+ * 409 conflict, we will get a SPDY_ERROR_PROTOCOL on Chrome. This is the only
739
+ * viable workaround
740
+ * If there is no conflict, then we upload the file.
741
+ * If there is a conflict, then we apply the conflict strategy : `erase` or `rename`:
742
+ * - The `erase` strategy means an upload with a new version
743
+ * - The `rename` strategy means a new upload with a new name
744
+ *
745
+ * @param {CozyClient} client - The CozyClient instance
746
+ * @param {string|ArrayBuffer} file - Can be the file path (file://) or the binary itself
747
+ * @param {FileUploadOptions} options - The upload options
748
+ */
749
+
750
+
751
+ exports.generateFileNameForRevision = generateFileNameForRevision;
752
+
753
+ var uploadFileWithConflictStrategy = /*#__PURE__*/function () {
754
+ var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(client, file, options) {
755
+ var name, dirId, conflictStrategy, path, existingFile, fileId, resp, _splitFilename2, filename, extension, newFileName;
756
+
757
+ return _regenerator.default.wrap(function _callee6$(_context6) {
758
+ while (1) {
759
+ switch (_context6.prev = _context6.next) {
760
+ case 0:
761
+ name = options.name, dirId = options.dirId, conflictStrategy = options.conflictStrategy;
762
+ _context6.prev = 1;
763
+ _context6.next = 4;
764
+ return getFullpath(client, dirId, name);
765
+
766
+ case 4:
767
+ path = _context6.sent;
768
+ _context6.next = 7;
769
+ return client.collection(_const.DOCTYPE_FILES).statByPath(path);
770
+
771
+ case 7:
772
+ existingFile = _context6.sent;
773
+ fileId = existingFile.data.id;
774
+
775
+ if (!(conflictStrategy === 'erase')) {
776
+ _context6.next = 16;
777
+ break;
778
+ }
779
+
780
+ _context6.next = 12;
781
+ return client.collection(_const.DOCTYPE_FILES).updateFile(file, _objectSpread(_objectSpread({}, options), {}, {
782
+ fileId: fileId
783
+ }));
784
+
785
+ case 12:
786
+ resp = _context6.sent;
787
+ return _context6.abrupt("return", resp);
788
+
789
+ case 16:
790
+ // @ts-ignore
791
+ _splitFilename2 = splitFilename({
792
+ name: name,
793
+ type: 'file'
794
+ }), filename = _splitFilename2.filename, extension = _splitFilename2.extension;
795
+ newFileName = generateNewFileNameOnConflict(filename) + extension; //recall itself with the newFilename.
796
+
797
+ return _context6.abrupt("return", uploadFileWithConflictStrategy(client, file, _objectSpread(_objectSpread({}, options), {}, {
798
+ name: newFileName
799
+ })));
800
+
801
+ case 19:
802
+ _context6.next = 26;
803
+ break;
804
+
805
+ case 21:
806
+ _context6.prev = 21;
807
+ _context6.t0 = _context6["catch"](1);
808
+
809
+ if (!/Not Found/.test(_context6.t0.message)) {
810
+ _context6.next = 25;
811
+ break;
812
+ }
813
+
814
+ return _context6.abrupt("return", client.collection(_const.DOCTYPE_FILES).createFile(file, options));
815
+
816
+ case 25:
817
+ throw _context6.t0;
818
+
819
+ case 26:
820
+ case "end":
821
+ return _context6.stop();
822
+ }
823
+ }
824
+ }, _callee6, null, [[1, 21]]);
825
+ }));
826
+
827
+ return function uploadFileWithConflictStrategy(_x16, _x17, _x18) {
828
+ return _ref7.apply(this, arguments);
829
+ };
830
+ }();
831
+ /**
832
+ * Read a file on a mobile
833
+ *
834
+ * @param {string} fileURL - The local file path (file://)
835
+ */
836
+
837
+
838
+ exports.uploadFileWithConflictStrategy = uploadFileWithConflictStrategy;
839
+
840
+ var readMobileFile = /*#__PURE__*/function () {
841
+ var _ref8 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(fileURL) {
842
+ var p;
843
+ return _regenerator.default.wrap(function _callee10$(_context10) {
844
+ while (1) {
845
+ switch (_context10.prev = _context10.next) {
846
+ case 0:
847
+ /** Cordova plugin doesn't support promise since they are supporting Android 4.X.X
848
+ * so we have to create manually a promise to be able to write beautiful code ;)
849
+ */
850
+ p = new Promise(function (resolve, reject) {
851
+ var onResolvedLocalFS = /*#__PURE__*/function () {
852
+ var _ref9 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(fileEntry) {
853
+ return _regenerator.default.wrap(function _callee9$(_context9) {
854
+ while (1) {
855
+ switch (_context9.prev = _context9.next) {
856
+ case 0:
857
+ fileEntry.file( /*#__PURE__*/function () {
858
+ var _ref10 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(file) {
859
+ var reader;
860
+ return _regenerator.default.wrap(function _callee8$(_context8) {
861
+ while (1) {
862
+ switch (_context8.prev = _context8.next) {
863
+ case 0:
864
+ reader = new FileReader();
865
+ reader.onloadend = /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7() {
866
+ return _regenerator.default.wrap(function _callee7$(_context7) {
867
+ while (1) {
868
+ switch (_context7.prev = _context7.next) {
869
+ case 0:
870
+ resolve(reader.result);
871
+
872
+ case 1:
873
+ case "end":
874
+ return _context7.stop();
875
+ }
876
+ }
877
+ }, _callee7);
878
+ })); // Read the file as an ArrayBuffer
879
+
880
+ reader.readAsArrayBuffer(file);
881
+
882
+ case 3:
883
+ case "end":
884
+ return _context8.stop();
885
+ }
886
+ }
887
+ }, _callee8);
888
+ }));
889
+
890
+ return function (_x21) {
891
+ return _ref10.apply(this, arguments);
892
+ };
893
+ }(), function (err) {
894
+ // Since this module is pretty recent, let's have this info in sentry if needed
895
+ console.error('error getting fileentry file!' + err); // eslint-disable-line no-console
896
+
897
+ reject(err);
898
+ });
899
+
900
+ case 1:
901
+ case "end":
902
+ return _context9.stop();
903
+ }
904
+ }
905
+ }, _callee9);
906
+ }));
907
+
908
+ return function onResolvedLocalFS(_x20) {
909
+ return _ref9.apply(this, arguments);
910
+ };
911
+ }();
912
+
913
+ var onError = function onError(error) {
914
+ reject(error);
915
+ };
916
+ /**
917
+ * file:/// can not be converted to a fileEntry without the Cordova's File plugin.
918
+ * `resolveLocalFileSystemURL` is provided by this plugin and can resolve the native
919
+ * path to a fileEntry readable by a `FileReader`
920
+ *
921
+ * When we finished to read the fileEntry as buffer, we start the upload process
922
+ *
923
+ */
924
+ // @ts-ignore
925
+
926
+
927
+ window.resolveLocalFileSystemURL(fileURL, onResolvedLocalFS, onError);
928
+ });
929
+ return _context10.abrupt("return", p);
930
+
931
+ case 2:
932
+ case "end":
933
+ return _context10.stop();
934
+ }
935
+ }
936
+ }, _callee10);
937
+ }));
938
+
939
+ return function readMobileFile(_x19) {
940
+ return _ref8.apply(this, arguments);
941
+ };
942
+ }();
943
+ /**
944
+ * Upload a file on a mobile
945
+ *
946
+ * @param {CozyClient} client - The CozyClient instance
947
+ * @param {string} fileURL - The local file path (file://)
948
+ * @param {FileUploadOptions} options - The upload options
949
+ */
950
+
951
+
952
+ exports.readMobileFile = readMobileFile;
953
+
954
+ var doMobileUpload = /*#__PURE__*/function () {
955
+ var _ref12 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(client, fileURL, options) {
956
+ var file;
957
+ return _regenerator.default.wrap(function _callee11$(_context11) {
958
+ while (1) {
959
+ switch (_context11.prev = _context11.next) {
960
+ case 0:
961
+ _context11.next = 2;
962
+ return readMobileFile(fileURL);
963
+
964
+ case 2:
965
+ file = _context11.sent;
966
+ return _context11.abrupt("return", uploadFileWithConflictStrategy(client, file, options));
967
+
968
+ case 4:
969
+ case "end":
970
+ return _context11.stop();
971
+ }
972
+ }
973
+ }, _callee11);
974
+ }));
975
+
976
+ return function doMobileUpload(_x22, _x23, _x24) {
977
+ return _ref12.apply(this, arguments);
978
+ };
979
+ }();
430
980
 
431
- exports.hasMetadataAttribute = hasMetadataAttribute;
981
+ exports.doMobileUpload = doMobileUpload;