cozy-client 60.1.1 → 60.3.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/dist/CozyClient.js +1 -1
- package/dist/links/DataProxyLink.js +165 -15
- package/dist/links/DataProxyLink.spec.js +86 -0
- package/dist/models/file.js +187 -127
- package/package.json +2 -2
- package/types/links/DataProxyLink.d.ts +5 -0
- package/types/models/file.d.ts +20 -6
package/dist/CozyClient.js
CHANGED
|
@@ -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.
|
|
3129
|
+
CozyClient.version = "60.3.0";
|
|
3130
3130
|
|
|
3131
3131
|
_microee.default.mixin(CozyClient);
|
|
3132
3132
|
|
|
@@ -15,14 +15,20 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
15
15
|
|
|
16
16
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
17
|
|
|
18
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
19
|
+
|
|
18
20
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
21
|
|
|
20
22
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
21
23
|
|
|
22
24
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
23
25
|
|
|
26
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
27
|
+
|
|
24
28
|
var _CozyLink2 = _interopRequireDefault(require("./CozyLink"));
|
|
25
29
|
|
|
30
|
+
var _cozyLogger = _interopRequireDefault(require("cozy-logger"));
|
|
31
|
+
|
|
26
32
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
27
33
|
|
|
28
34
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
@@ -44,7 +50,30 @@ var DataProxyLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
44
50
|
|
|
45
51
|
(0, _classCallCheck2.default)(this, DataProxyLink);
|
|
46
52
|
_this = _super.call(this);
|
|
53
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_onReceiveMessage", function (event) {
|
|
54
|
+
// See https://github.com/cozy/cozy-web-data-proxy/blob/1fc3deef767536aa264074c8a377f422b588409d/src/dataproxy/parent/ParentWindowProvider.tsx#L27
|
|
55
|
+
if (!event.origin.includes('dataproxy')) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var eventData = event === null || event === void 0 ? void 0 : event.data;
|
|
60
|
+
|
|
61
|
+
if (eventData && typeof eventData === 'object') {
|
|
62
|
+
if (eventData.type === 'DATAPROXYMESSAGE' && eventData.payload === 'READY') {
|
|
63
|
+
_cozyLogger.default.info("Received message: DataProxy is ready");
|
|
64
|
+
|
|
65
|
+
_this._flushQueue();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
47
69
|
_this.dataproxy = dataproxy || null;
|
|
70
|
+
_this._queue = [];
|
|
71
|
+
_this._drainingRequests = false;
|
|
72
|
+
|
|
73
|
+
if (window) {
|
|
74
|
+
window.addEventListener('message', _this._onReceiveMessage);
|
|
75
|
+
}
|
|
76
|
+
|
|
48
77
|
return _this;
|
|
49
78
|
}
|
|
50
79
|
|
|
@@ -64,6 +93,8 @@ var DataProxyLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
64
93
|
key: "registerDataProxy",
|
|
65
94
|
value: function registerDataProxy(dataproxy) {
|
|
66
95
|
this.dataproxy = dataproxy;
|
|
96
|
+
|
|
97
|
+
this._flushQueue();
|
|
67
98
|
}
|
|
68
99
|
}, {
|
|
69
100
|
key: "reset",
|
|
@@ -90,24 +121,31 @@ var DataProxyLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
90
121
|
key: "request",
|
|
91
122
|
value: function () {
|
|
92
123
|
var _request = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(operation, options, result, forward) {
|
|
93
|
-
var
|
|
124
|
+
var _this$dataproxy,
|
|
125
|
+
_this2 = this;
|
|
126
|
+
|
|
94
127
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
95
128
|
while (1) {
|
|
96
129
|
switch (_context2.prev = _context2.next) {
|
|
97
130
|
case 0:
|
|
98
|
-
if (!this.dataproxy) {
|
|
99
|
-
_context2.next =
|
|
131
|
+
if (!((_this$dataproxy = this.dataproxy) !== null && _this$dataproxy !== void 0 && _this$dataproxy.requestLink)) {
|
|
132
|
+
_context2.next = 2;
|
|
100
133
|
break;
|
|
101
134
|
}
|
|
102
135
|
|
|
103
|
-
|
|
104
|
-
opts = options || {};
|
|
105
|
-
return _context2.abrupt("return", this.dataproxy.requestLink(operation, opts));
|
|
136
|
+
return _context2.abrupt("return", this.doRequest(operation, options));
|
|
106
137
|
|
|
107
|
-
case
|
|
108
|
-
return _context2.abrupt("return",
|
|
138
|
+
case 2:
|
|
139
|
+
return _context2.abrupt("return", new Promise(function (resolve, reject) {
|
|
140
|
+
_this2._queue.push({
|
|
141
|
+
operation: operation,
|
|
142
|
+
options: options,
|
|
143
|
+
resolve: resolve,
|
|
144
|
+
reject: reject
|
|
145
|
+
});
|
|
146
|
+
}));
|
|
109
147
|
|
|
110
|
-
case
|
|
148
|
+
case 3:
|
|
111
149
|
case "end":
|
|
112
150
|
return _context2.stop();
|
|
113
151
|
}
|
|
@@ -122,29 +160,141 @@ var DataProxyLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
122
160
|
return request;
|
|
123
161
|
}()
|
|
124
162
|
}, {
|
|
125
|
-
key: "
|
|
163
|
+
key: "doRequest",
|
|
126
164
|
value: function () {
|
|
127
|
-
var
|
|
165
|
+
var _doRequest = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(operation, options) {
|
|
166
|
+
var opts, startQuery, resp, endQuery;
|
|
128
167
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
129
168
|
while (1) {
|
|
130
169
|
switch (_context3.prev = _context3.next) {
|
|
131
170
|
case 0:
|
|
132
|
-
|
|
171
|
+
opts = options || {};
|
|
172
|
+
startQuery = performance.now(); // Send the request to the DataProxy, that will handle both web and mobile environments
|
|
133
173
|
|
|
134
|
-
|
|
174
|
+
_context3.next = 4;
|
|
175
|
+
return this.dataproxy.requestLink(operation, opts);
|
|
176
|
+
|
|
177
|
+
case 4:
|
|
178
|
+
resp = _context3.sent;
|
|
179
|
+
endQuery = performance.now();
|
|
180
|
+
|
|
181
|
+
_cozyLogger.default.info("Request query took ".concat(endQuery - startQuery, " ms"));
|
|
182
|
+
|
|
183
|
+
return _context3.abrupt("return", resp);
|
|
184
|
+
|
|
185
|
+
case 8:
|
|
135
186
|
case "end":
|
|
136
187
|
return _context3.stop();
|
|
137
188
|
}
|
|
138
189
|
}
|
|
139
|
-
}, _callee3);
|
|
190
|
+
}, _callee3, this);
|
|
140
191
|
}));
|
|
141
192
|
|
|
142
|
-
function
|
|
193
|
+
function doRequest(_x5, _x6) {
|
|
194
|
+
return _doRequest.apply(this, arguments);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return doRequest;
|
|
198
|
+
}()
|
|
199
|
+
}, {
|
|
200
|
+
key: "persistCozyData",
|
|
201
|
+
value: function () {
|
|
202
|
+
var _persistCozyData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(data, forward) {
|
|
203
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
204
|
+
while (1) {
|
|
205
|
+
switch (_context4.prev = _context4.next) {
|
|
206
|
+
case 0:
|
|
207
|
+
return _context4.abrupt("return");
|
|
208
|
+
|
|
209
|
+
case 1:
|
|
210
|
+
case "end":
|
|
211
|
+
return _context4.stop();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}, _callee4);
|
|
215
|
+
}));
|
|
216
|
+
|
|
217
|
+
function persistCozyData(_x7, _x8) {
|
|
143
218
|
return _persistCozyData.apply(this, arguments);
|
|
144
219
|
}
|
|
145
220
|
|
|
146
221
|
return persistCozyData;
|
|
147
222
|
}()
|
|
223
|
+
}, {
|
|
224
|
+
key: "_flushQueue",
|
|
225
|
+
value: function () {
|
|
226
|
+
var _flushQueue2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
|
|
227
|
+
var _this$dataproxy2;
|
|
228
|
+
|
|
229
|
+
var _this$_queue$shift, operation, options, resolve, reject, resp;
|
|
230
|
+
|
|
231
|
+
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
232
|
+
while (1) {
|
|
233
|
+
switch (_context5.prev = _context5.next) {
|
|
234
|
+
case 0:
|
|
235
|
+
if (!(!((_this$dataproxy2 = this.dataproxy) !== null && _this$dataproxy2 !== void 0 && _this$dataproxy2.requestLink) || this._queue.length < 1)) {
|
|
236
|
+
_context5.next = 2;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return _context5.abrupt("return");
|
|
241
|
+
|
|
242
|
+
case 2:
|
|
243
|
+
_cozyLogger.default.info("Execute ".concat(this._queue.length, " delayed requests"));
|
|
244
|
+
|
|
245
|
+
this._drainingRequests = true;
|
|
246
|
+
_context5.prev = 4;
|
|
247
|
+
|
|
248
|
+
case 5:
|
|
249
|
+
if (!(this._queue.length > 0)) {
|
|
250
|
+
_context5.next = 19;
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
_this$_queue$shift = this._queue.shift(), operation = _this$_queue$shift.operation, options = _this$_queue$shift.options, resolve = _this$_queue$shift.resolve, reject = _this$_queue$shift.reject;
|
|
255
|
+
_context5.prev = 7;
|
|
256
|
+
_context5.next = 10;
|
|
257
|
+
return this.doRequest(operation, options);
|
|
258
|
+
|
|
259
|
+
case 10:
|
|
260
|
+
resp = _context5.sent;
|
|
261
|
+
resolve(resp);
|
|
262
|
+
_context5.next = 17;
|
|
263
|
+
break;
|
|
264
|
+
|
|
265
|
+
case 14:
|
|
266
|
+
_context5.prev = 14;
|
|
267
|
+
_context5.t0 = _context5["catch"](7);
|
|
268
|
+
reject(_context5.t0);
|
|
269
|
+
|
|
270
|
+
case 17:
|
|
271
|
+
_context5.next = 5;
|
|
272
|
+
break;
|
|
273
|
+
|
|
274
|
+
case 19:
|
|
275
|
+
_context5.prev = 19;
|
|
276
|
+
this._drainingRequests = false; // Run it again in case queue has filled again during the flush
|
|
277
|
+
|
|
278
|
+
if (this._queue.length > 0) {
|
|
279
|
+
this._flushQueue();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return _context5.finish(19);
|
|
283
|
+
|
|
284
|
+
case 23:
|
|
285
|
+
case "end":
|
|
286
|
+
return _context5.stop();
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}, _callee5, this, [[4,, 19, 23], [7, 14]]);
|
|
290
|
+
}));
|
|
291
|
+
|
|
292
|
+
function _flushQueue() {
|
|
293
|
+
return _flushQueue2.apply(this, arguments);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return _flushQueue;
|
|
297
|
+
}()
|
|
148
298
|
}]);
|
|
149
299
|
return DataProxyLink;
|
|
150
300
|
}(_CozyLink2.default);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
import DataProxyLink from './DataProxyLink'
|
|
3
|
+
|
|
4
|
+
describe('DataProxyLink queueing', () => {
|
|
5
|
+
it('should directly call dataproxy requestLink if available', async () => {
|
|
6
|
+
const requestLink = jest.fn().mockResolvedValue('OK')
|
|
7
|
+
const dataproxy = { requestLink }
|
|
8
|
+
const link = new DataProxyLink({ dataproxy })
|
|
9
|
+
|
|
10
|
+
const res = await link.request({ op: 'op1' }, {}, undefined, undefined)
|
|
11
|
+
|
|
12
|
+
expect(res).toBe('OK')
|
|
13
|
+
expect(requestLink).toHaveBeenCalledTimes(1)
|
|
14
|
+
expect(requestLink).toHaveBeenCalledWith({ op: 'op1' }, {})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('should fill the event queue as long as dataproxy is not ready and run all of them once it registers', async () => {
|
|
18
|
+
const link = new DataProxyLink() // no dataproxy
|
|
19
|
+
|
|
20
|
+
const p1 = link.request({ op: 'op1' }, {}, undefined, undefined)
|
|
21
|
+
const p2 = link.request({ op: 'op2' }, {}, undefined, undefined)
|
|
22
|
+
|
|
23
|
+
expect(link._queue.length).toEqual(2)
|
|
24
|
+
|
|
25
|
+
const requestLink = jest
|
|
26
|
+
.fn()
|
|
27
|
+
.mockResolvedValueOnce('Res1')
|
|
28
|
+
.mockResolvedValueOnce('Res2')
|
|
29
|
+
|
|
30
|
+
link.registerDataProxy({ requestLink })
|
|
31
|
+
|
|
32
|
+
await expect(p1).resolves.toBe('Res1')
|
|
33
|
+
await expect(p2).resolves.toBe('Res2')
|
|
34
|
+
|
|
35
|
+
expect(requestLink.mock.calls.map(c => c[0].op)).toEqual(['op1', 'op2'])
|
|
36
|
+
expect(link._queue.length).toEqual(0)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('should correctly deal with rejected promises ', async () => {
|
|
40
|
+
const link = new DataProxyLink()
|
|
41
|
+
|
|
42
|
+
const pOk1 = link.request({ op: 'op1' }, {})
|
|
43
|
+
const pFail = link.request({ op: 'op2' }, {})
|
|
44
|
+
const pOk2 = link.request({ op: 'op3' }, {})
|
|
45
|
+
|
|
46
|
+
const requestLink = jest
|
|
47
|
+
.fn()
|
|
48
|
+
.mockResolvedValueOnce('Res1')
|
|
49
|
+
.mockRejectedValueOnce(new Error('boom'))
|
|
50
|
+
.mockResolvedValueOnce('Res3')
|
|
51
|
+
|
|
52
|
+
link.registerDataProxy({ requestLink })
|
|
53
|
+
|
|
54
|
+
await expect(pOk1).resolves.toBe('Res1')
|
|
55
|
+
await expect(pFail).rejects.toThrow('boom')
|
|
56
|
+
await expect(pOk2).resolves.toBe('Res3')
|
|
57
|
+
|
|
58
|
+
expect(requestLink.mock.calls.map(c => c[0].op)).toEqual([
|
|
59
|
+
'op1',
|
|
60
|
+
'op2',
|
|
61
|
+
'op3'
|
|
62
|
+
])
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('should flush events when ready message is received', async () => {
|
|
66
|
+
const link = new DataProxyLink()
|
|
67
|
+
|
|
68
|
+
const p1 = link.request({ op: 'op1' }, {})
|
|
69
|
+
const p2 = link.request({ op: 'op2' }, {})
|
|
70
|
+
|
|
71
|
+
const requestLink = jest
|
|
72
|
+
.fn()
|
|
73
|
+
.mockResolvedValueOnce('Res1')
|
|
74
|
+
.mockResolvedValueOnce('Res2')
|
|
75
|
+
link.dataproxy = { requestLink }
|
|
76
|
+
|
|
77
|
+
const ev = new MessageEvent('message', {
|
|
78
|
+
data: { type: 'DATAPROXYMESSAGE', payload: 'READY' },
|
|
79
|
+
origin: 'http://dataproxy.cozy.localhost:8080'
|
|
80
|
+
})
|
|
81
|
+
window.dispatchEvent(ev)
|
|
82
|
+
|
|
83
|
+
await expect(p1).resolves.toBe('Res1')
|
|
84
|
+
await expect(p2).resolves.toBe('Res2')
|
|
85
|
+
})
|
|
86
|
+
})
|
package/dist/models/file.js
CHANGED
|
@@ -377,6 +377,8 @@ var isSharingShorcutNew = function isSharingShorcutNew(file) {
|
|
|
377
377
|
* @param {CozyClient} client - The CozyClient instance
|
|
378
378
|
* @param {import("../types").IOCozyFile} file - The file to qualify
|
|
379
379
|
* @param {object} qualification - The file qualification
|
|
380
|
+
* @param {object} [params] - Parameters
|
|
381
|
+
* @param {string} [params.driveId] - ID of the shared drive in which the file should be saved
|
|
380
382
|
* @returns {Promise<import("../types").IOCozyFile>} The saved file
|
|
381
383
|
*/
|
|
382
384
|
|
|
@@ -385,15 +387,22 @@ exports.isSharingShorcutNew = isSharingShorcutNew;
|
|
|
385
387
|
|
|
386
388
|
var saveFileQualification = /*#__PURE__*/function () {
|
|
387
389
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, file, qualification) {
|
|
388
|
-
var
|
|
390
|
+
var _ref2,
|
|
391
|
+
driveId,
|
|
392
|
+
qualifiedFile,
|
|
393
|
+
_args = arguments;
|
|
394
|
+
|
|
389
395
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
390
396
|
while (1) {
|
|
391
397
|
switch (_context.prev = _context.next) {
|
|
392
398
|
case 0:
|
|
399
|
+
_ref2 = _args.length > 3 && _args[3] !== undefined ? _args[3] : {}, driveId = _ref2.driveId;
|
|
393
400
|
qualifiedFile = (0, _qualification.setQualification)(file, qualification);
|
|
394
|
-
return _context.abrupt("return", client.collection(_const.DOCTYPE_FILES
|
|
401
|
+
return _context.abrupt("return", client.collection(_const.DOCTYPE_FILES, {
|
|
402
|
+
driveId: driveId
|
|
403
|
+
}).updateMetadataAttribute(file._id, qualifiedFile.metadata));
|
|
395
404
|
|
|
396
|
-
case
|
|
405
|
+
case 3:
|
|
397
406
|
case "end":
|
|
398
407
|
return _context.stop();
|
|
399
408
|
}
|
|
@@ -417,7 +426,7 @@ var saveFileQualification = /*#__PURE__*/function () {
|
|
|
417
426
|
exports.saveFileQualification = saveFileQualification;
|
|
418
427
|
|
|
419
428
|
var fetchFilesByQualificationRules = /*#__PURE__*/function () {
|
|
420
|
-
var
|
|
429
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(client, docRules) {
|
|
421
430
|
var rules, count, query, result;
|
|
422
431
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
423
432
|
while (1) {
|
|
@@ -445,7 +454,7 @@ var fetchFilesByQualificationRules = /*#__PURE__*/function () {
|
|
|
445
454
|
}));
|
|
446
455
|
|
|
447
456
|
return function fetchFilesByQualificationRules(_x4, _x5) {
|
|
448
|
-
return
|
|
457
|
+
return _ref3.apply(this, arguments);
|
|
449
458
|
};
|
|
450
459
|
}();
|
|
451
460
|
/**
|
|
@@ -460,9 +469,9 @@ var fetchFilesByQualificationRules = /*#__PURE__*/function () {
|
|
|
460
469
|
|
|
461
470
|
exports.fetchFilesByQualificationRules = fetchFilesByQualificationRules;
|
|
462
471
|
|
|
463
|
-
var hasMetadataAttribute = function hasMetadataAttribute(
|
|
464
|
-
var file =
|
|
465
|
-
attribute =
|
|
472
|
+
var hasMetadataAttribute = function hasMetadataAttribute(_ref4) {
|
|
473
|
+
var file = _ref4.file,
|
|
474
|
+
attribute = _ref4.attribute;
|
|
466
475
|
return (0, _has.default)(file, "metadata.".concat(attribute));
|
|
467
476
|
};
|
|
468
477
|
/**
|
|
@@ -478,7 +487,7 @@ var hasMetadataAttribute = function hasMetadataAttribute(_ref3) {
|
|
|
478
487
|
exports.hasMetadataAttribute = hasMetadataAttribute;
|
|
479
488
|
|
|
480
489
|
var getFullpath = /*#__PURE__*/function () {
|
|
481
|
-
var
|
|
490
|
+
var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(client, dirId, name) {
|
|
482
491
|
var _yield$client$query, parentDir, parentDirectoryPath;
|
|
483
492
|
|
|
484
493
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
@@ -511,7 +520,7 @@ var getFullpath = /*#__PURE__*/function () {
|
|
|
511
520
|
}));
|
|
512
521
|
|
|
513
522
|
return function getFullpath(_x6, _x7, _x8) {
|
|
514
|
-
return
|
|
523
|
+
return _ref5.apply(this, arguments);
|
|
515
524
|
};
|
|
516
525
|
}();
|
|
517
526
|
/**
|
|
@@ -525,8 +534,9 @@ var getFullpath = /*#__PURE__*/function () {
|
|
|
525
534
|
* @param {CozyClient} client - The CozyClient instance
|
|
526
535
|
* @param {import('../types').IOCozyFile | import('../types').NextcloudFile} file - The file to move (required)
|
|
527
536
|
* @param {import('../types').IOCozyFolder | import('../types').NextcloudFile} destination - The destination folder (required)
|
|
528
|
-
* @param {object} options
|
|
529
|
-
* @param {boolean} options.force
|
|
537
|
+
* @param {object} [options] - The options
|
|
538
|
+
* @param {boolean} [options.force] - Whether we should overwrite,
|
|
539
|
+
* @param {string} [options.driveId] - The ID of the shared drive in which the file should be moved
|
|
530
540
|
* i.e. put to trash, the destination in case of conflict (defaults to false).
|
|
531
541
|
* @returns {Promise<{moved: undefined|import('../types').IOCozyFile, deleted: null|string[] }>} - A promise that returns the move action response (if any)
|
|
532
542
|
* and the deleted file id (if any) if resolved or an Error if rejected
|
|
@@ -536,9 +546,12 @@ var getFullpath = /*#__PURE__*/function () {
|
|
|
536
546
|
exports.getFullpath = getFullpath;
|
|
537
547
|
|
|
538
548
|
var move = /*#__PURE__*/function () {
|
|
539
|
-
var
|
|
540
|
-
var
|
|
549
|
+
var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(client, file, destination) {
|
|
550
|
+
var _ref7,
|
|
551
|
+
_ref7$force,
|
|
541
552
|
force,
|
|
553
|
+
driveId,
|
|
554
|
+
filesCollection,
|
|
542
555
|
resp,
|
|
543
556
|
destinationPath,
|
|
544
557
|
conflictResp,
|
|
@@ -549,9 +562,7 @@ var move = /*#__PURE__*/function () {
|
|
|
549
562
|
while (1) {
|
|
550
563
|
switch (_context4.prev = _context4.next) {
|
|
551
564
|
case 0:
|
|
552
|
-
|
|
553
|
-
force: false
|
|
554
|
-
}, force = _ref6.force;
|
|
565
|
+
_ref7 = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : {}, _ref7$force = _ref7.force, force = _ref7$force === void 0 ? false : _ref7$force, driveId = _ref7.driveId;
|
|
555
566
|
_context4.prev = 1;
|
|
556
567
|
|
|
557
568
|
if (!(file._type === 'io.cozy.remote.nextcloud.files')) {
|
|
@@ -608,77 +619,83 @@ var move = /*#__PURE__*/function () {
|
|
|
608
619
|
throw _context4.t0;
|
|
609
620
|
|
|
610
621
|
case 19:
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
622
|
+
// Move inside a Cozy server
|
|
623
|
+
filesCollection = client.collection(_const.DOCTYPE_FILES, {
|
|
624
|
+
driveId: driveId
|
|
625
|
+
});
|
|
626
|
+
_context4.prev = 20;
|
|
627
|
+
_context4.next = 23;
|
|
628
|
+
return filesCollection.updateFileMetadata(file._id, {
|
|
614
629
|
dir_id: destination._id
|
|
615
630
|
});
|
|
616
631
|
|
|
617
|
-
case
|
|
632
|
+
case 23:
|
|
618
633
|
resp = _context4.sent;
|
|
619
634
|
return _context4.abrupt("return", {
|
|
620
635
|
moved: resp.data,
|
|
621
636
|
deleted: null
|
|
622
637
|
});
|
|
623
638
|
|
|
624
|
-
case
|
|
625
|
-
_context4.prev =
|
|
626
|
-
_context4.t1 = _context4["catch"](
|
|
639
|
+
case 27:
|
|
640
|
+
_context4.prev = 27;
|
|
641
|
+
_context4.t1 = _context4["catch"](20);
|
|
627
642
|
|
|
628
643
|
if (!(_context4.t1.status === 409 && force)) {
|
|
629
|
-
_context4.next =
|
|
644
|
+
_context4.next = 44;
|
|
630
645
|
break;
|
|
631
646
|
}
|
|
632
647
|
|
|
633
|
-
_context4.next =
|
|
648
|
+
_context4.next = 32;
|
|
634
649
|
return getFullpath(client, destination._id, file.name);
|
|
635
650
|
|
|
636
|
-
case
|
|
651
|
+
case 32:
|
|
637
652
|
destinationPath = _context4.sent;
|
|
638
|
-
_context4.next =
|
|
639
|
-
return
|
|
653
|
+
_context4.next = 35;
|
|
654
|
+
return filesCollection.statByPath(destinationPath);
|
|
640
655
|
|
|
641
|
-
case
|
|
656
|
+
case 35:
|
|
642
657
|
conflictResp = _context4.sent;
|
|
643
|
-
_context4.next =
|
|
644
|
-
return
|
|
658
|
+
_context4.next = 38;
|
|
659
|
+
return filesCollection.destroy(conflictResp.data);
|
|
645
660
|
|
|
646
|
-
case
|
|
647
|
-
_context4.next =
|
|
648
|
-
return
|
|
661
|
+
case 38:
|
|
662
|
+
_context4.next = 40;
|
|
663
|
+
return filesCollection.updateFileMetadata(file._id, {
|
|
649
664
|
dir_id: destination._id
|
|
650
665
|
});
|
|
651
666
|
|
|
652
|
-
case
|
|
667
|
+
case 40:
|
|
653
668
|
_resp = _context4.sent;
|
|
654
669
|
return _context4.abrupt("return", {
|
|
655
670
|
moved: _resp.data,
|
|
656
671
|
deleted: conflictResp.data.id
|
|
657
672
|
});
|
|
658
673
|
|
|
659
|
-
case
|
|
674
|
+
case 44:
|
|
660
675
|
throw _context4.t1;
|
|
661
676
|
|
|
662
|
-
case
|
|
677
|
+
case 45:
|
|
663
678
|
case "end":
|
|
664
679
|
return _context4.stop();
|
|
665
680
|
}
|
|
666
681
|
}
|
|
667
|
-
}, _callee4, null, [[1, 16], [
|
|
682
|
+
}, _callee4, null, [[1, 16], [20, 27]]);
|
|
668
683
|
}));
|
|
669
684
|
|
|
670
685
|
return function move(_x9, _x10, _x11) {
|
|
671
|
-
return
|
|
686
|
+
return _ref6.apply(this, arguments);
|
|
672
687
|
};
|
|
673
688
|
}();
|
|
674
689
|
/**
|
|
675
690
|
*
|
|
676
691
|
* Method to upload a file even if a file with the same name already exists.
|
|
677
692
|
*
|
|
678
|
-
* @param {CozyClient} client
|
|
679
|
-
* @param {string} dirPath
|
|
680
|
-
* @param {object} file
|
|
681
|
-
* @param {object} metadata
|
|
693
|
+
* @param {CozyClient} client - The CozyClient instance
|
|
694
|
+
* @param {string} dirPath - Fullpath of directory to upload to ex: path/to/
|
|
695
|
+
* @param {object} file - HTML Object file
|
|
696
|
+
* @param {object} metadata - An object containing the wanted metadata to attach
|
|
697
|
+
* @param {object} [params] - Parameters
|
|
698
|
+
* @param {string} [params.driveId] - ID of the shared drive in which the file should be saved
|
|
682
699
|
* @returns {Promise<import("../types").IOCozyFile>} The overrided file
|
|
683
700
|
*/
|
|
684
701
|
|
|
@@ -686,71 +703,85 @@ var move = /*#__PURE__*/function () {
|
|
|
686
703
|
exports.move = move;
|
|
687
704
|
|
|
688
705
|
var overrideFileForPath = /*#__PURE__*/function () {
|
|
689
|
-
var
|
|
690
|
-
var
|
|
706
|
+
var _ref8 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(client, dirPath, file, metadata) {
|
|
707
|
+
var _ref9,
|
|
708
|
+
driveId,
|
|
709
|
+
path,
|
|
710
|
+
filesCollection,
|
|
711
|
+
existingFile,
|
|
712
|
+
_existingFile$data,
|
|
713
|
+
fileId,
|
|
714
|
+
dirId,
|
|
715
|
+
resp,
|
|
716
|
+
_dirId,
|
|
717
|
+
createdFile,
|
|
718
|
+
_args5 = arguments;
|
|
691
719
|
|
|
692
720
|
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
693
721
|
while (1) {
|
|
694
722
|
switch (_context5.prev = _context5.next) {
|
|
695
723
|
case 0:
|
|
724
|
+
_ref9 = _args5.length > 4 && _args5[4] !== undefined ? _args5[4] : {}, driveId = _ref9.driveId;
|
|
696
725
|
path = dirPath;
|
|
697
726
|
if (!path.endsWith('/')) path = path + '/';
|
|
698
|
-
filesCollection = client.collection(_const.DOCTYPE_FILES
|
|
699
|
-
|
|
700
|
-
|
|
727
|
+
filesCollection = client.collection(_const.DOCTYPE_FILES, {
|
|
728
|
+
driveId: driveId
|
|
729
|
+
});
|
|
730
|
+
_context5.prev = 4;
|
|
731
|
+
_context5.next = 7;
|
|
701
732
|
return filesCollection.statByPath(path + file.name);
|
|
702
733
|
|
|
703
|
-
case
|
|
734
|
+
case 7:
|
|
704
735
|
existingFile = _context5.sent;
|
|
705
736
|
_existingFile$data = existingFile.data, fileId = _existingFile$data.id, dirId = _existingFile$data.dir_id;
|
|
706
|
-
_context5.next =
|
|
737
|
+
_context5.next = 11;
|
|
707
738
|
return filesCollection.updateFile(file, {
|
|
708
739
|
dirId: dirId,
|
|
709
740
|
fileId: fileId,
|
|
710
741
|
metadata: metadata
|
|
711
742
|
});
|
|
712
743
|
|
|
713
|
-
case
|
|
744
|
+
case 11:
|
|
714
745
|
resp = _context5.sent;
|
|
715
746
|
return _context5.abrupt("return", resp);
|
|
716
747
|
|
|
717
|
-
case
|
|
718
|
-
_context5.prev =
|
|
719
|
-
_context5.t0 = _context5["catch"](
|
|
748
|
+
case 15:
|
|
749
|
+
_context5.prev = 15;
|
|
750
|
+
_context5.t0 = _context5["catch"](4);
|
|
720
751
|
|
|
721
752
|
if (!/Not Found/.test(_context5.t0)) {
|
|
722
|
-
_context5.next =
|
|
753
|
+
_context5.next = 25;
|
|
723
754
|
break;
|
|
724
755
|
}
|
|
725
756
|
|
|
726
|
-
_context5.next =
|
|
757
|
+
_context5.next = 20;
|
|
727
758
|
return filesCollection.ensureDirectoryExists(path);
|
|
728
759
|
|
|
729
|
-
case
|
|
760
|
+
case 20:
|
|
730
761
|
_dirId = _context5.sent;
|
|
731
|
-
_context5.next =
|
|
762
|
+
_context5.next = 23;
|
|
732
763
|
return filesCollection.createFile(file, {
|
|
733
764
|
dirId: _dirId,
|
|
734
765
|
metadata: metadata
|
|
735
766
|
});
|
|
736
767
|
|
|
737
|
-
case
|
|
768
|
+
case 23:
|
|
738
769
|
createdFile = _context5.sent;
|
|
739
770
|
return _context5.abrupt("return", createdFile);
|
|
740
771
|
|
|
741
|
-
case
|
|
772
|
+
case 25:
|
|
742
773
|
throw _context5.t0;
|
|
743
774
|
|
|
744
|
-
case
|
|
775
|
+
case 26:
|
|
745
776
|
case "end":
|
|
746
777
|
return _context5.stop();
|
|
747
778
|
}
|
|
748
779
|
}
|
|
749
|
-
}, _callee5, null, [[
|
|
780
|
+
}, _callee5, null, [[4, 15]]);
|
|
750
781
|
}));
|
|
751
782
|
|
|
752
783
|
return function overrideFileForPath(_x12, _x13, _x14, _x15) {
|
|
753
|
-
return
|
|
784
|
+
return _ref8.apply(this, arguments);
|
|
754
785
|
};
|
|
755
786
|
}();
|
|
756
787
|
/**
|
|
@@ -806,6 +837,7 @@ var generateFileNameForRevision = function generateFileNameForRevision(file, rev
|
|
|
806
837
|
* @property {string} [contentType] - The file Content-Type
|
|
807
838
|
* @property {string} [conflictStrategy] - Erase / rename
|
|
808
839
|
* @property {import('../types').ConflictOptions} [conflictOptions] - Conflict options
|
|
840
|
+
* @property {string} [driveId] - ID of the shared drive in which the file should be saved
|
|
809
841
|
*/
|
|
810
842
|
|
|
811
843
|
/**
|
|
@@ -828,42 +860,45 @@ var generateFileNameForRevision = function generateFileNameForRevision(file, rev
|
|
|
828
860
|
exports.generateFileNameForRevision = generateFileNameForRevision;
|
|
829
861
|
|
|
830
862
|
var uploadFileWithConflictStrategy = /*#__PURE__*/function () {
|
|
831
|
-
var
|
|
832
|
-
var name, dirId, conflictStrategy, conflictOptions, path, existingFile, fileId, resp, _splitFilename2, filename, extension, newFileName;
|
|
863
|
+
var _ref10 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(client, file, options) {
|
|
864
|
+
var name, dirId, conflictStrategy, conflictOptions, driveId, filesCollection, path, existingFile, fileId, resp, _splitFilename2, filename, extension, newFileName;
|
|
833
865
|
|
|
834
866
|
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
835
867
|
while (1) {
|
|
836
868
|
switch (_context6.prev = _context6.next) {
|
|
837
869
|
case 0:
|
|
838
|
-
name = options.name, dirId = options.dirId, conflictStrategy = options.conflictStrategy, conflictOptions = options.conflictOptions;
|
|
839
|
-
|
|
840
|
-
|
|
870
|
+
name = options.name, dirId = options.dirId, conflictStrategy = options.conflictStrategy, conflictOptions = options.conflictOptions, driveId = options.driveId;
|
|
871
|
+
filesCollection = client.collection(_const.DOCTYPE_FILES, {
|
|
872
|
+
driveId: driveId
|
|
873
|
+
});
|
|
874
|
+
_context6.prev = 2;
|
|
875
|
+
_context6.next = 5;
|
|
841
876
|
return getFullpath(client, dirId, name);
|
|
842
877
|
|
|
843
|
-
case
|
|
878
|
+
case 5:
|
|
844
879
|
path = _context6.sent;
|
|
845
|
-
_context6.next =
|
|
846
|
-
return
|
|
880
|
+
_context6.next = 8;
|
|
881
|
+
return filesCollection.statByPath(path);
|
|
847
882
|
|
|
848
|
-
case
|
|
883
|
+
case 8:
|
|
849
884
|
existingFile = _context6.sent;
|
|
850
885
|
fileId = existingFile.data.id;
|
|
851
886
|
|
|
852
887
|
if (!(conflictStrategy === 'erase')) {
|
|
853
|
-
_context6.next =
|
|
888
|
+
_context6.next = 17;
|
|
854
889
|
break;
|
|
855
890
|
}
|
|
856
891
|
|
|
857
|
-
_context6.next =
|
|
858
|
-
return
|
|
892
|
+
_context6.next = 13;
|
|
893
|
+
return filesCollection.updateFile(file, _objectSpread(_objectSpread({}, options), {}, {
|
|
859
894
|
fileId: fileId
|
|
860
895
|
}));
|
|
861
896
|
|
|
862
|
-
case
|
|
897
|
+
case 13:
|
|
863
898
|
resp = _context6.sent;
|
|
864
899
|
return _context6.abrupt("return", resp);
|
|
865
900
|
|
|
866
|
-
case
|
|
901
|
+
case 17:
|
|
867
902
|
// @ts-ignore
|
|
868
903
|
_splitFilename2 = splitFilename({
|
|
869
904
|
name: name,
|
|
@@ -875,34 +910,34 @@ var uploadFileWithConflictStrategy = /*#__PURE__*/function () {
|
|
|
875
910
|
name: newFileName
|
|
876
911
|
})));
|
|
877
912
|
|
|
878
|
-
case
|
|
879
|
-
_context6.next =
|
|
913
|
+
case 20:
|
|
914
|
+
_context6.next = 27;
|
|
880
915
|
break;
|
|
881
916
|
|
|
882
|
-
case
|
|
883
|
-
_context6.prev =
|
|
884
|
-
_context6.t0 = _context6["catch"](
|
|
917
|
+
case 22:
|
|
918
|
+
_context6.prev = 22;
|
|
919
|
+
_context6.t0 = _context6["catch"](2);
|
|
885
920
|
|
|
886
921
|
if (!/Not Found/.test(_context6.t0.message)) {
|
|
887
|
-
_context6.next =
|
|
922
|
+
_context6.next = 26;
|
|
888
923
|
break;
|
|
889
924
|
}
|
|
890
925
|
|
|
891
|
-
return _context6.abrupt("return",
|
|
926
|
+
return _context6.abrupt("return", filesCollection.createFile(file, options));
|
|
892
927
|
|
|
893
|
-
case
|
|
928
|
+
case 26:
|
|
894
929
|
throw _context6.t0;
|
|
895
930
|
|
|
896
|
-
case
|
|
931
|
+
case 27:
|
|
897
932
|
case "end":
|
|
898
933
|
return _context6.stop();
|
|
899
934
|
}
|
|
900
935
|
}
|
|
901
|
-
}, _callee6, null, [[
|
|
936
|
+
}, _callee6, null, [[2, 22]]);
|
|
902
937
|
}));
|
|
903
938
|
|
|
904
939
|
return function uploadFileWithConflictStrategy(_x16, _x17, _x18) {
|
|
905
|
-
return
|
|
940
|
+
return _ref10.apply(this, arguments);
|
|
906
941
|
};
|
|
907
942
|
}();
|
|
908
943
|
/**
|
|
@@ -955,6 +990,8 @@ var isFromKonnector = function isFromKonnector(file) {
|
|
|
955
990
|
/**
|
|
956
991
|
* @param {CozyClient} client - Instance of CozyClient
|
|
957
992
|
* @param {string} fileId - Id of io.cozy.files document
|
|
993
|
+
* @param {object} [params] - Parameters
|
|
994
|
+
* @param {string} [params.driveId] - ID of the shared drive in which the file should be saved
|
|
958
995
|
* @returns {Promise<Blob>}
|
|
959
996
|
*/
|
|
960
997
|
|
|
@@ -962,26 +999,35 @@ var isFromKonnector = function isFromKonnector(file) {
|
|
|
962
999
|
exports.isFromKonnector = isFromKonnector;
|
|
963
1000
|
|
|
964
1001
|
var fetchBlobFileById = /*#__PURE__*/function () {
|
|
965
|
-
var
|
|
966
|
-
var
|
|
1002
|
+
var _ref11 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(client, fileId) {
|
|
1003
|
+
var _ref12,
|
|
1004
|
+
driveId,
|
|
1005
|
+
fileColl,
|
|
1006
|
+
fileBin,
|
|
1007
|
+
fileBlob,
|
|
1008
|
+
_args7 = arguments;
|
|
1009
|
+
|
|
967
1010
|
return _regenerator.default.wrap(function _callee7$(_context7) {
|
|
968
1011
|
while (1) {
|
|
969
1012
|
switch (_context7.prev = _context7.next) {
|
|
970
1013
|
case 0:
|
|
971
|
-
|
|
972
|
-
|
|
1014
|
+
_ref12 = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : {}, driveId = _ref12.driveId;
|
|
1015
|
+
fileColl = client.collection(_const.DOCTYPE_FILES, {
|
|
1016
|
+
driveId: driveId
|
|
1017
|
+
});
|
|
1018
|
+
_context7.next = 4;
|
|
973
1019
|
return fileColl.fetchFileContentById(fileId);
|
|
974
1020
|
|
|
975
|
-
case
|
|
1021
|
+
case 4:
|
|
976
1022
|
fileBin = _context7.sent;
|
|
977
|
-
_context7.next =
|
|
1023
|
+
_context7.next = 7;
|
|
978
1024
|
return fileBin.blob();
|
|
979
1025
|
|
|
980
|
-
case
|
|
1026
|
+
case 7:
|
|
981
1027
|
fileBlob = _context7.sent;
|
|
982
1028
|
return _context7.abrupt("return", fileBlob);
|
|
983
1029
|
|
|
984
|
-
case
|
|
1030
|
+
case 9:
|
|
985
1031
|
case "end":
|
|
986
1032
|
return _context7.stop();
|
|
987
1033
|
}
|
|
@@ -990,7 +1036,7 @@ var fetchBlobFileById = /*#__PURE__*/function () {
|
|
|
990
1036
|
}));
|
|
991
1037
|
|
|
992
1038
|
return function fetchBlobFileById(_x19, _x20) {
|
|
993
|
-
return
|
|
1039
|
+
return _ref11.apply(this, arguments);
|
|
994
1040
|
};
|
|
995
1041
|
}();
|
|
996
1042
|
/**
|
|
@@ -999,6 +1045,8 @@ var fetchBlobFileById = /*#__PURE__*/function () {
|
|
|
999
1045
|
* @param {object} client - The client object used for making API requests.
|
|
1000
1046
|
* @param {object} file - The file object to be copied.
|
|
1001
1047
|
* @param {object} destination - The destination object where the file will be copied to.
|
|
1048
|
+
* @param {object} [params] - Parameters
|
|
1049
|
+
* @param {string} [params.driveId] - ID of the shared drive in which the file should be saved
|
|
1002
1050
|
* @returns {Promise} - A promise that resolves with the response from the API.
|
|
1003
1051
|
* @throws {Error} - If an error occurs during the API request.
|
|
1004
1052
|
*/
|
|
@@ -1007,80 +1055,89 @@ var fetchBlobFileById = /*#__PURE__*/function () {
|
|
|
1007
1055
|
exports.fetchBlobFileById = fetchBlobFileById;
|
|
1008
1056
|
|
|
1009
1057
|
var copy = /*#__PURE__*/function () {
|
|
1010
|
-
var
|
|
1011
|
-
var
|
|
1058
|
+
var _ref13 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(client, file, destination) {
|
|
1059
|
+
var _ref14,
|
|
1060
|
+
driveId,
|
|
1061
|
+
_resp2,
|
|
1062
|
+
_resp3,
|
|
1063
|
+
_resp4,
|
|
1064
|
+
resp,
|
|
1065
|
+
_args8 = arguments;
|
|
1012
1066
|
|
|
1013
1067
|
return _regenerator.default.wrap(function _callee8$(_context8) {
|
|
1014
1068
|
while (1) {
|
|
1015
1069
|
switch (_context8.prev = _context8.next) {
|
|
1016
1070
|
case 0:
|
|
1017
|
-
|
|
1071
|
+
_ref14 = _args8.length > 3 && _args8[3] !== undefined ? _args8[3] : {}, driveId = _ref14.driveId;
|
|
1072
|
+
_context8.prev = 1;
|
|
1018
1073
|
|
|
1019
1074
|
if (!(file._type === 'io.cozy.remote.nextcloud.files' && destination._type === 'io.cozy.remote.nextcloud.files')) {
|
|
1020
|
-
_context8.next =
|
|
1075
|
+
_context8.next = 7;
|
|
1021
1076
|
break;
|
|
1022
1077
|
}
|
|
1023
1078
|
|
|
1024
|
-
_context8.next =
|
|
1079
|
+
_context8.next = 5;
|
|
1025
1080
|
return client.collection('io.cozy.remote.nextcloud.files').copy(file, destination);
|
|
1026
1081
|
|
|
1027
|
-
case
|
|
1082
|
+
case 5:
|
|
1028
1083
|
_resp2 = _context8.sent;
|
|
1029
1084
|
return _context8.abrupt("return", _resp2);
|
|
1030
1085
|
|
|
1031
|
-
case
|
|
1086
|
+
case 7:
|
|
1032
1087
|
if (!(file._type === 'io.cozy.remote.nextcloud.files' && destination._type === 'io.cozy.files')) {
|
|
1033
|
-
_context8.next =
|
|
1088
|
+
_context8.next = 12;
|
|
1034
1089
|
break;
|
|
1035
1090
|
}
|
|
1036
1091
|
|
|
1037
|
-
_context8.next =
|
|
1092
|
+
_context8.next = 10;
|
|
1038
1093
|
return client.collection('io.cozy.remote.nextcloud.files').moveToCozy(file, destination, {
|
|
1039
1094
|
copy: true
|
|
1040
1095
|
});
|
|
1041
1096
|
|
|
1042
|
-
case
|
|
1097
|
+
case 10:
|
|
1043
1098
|
_resp3 = _context8.sent;
|
|
1044
1099
|
return _context8.abrupt("return", _resp3);
|
|
1045
1100
|
|
|
1046
|
-
case
|
|
1101
|
+
case 12:
|
|
1047
1102
|
if (!(destination._type === 'io.cozy.remote.nextcloud.files')) {
|
|
1048
|
-
_context8.next =
|
|
1103
|
+
_context8.next = 17;
|
|
1049
1104
|
break;
|
|
1050
1105
|
}
|
|
1051
1106
|
|
|
1052
|
-
_context8.next =
|
|
1107
|
+
_context8.next = 15;
|
|
1053
1108
|
return client.collection('io.cozy.remote.nextcloud.files').moveFromCozy(destination, file, {
|
|
1054
1109
|
copy: true
|
|
1055
1110
|
});
|
|
1056
1111
|
|
|
1057
|
-
case
|
|
1112
|
+
case 15:
|
|
1058
1113
|
_resp4 = _context8.sent;
|
|
1059
1114
|
return _context8.abrupt("return", _resp4);
|
|
1060
1115
|
|
|
1061
|
-
case
|
|
1062
|
-
_context8.next =
|
|
1063
|
-
return client.collection(_const.DOCTYPE_FILES
|
|
1116
|
+
case 17:
|
|
1117
|
+
_context8.next = 19;
|
|
1118
|
+
return client.collection(_const.DOCTYPE_FILES, {
|
|
1119
|
+
driveId: driveId
|
|
1120
|
+
}).copy(file._id, undefined, destination._id);
|
|
1064
1121
|
|
|
1065
|
-
case
|
|
1122
|
+
case 19:
|
|
1066
1123
|
resp = _context8.sent;
|
|
1067
1124
|
return _context8.abrupt("return", resp);
|
|
1068
1125
|
|
|
1069
|
-
case
|
|
1070
|
-
_context8.prev =
|
|
1071
|
-
_context8.t0 = _context8["catch"](
|
|
1126
|
+
case 23:
|
|
1127
|
+
_context8.prev = 23;
|
|
1128
|
+
_context8.t0 = _context8["catch"](1);
|
|
1072
1129
|
throw _context8.t0;
|
|
1073
1130
|
|
|
1074
|
-
case
|
|
1131
|
+
case 26:
|
|
1075
1132
|
case "end":
|
|
1076
1133
|
return _context8.stop();
|
|
1077
1134
|
}
|
|
1078
1135
|
}
|
|
1079
|
-
}, _callee8, null, [[
|
|
1136
|
+
}, _callee8, null, [[1, 23]]);
|
|
1080
1137
|
}));
|
|
1081
1138
|
|
|
1082
1139
|
return function copy(_x21, _x22, _x23) {
|
|
1083
|
-
return
|
|
1140
|
+
return _ref13.apply(this, arguments);
|
|
1084
1141
|
};
|
|
1085
1142
|
}();
|
|
1086
1143
|
/**
|
|
@@ -1095,6 +1152,7 @@ var copy = /*#__PURE__*/function () {
|
|
|
1095
1152
|
* @param {CozyClient} params.client - Instance of CozyClient
|
|
1096
1153
|
* @param {import("../types").IOCozyFile} params.file - io.cozy.files metadata of the document to downloaded
|
|
1097
1154
|
* @param {string} [params.url] - Blob url that should be used to download encrypted files
|
|
1155
|
+
* @param {string} [params.driveId] - ID of the shared drive in which the file can be found
|
|
1098
1156
|
* @param {import('cozy-intent').WebviewService} [params.webviewIntent] - webviewIntent that can be used to redirect the download to host Flagship app
|
|
1099
1157
|
*
|
|
1100
1158
|
* @returns {Promise<any>}
|
|
@@ -1104,15 +1162,17 @@ var copy = /*#__PURE__*/function () {
|
|
|
1104
1162
|
exports.copy = copy;
|
|
1105
1163
|
|
|
1106
1164
|
var downloadFile = /*#__PURE__*/function () {
|
|
1107
|
-
var
|
|
1108
|
-
var client, file, url, webviewIntent, filesCollection, _yield$webviewIntent$, isFlagshipDownloadAvailable;
|
|
1165
|
+
var _ref16 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(_ref15) {
|
|
1166
|
+
var client, file, url, webviewIntent, driveId, filesCollection, _yield$webviewIntent$, isFlagshipDownloadAvailable;
|
|
1109
1167
|
|
|
1110
1168
|
return _regenerator.default.wrap(function _callee9$(_context9) {
|
|
1111
1169
|
while (1) {
|
|
1112
1170
|
switch (_context9.prev = _context9.next) {
|
|
1113
1171
|
case 0:
|
|
1114
|
-
client =
|
|
1115
|
-
filesCollection = client.collection(_const.DOCTYPE_FILES
|
|
1172
|
+
client = _ref15.client, file = _ref15.file, url = _ref15.url, webviewIntent = _ref15.webviewIntent, driveId = _ref15.driveId;
|
|
1173
|
+
filesCollection = client.collection(_const.DOCTYPE_FILES, {
|
|
1174
|
+
driveId: driveId
|
|
1175
|
+
});
|
|
1116
1176
|
|
|
1117
1177
|
if (!((0, _cozyDeviceHelper.isFlagshipApp)() && webviewIntent && !isEncrypted(file))) {
|
|
1118
1178
|
_context9.next = 19;
|
|
@@ -1180,7 +1240,7 @@ var downloadFile = /*#__PURE__*/function () {
|
|
|
1180
1240
|
}));
|
|
1181
1241
|
|
|
1182
1242
|
return function downloadFile(_x24) {
|
|
1183
|
-
return
|
|
1243
|
+
return _ref16.apply(this, arguments);
|
|
1184
1244
|
};
|
|
1185
1245
|
}();
|
|
1186
1246
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "60.
|
|
3
|
+
"version": "60.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"react-native-ios11-devicecheck": "^0.0.3"
|
|
75
75
|
},
|
|
76
76
|
"sideEffects": false,
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "708cec590442076e46405082403975018fa8bb31"
|
|
78
78
|
}
|
|
@@ -7,6 +7,8 @@ export default class DataProxyLink extends CozyLink {
|
|
|
7
7
|
dataproxy: object;
|
|
8
8
|
});
|
|
9
9
|
dataproxy: any;
|
|
10
|
+
_queue: any[];
|
|
11
|
+
_drainingRequests: boolean;
|
|
10
12
|
registerClient(client: any): void;
|
|
11
13
|
/**
|
|
12
14
|
* When the link is given to a cozy-client instance, the dataproxy might not be ready yet.
|
|
@@ -16,5 +18,8 @@ export default class DataProxyLink extends CozyLink {
|
|
|
16
18
|
* @param {object} dataproxy - The dataproxy instance
|
|
17
19
|
*/
|
|
18
20
|
registerDataProxy(dataproxy: object): void;
|
|
21
|
+
doRequest(operation: any, options: any): Promise<any>;
|
|
22
|
+
_flushQueue(): Promise<void>;
|
|
23
|
+
_onReceiveMessage: (event: any) => void;
|
|
19
24
|
}
|
|
20
25
|
import CozyLink from "./CozyLink";
|
package/types/models/file.d.ts
CHANGED
|
@@ -47,20 +47,25 @@ export function isSharingShortcut(file: import("../types").IOCozyFile): boolean;
|
|
|
47
47
|
export function isSharingShorcut(file: import("../types").IOCozyFile): boolean;
|
|
48
48
|
export function isSharingShortcutNew(file: import("../types").IOCozyFile): boolean;
|
|
49
49
|
export function isSharingShorcutNew(file: object): boolean;
|
|
50
|
-
export function saveFileQualification(client: CozyClient, file: import("../types").IOCozyFile, qualification: object
|
|
50
|
+
export function saveFileQualification(client: CozyClient, file: import("../types").IOCozyFile, qualification: object, { driveId }?: {
|
|
51
|
+
driveId: string;
|
|
52
|
+
}): Promise<import("../types").IOCozyFile>;
|
|
51
53
|
export function fetchFilesByQualificationRules(client: object, docRules: object): Promise<import("../types").QueryResult>;
|
|
52
54
|
export function hasMetadataAttribute({ file, attribute }: {
|
|
53
55
|
file: import("../types").IOCozyFile;
|
|
54
56
|
attribute: string;
|
|
55
57
|
}): boolean;
|
|
56
58
|
export function getFullpath(client: CozyClient, dirId: string, name: string): Promise<string>;
|
|
57
|
-
export function move(client: CozyClient, file: import('../types').IOCozyFile | import('../types').NextcloudFile, destination: import('../types').IOCozyFolder | import('../types').NextcloudFile, { force }?: {
|
|
59
|
+
export function move(client: CozyClient, file: import('../types').IOCozyFile | import('../types').NextcloudFile, destination: import('../types').IOCozyFolder | import('../types').NextcloudFile, { force, driveId }?: {
|
|
58
60
|
force: boolean;
|
|
61
|
+
driveId: string;
|
|
59
62
|
}): Promise<{
|
|
60
63
|
moved: undefined | import('../types').IOCozyFile;
|
|
61
64
|
deleted: null | string[];
|
|
62
65
|
}>;
|
|
63
|
-
export function overrideFileForPath(client: CozyClient, dirPath: string, file: object, metadata: object
|
|
66
|
+
export function overrideFileForPath(client: CozyClient, dirPath: string, file: object, metadata: object, { driveId }?: {
|
|
67
|
+
driveId: string;
|
|
68
|
+
}): Promise<import("../types").IOCozyFile>;
|
|
64
69
|
export function generateNewFileNameOnConflict(filenameWithoutExtension: string, conflictOptions?: import('../types').ConflictOptions): string;
|
|
65
70
|
export function generateFileNameForRevision(file: import("../types").IOCozyFile, revision: object, f: Function): string;
|
|
66
71
|
export function uploadFileWithConflictStrategy(client: CozyClient, file: string | ArrayBuffer, options: FileUploadOptions): any;
|
|
@@ -68,12 +73,17 @@ export function isPlainText(mimeType?: string, fileName?: string): boolean;
|
|
|
68
73
|
export function hasQualifications(file: import("../types").IOCozyFile): boolean;
|
|
69
74
|
export function hasCertifications(file: import("../types").IOCozyFile): boolean;
|
|
70
75
|
export function isFromKonnector(file: import("../types").IOCozyFile): boolean;
|
|
71
|
-
export function fetchBlobFileById(client: CozyClient, fileId: string
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
export function fetchBlobFileById(client: CozyClient, fileId: string, { driveId }?: {
|
|
77
|
+
driveId: string;
|
|
78
|
+
}): Promise<Blob>;
|
|
79
|
+
export function copy(client: object, file: object, destination: object, { driveId }?: {
|
|
80
|
+
driveId: string;
|
|
81
|
+
}): Promise<any>;
|
|
82
|
+
export function downloadFile({ client, file, url, webviewIntent, driveId }: {
|
|
74
83
|
client: CozyClient;
|
|
75
84
|
file: import("../types").IOCozyFile;
|
|
76
85
|
url: string;
|
|
86
|
+
driveId: string;
|
|
77
87
|
webviewIntent: import('cozy-intent').WebviewService;
|
|
78
88
|
}): Promise<any>;
|
|
79
89
|
export type FileUploadOptions = {
|
|
@@ -101,5 +111,9 @@ export type FileUploadOptions = {
|
|
|
101
111
|
* - Conflict options
|
|
102
112
|
*/
|
|
103
113
|
conflictOptions?: import('../types').ConflictOptions;
|
|
114
|
+
/**
|
|
115
|
+
* - ID of the shared drive in which the file should be saved
|
|
116
|
+
*/
|
|
117
|
+
driveId?: string;
|
|
104
118
|
};
|
|
105
119
|
import CozyClient from "../CozyClient";
|