cozy-client 27.12.0 → 27.13.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.
- package/CHANGELOG.md +11 -0
- package/dist/CozyClient.js +1 -1
- package/dist/models/file.js +43 -2
- package/dist/models/file.spec.js +18 -1
- package/package.json +2 -2
- package/types/models/file.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [27.13.0](https://github.com/cozy/cozy-client/compare/v27.12.0...v27.13.0) (2022-01-24)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add fetchBlobFileById function ([eb37b1a](https://github.com/cozy/cozy-client/commit/eb37b1af091d3e95372a0540ad0f14ba59e74a4c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [27.12.0](https://github.com/cozy/cozy-client/compare/v27.11.1...v27.12.0) (2022-01-14)
|
|
7
18
|
|
|
8
19
|
|
package/dist/CozyClient.js
CHANGED
|
@@ -2463,7 +2463,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2463
2463
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2464
2464
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2465
2465
|
|
|
2466
|
-
CozyClient.version = "27.
|
|
2466
|
+
CozyClient.version = "27.13.0";
|
|
2467
2467
|
|
|
2468
2468
|
_microee.default.mixin(CozyClient);
|
|
2469
2469
|
|
package/dist/models/file.js
CHANGED
|
@@ -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.isFromKonnector = exports.hasCertifications = exports.hasQualifications = exports.isPlainText = 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;
|
|
11
|
+
exports.fetchBlobFileById = exports.isFromKonnector = exports.hasCertifications = exports.hasQualifications = exports.isPlainText = 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
|
|
|
@@ -1023,5 +1023,46 @@ exports.hasCertifications = hasCertifications;
|
|
|
1023
1023
|
var isFromKonnector = function isFromKonnector(file) {
|
|
1024
1024
|
return (0, _has.default)(file, 'cozyMetadata.sourceAccount');
|
|
1025
1025
|
};
|
|
1026
|
+
/**
|
|
1027
|
+
* @param {CozyClient} client - Instance of CozyClient
|
|
1028
|
+
* @param {string} fileId - Id of io.cozy.files document
|
|
1029
|
+
* @returns {Promise<Blob>}
|
|
1030
|
+
*/
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
exports.isFromKonnector = isFromKonnector;
|
|
1034
|
+
|
|
1035
|
+
var fetchBlobFileById = /*#__PURE__*/function () {
|
|
1036
|
+
var _ref13 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(client, fileId) {
|
|
1037
|
+
var fileColl, fileBin, fileBlob;
|
|
1038
|
+
return _regenerator.default.wrap(function _callee12$(_context12) {
|
|
1039
|
+
while (1) {
|
|
1040
|
+
switch (_context12.prev = _context12.next) {
|
|
1041
|
+
case 0:
|
|
1042
|
+
fileColl = client.collection(_const.DOCTYPE_FILES);
|
|
1043
|
+
_context12.next = 3;
|
|
1044
|
+
return fileColl.fetchFileContentById(fileId);
|
|
1045
|
+
|
|
1046
|
+
case 3:
|
|
1047
|
+
fileBin = _context12.sent;
|
|
1048
|
+
_context12.next = 6;
|
|
1049
|
+
return fileBin.blob();
|
|
1050
|
+
|
|
1051
|
+
case 6:
|
|
1052
|
+
fileBlob = _context12.sent;
|
|
1053
|
+
return _context12.abrupt("return", fileBlob);
|
|
1054
|
+
|
|
1055
|
+
case 8:
|
|
1056
|
+
case "end":
|
|
1057
|
+
return _context12.stop();
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}, _callee12);
|
|
1061
|
+
}));
|
|
1062
|
+
|
|
1063
|
+
return function fetchBlobFileById(_x25, _x26) {
|
|
1064
|
+
return _ref13.apply(this, arguments);
|
|
1065
|
+
};
|
|
1066
|
+
}();
|
|
1026
1067
|
|
|
1027
|
-
exports.
|
|
1068
|
+
exports.fetchBlobFileById = fetchBlobFileById;
|
package/dist/models/file.spec.js
CHANGED
|
@@ -15,6 +15,7 @@ const statByPathSpy = jest.fn().mockName('statByPath')
|
|
|
15
15
|
const updateFileMetadataSpy = jest.fn().mockName('updateFileMetadata')
|
|
16
16
|
const createFileSpy = jest.fn().mockName('createFileSpy')
|
|
17
17
|
const updateFileSpy = jest.fn().mockName('updateFileSpy')
|
|
18
|
+
const fetchFileContentByIdSpy = jest.fn().mockName('fetchFileContentById')
|
|
18
19
|
|
|
19
20
|
beforeAll(() => {
|
|
20
21
|
cozyClient.stackClient.collection.mockReturnValue({
|
|
@@ -23,7 +24,8 @@ beforeAll(() => {
|
|
|
23
24
|
statByPath: statByPathSpy,
|
|
24
25
|
updateFileMetadata: updateFileMetadataSpy,
|
|
25
26
|
createFile: createFileSpy,
|
|
26
|
-
updateFile: updateFileSpy
|
|
27
|
+
updateFile: updateFileSpy,
|
|
28
|
+
fetchFileContentById: fetchFileContentByIdSpy
|
|
27
29
|
})
|
|
28
30
|
})
|
|
29
31
|
|
|
@@ -702,6 +704,21 @@ describe('File Model', () => {
|
|
|
702
704
|
})
|
|
703
705
|
})
|
|
704
706
|
})
|
|
707
|
+
|
|
708
|
+
describe('fetchBlobFileById', () => {
|
|
709
|
+
const mockData = { _id: '001', name: 'file01' }
|
|
710
|
+
|
|
711
|
+
it('should return Blob data', async () => {
|
|
712
|
+
fetchFileContentByIdSpy.mockImplementation(() => ({
|
|
713
|
+
blob: jest.fn().mockReturnValue(new Blob([mockData]))
|
|
714
|
+
}))
|
|
715
|
+
const res = await fileModel.fetchBlobFileById(cozyClient, mockData._id)
|
|
716
|
+
|
|
717
|
+
expect(fetchFileContentByIdSpy).toHaveBeenCalledWith('001')
|
|
718
|
+
expect(res instanceof Blob).toEqual(true)
|
|
719
|
+
expect(res.size).toBeGreaterThan(0)
|
|
720
|
+
})
|
|
721
|
+
})
|
|
705
722
|
})
|
|
706
723
|
|
|
707
724
|
describe('File qualification', () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.13.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
|
|
72
72
|
},
|
|
73
73
|
"sideEffects": false,
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "722612063fc639ce573a2b4239970cd13e61d2fb"
|
|
75
75
|
}
|
package/types/models/file.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export function isPlainText(mimeType?: string, fileName?: string): boolean;
|
|
|
61
61
|
export function hasQualifications(file: IOCozyFile): boolean;
|
|
62
62
|
export function hasCertifications(file: IOCozyFile): boolean;
|
|
63
63
|
export function isFromKonnector(file: IOCozyFile): boolean;
|
|
64
|
+
export function fetchBlobFileById(client: CozyClient, fileId: string): Promise<Blob>;
|
|
64
65
|
export type FileUploadOptions = {
|
|
65
66
|
/**
|
|
66
67
|
* - The file name to upload
|