cozy-client 40.5.0 → 40.6.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.
@@ -2695,7 +2695,7 @@ var CozyClient = /*#__PURE__*/function () {
2695
2695
  CozyClient.hooks = CozyClient.hooks || {};
2696
2696
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2697
2697
 
2698
- CozyClient.version = "40.5.0";
2698
+ CozyClient.version = "40.6.0";
2699
2699
 
2700
2700
  _microee.default.mixin(CozyClient);
2701
2701
 
@@ -659,18 +659,26 @@ var overrideFileForPath = /*#__PURE__*/function () {
659
659
  * Method to generate a new filename if there is a conflict
660
660
  *
661
661
  * @param {string} filenameWithoutExtension - A filename without the extension
662
+ * @param {RegExp} [originalNameFormatRegex] - A regex to check if the name is still in his original format
662
663
  * @returns {string} A filename with the right suffix
663
664
  */
664
665
 
665
666
 
666
667
  exports.overrideFileForPath = overrideFileForPath;
667
668
 
668
- var generateNewFileNameOnConflict = function generateNewFileNameOnConflict(filenameWithoutExtension) {
669
- //Check if the string ends by _1
669
+ var generateNewFileNameOnConflict = function generateNewFileNameOnConflict(filenameWithoutExtension, originalNameFormatRegex) {
670
+ var isOriginalNameFormat = false;
671
+
672
+ if (originalNameFormatRegex && originalNameFormatRegex.test(filenameWithoutExtension)) {
673
+ isOriginalNameFormat = true;
674
+ } //Check if the string ends by _1
675
+
676
+
670
677
  var regex = new RegExp('(_)([0-9]+)$');
671
678
  var matches = filenameWithoutExtension.match(regex);
679
+ var shouldIncrement = matches && !isOriginalNameFormat;
672
680
 
673
- if (matches) {
681
+ if (shouldIncrement) {
674
682
  var versionNumber = parseInt(matches[2]); //increment versionNumber
675
683
 
676
684
  versionNumber++;
@@ -571,6 +571,29 @@ describe('File Model', () => {
571
571
  expect(filename3).toEqual('test_1_1_test_1')
572
572
  const filename4 = fileModel.generateNewFileNameOnConflict('test_')
573
573
  expect(filename4).toEqual('test__1')
574
+ const filename5 = fileModel.generateNewFileNameOnConflict('test_1_1')
575
+ expect(filename5).toEqual('test_1_2')
576
+ })
577
+
578
+ it('should generate the right file name with _X when passing a format', () => {
579
+ const regex = new RegExp('^([a-z]+)(_)([0-9]+)$') // test_1
580
+
581
+ const filename1 = fileModel.generateNewFileNameOnConflict('test', regex)
582
+ expect(filename1).toEqual('test_1')
583
+ const filename2 = fileModel.generateNewFileNameOnConflict('test_1', regex)
584
+ expect(filename2).toEqual('test_1_1')
585
+ const filename3 = fileModel.generateNewFileNameOnConflict(
586
+ 'test_1_1_test',
587
+ regex
588
+ )
589
+ expect(filename3).toEqual('test_1_1_test_1')
590
+ const filename4 = fileModel.generateNewFileNameOnConflict('test_', regex)
591
+ expect(filename4).toEqual('test__1')
592
+ const filename5 = fileModel.generateNewFileNameOnConflict(
593
+ 'test_1_1',
594
+ regex
595
+ )
596
+ expect(filename5).toEqual('test_1_2')
574
597
  })
575
598
  })
576
599
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "40.5.0",
3
+ "version": "40.6.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -73,5 +73,5 @@
73
73
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
74
74
  },
75
75
  "sideEffects": false,
76
- "gitHead": "c05e32361f5bb6f3303d591a454b47a03bbb8217"
76
+ "gitHead": "b63d9b7ca8b6216ab035fa58a92ba909c22837cf"
77
77
  }
@@ -52,7 +52,7 @@ export function move(client: CozyClient, fileId: string, destination: {
52
52
  path: string;
53
53
  }, force?: boolean): Promise<any>;
54
54
  export function overrideFileForPath(client: CozyClient, dirPath: string, file: object, metadata: object): Promise<import("../types").IOCozyFile>;
55
- export function generateNewFileNameOnConflict(filenameWithoutExtension: string): string;
55
+ export function generateNewFileNameOnConflict(filenameWithoutExtension: string, originalNameFormatRegex?: RegExp): string;
56
56
  export function generateFileNameForRevision(file: import("../types").IOCozyFile, revision: object, f: Function): string;
57
57
  export function uploadFileWithConflictStrategy(client: CozyClient, file: string | ArrayBuffer, options: FileUploadOptions): any;
58
58
  export function readMobileFile(fileURL: string): Promise<any>;