cozy-client 60.26.0 → 60.27.0

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.
@@ -3126,7 +3126,7 @@ var CozyClient = /*#__PURE__*/function () {
3126
3126
  CozyClient.hooks = CozyClient.hooks || {};
3127
3127
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
3128
3128
 
3129
- CozyClient.version = "60.26.0";
3129
+ CozyClient.version = "60.27.0";
3130
3130
 
3131
3131
  _microee.default.mixin(CozyClient);
3132
3132
 
@@ -902,14 +902,24 @@ var overrideFileForPath = /*#__PURE__*/function () {
902
902
  exports.overrideFileForPath = overrideFileForPath;
903
903
 
904
904
  var generateNewFileNameOnConflict = function generateNewFileNameOnConflict(filenameWithoutExtension, conflictOptions) {
905
- var delimiter = (conflictOptions === null || conflictOptions === void 0 ? void 0 : conflictOptions.delimiter) || '_'; //Check if the string ends by _1
905
+ var delimiter = conflictOptions === null || conflictOptions === void 0 ? void 0 : conflictOptions.delimiter;
906
+
907
+ if (!delimiter) {
908
+ var _matches = filenameWithoutExtension.match(/^(.*) \(([0-9]+)\)$/);
909
+
910
+ if (_matches) {
911
+ return "".concat(_matches[1], " (").concat(parseInt(_matches[2], 10) + 1, ")");
912
+ }
913
+
914
+ return "".concat(filenameWithoutExtension, " (1)");
915
+ } // Keep explicit delimiter support for callers that opted into the legacy format.
916
+
906
917
 
907
918
  var regex = new RegExp("(".concat(delimiter, ")([0-9]+)$"));
908
919
  var matches = filenameWithoutExtension.match(regex);
909
920
 
910
921
  if (matches) {
911
- var versionNumber = parseInt(matches[2]); //increment versionNumber
912
-
922
+ var versionNumber = parseInt(matches[2], 10);
913
923
  versionNumber++;
914
924
  var newFilenameWithoutExtension = filenameWithoutExtension.replace(new RegExp("(".concat(delimiter, ")([0-9]+)$")), "".concat(delimiter).concat(versionNumber));
915
925
  return newFilenameWithoutExtension;
@@ -592,19 +592,59 @@ describe('File Model', () => {
592
592
  })
593
593
 
594
594
  describe('generateNewFileNameOnConflict', () => {
595
- it('should generate the right file name with _X', () => {
595
+ it('should generate the default file name with parenthesized copy counters', () => {
596
596
  const filename1 = fileModel.generateNewFileNameOnConflict('test')
597
+ expect(filename1).toEqual('test (1)')
598
+ const filename2 = fileModel.generateNewFileNameOnConflict('test (1)')
599
+ expect(filename2).toEqual('test (2)')
600
+ const filename3 = fileModel.generateNewFileNameOnConflict('test_1_1_test')
601
+ expect(filename3).toEqual('test_1_1_test (1)')
602
+ const filename4 = fileModel.generateNewFileNameOnConflict(
603
+ 'test_1_1_test (1)'
604
+ )
605
+ expect(filename4).toEqual('test_1_1_test (2)')
606
+ const filename5 = fileModel.generateNewFileNameOnConflict('test_')
607
+ expect(filename5).toEqual('test_ (1)')
608
+ })
609
+
610
+ it('should not increment numbers that are part of the file name', () => {
611
+ const filename1 = fileModel.generateNewFileNameOnConflict('IMG_4521')
612
+ expect(filename1).toEqual('IMG_4521 (1)')
613
+ const filename2 = fileModel.generateNewFileNameOnConflict('DSC_0001')
614
+ expect(filename2).toEqual('DSC_0001 (1)')
615
+ const filename3 = fileModel.generateNewFileNameOnConflict('report_2024')
616
+ expect(filename3).toEqual('report_2024 (1)')
617
+ const filename4 = fileModel.generateNewFileNameOnConflict(
618
+ 'report (draft)'
619
+ )
620
+ expect(filename4).toEqual('report (draft) (1)')
621
+ })
622
+
623
+ it('should keep the legacy delimiter behavior when delimiter is passed', () => {
624
+ const conflictOptions = {
625
+ delimiter: '_'
626
+ }
627
+
628
+ const filename1 = fileModel.generateNewFileNameOnConflict(
629
+ 'test',
630
+ conflictOptions
631
+ )
597
632
  expect(filename1).toEqual('test_1')
598
- const filename2 = fileModel.generateNewFileNameOnConflict('test_1')
633
+ const filename2 = fileModel.generateNewFileNameOnConflict(
634
+ 'test_1',
635
+ conflictOptions
636
+ )
599
637
  expect(filename2).toEqual('test_2')
600
- const filename3 = fileModel.generateNewFileNameOnConflict('test_1_1_test')
638
+ const filename3 = fileModel.generateNewFileNameOnConflict(
639
+ 'test_1_1_test',
640
+ conflictOptions
641
+ )
601
642
  expect(filename3).toEqual('test_1_1_test_1')
602
643
  const filename4 = fileModel.generateNewFileNameOnConflict(
603
- 'test_1_1_test_1'
644
+ 'test_',
645
+ conflictOptions
604
646
  )
605
- expect(filename4).toEqual('test_1_1_test_2')
606
- const filename5 = fileModel.generateNewFileNameOnConflict('test_')
607
- expect(filename5).toEqual('test__1')
647
+ expect(filename4).toEqual('test__1')
608
648
  })
609
649
 
610
650
  it('should generate the right file name with _cozyX', () => {
@@ -713,7 +753,33 @@ describe('File Model', () => {
713
753
  await fileModel.uploadFileWithConflictStrategy(cozyClient, '', opts)
714
754
  expect(createFileSpy).toHaveBeenCalledWith('', {
715
755
  ...opts,
716
- name: 'filename_1'
756
+ name: 'filename (1)'
757
+ })
758
+ })
759
+
760
+ it('should keep real filename numbers when renaming a file with an extension', async () => {
761
+ const dirId = 'toto'
762
+ //first call we return an existing file => conflict
763
+ //second call, we reject as not found
764
+ statByPathSpy
765
+ .mockReturnValueOnce({
766
+ data: {
767
+ _id: 'file_id',
768
+ _type: 'io.cozy.files'
769
+ }
770
+ })
771
+ .mockRejectedValueOnce(new Error('Not Found'))
772
+
773
+ const opts = {
774
+ name: 'IMG_4521.jpg',
775
+ dirId,
776
+ conflictStrategy: 'rename',
777
+ contentType: 'image/jpeg'
778
+ }
779
+ await fileModel.uploadFileWithConflictStrategy(cozyClient, '', opts)
780
+ expect(createFileSpy).toHaveBeenCalledWith('', {
781
+ ...opts,
782
+ name: 'IMG_4521 (1).jpg'
717
783
  })
718
784
  })
719
785
 
package/dist/types.js CHANGED
@@ -957,7 +957,7 @@ var _dsl = require("./queries/dsl");
957
957
  * Represents available options of generateNewFileNameOnConflict method
958
958
  *
959
959
  * @typedef {object} ConflictOptions
960
- * @property {string} [delimiter] - Delimiter before the incremented number. Default to '_'
960
+ * @property {string} [delimiter] - Custom delimiter before the incremented number. Defaults to parenthesized copy counters.
961
961
  */
962
962
 
963
963
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "60.26.0",
3
+ "version": "60.27.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -19,7 +19,7 @@
19
19
  "@types/jest": "^26.0.20",
20
20
  "@types/lodash": "^4.14.170",
21
21
  "btoa": "^1.2.1",
22
- "cozy-stack-client": "^60.24.0",
22
+ "cozy-stack-client": "^60.27.0",
23
23
  "date-fns": "^2.30.0",
24
24
  "fast-deep-equal": "^3.1.3",
25
25
  "json-stable-stringify": "^1.0.1",
@@ -74,5 +74,5 @@
74
74
  "react-native-ios11-devicecheck": "^0.0.3"
75
75
  },
76
76
  "sideEffects": false,
77
- "gitHead": "364d348ff17d2e0683b7bfec9f03ab5a680f9c29"
77
+ "gitHead": "d25894f5658bdea0d20bfd491cc86d18f8559679"
78
78
  }
package/types/types.d.ts CHANGED
@@ -1702,7 +1702,7 @@ export type RedirectLinkData = {
1702
1702
  */
1703
1703
  export type ConflictOptions = {
1704
1704
  /**
1705
- * - Delimiter before the incremented number. Default to '_'
1705
+ * - Custom delimiter before the incremented number. Defaults to parenthesized copy counters.
1706
1706
  */
1707
1707
  delimiter?: string;
1708
1708
  };