@nextcloud/files 2.1.0 → 3.0.0-beta.10

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.
Files changed (44) hide show
  1. package/LICENSE +68 -81
  2. package/README.md +1 -1
  3. package/dist/fileAction.d.ts +77 -0
  4. package/dist/files/file.d.ts +26 -0
  5. package/dist/files/fileType.d.ts +25 -0
  6. package/dist/files/folder.d.ts +30 -0
  7. package/dist/files/node.d.ts +86 -0
  8. package/dist/files/nodeData.d.ts +59 -0
  9. package/dist/humanfilesize.d.ts +29 -1
  10. package/dist/index.d.ts +44 -0
  11. package/dist/index.esm.js +771 -0
  12. package/dist/index.esm.js.map +1 -0
  13. package/dist/index.js +889 -14
  14. package/dist/index.js.map +1 -1
  15. package/dist/newFileMenu.d.ts +52 -0
  16. package/dist/permissions.d.ts +35 -0
  17. package/dist/utils/logger.d.ts +23 -0
  18. package/package.json +61 -27
  19. package/.github/dependabot.yml +0 -10
  20. package/.github/workflows/dependabot-approve-merge.yml +0 -29
  21. package/.travis.yml +0 -19
  22. package/CHANGELOG.md +0 -23
  23. package/babel.config.js +0 -15
  24. package/dist/doc/.nojekyll +0 -0
  25. package/dist/doc/assets/css/main.css +0 -2328
  26. package/dist/doc/assets/images/icons.png +0 -0
  27. package/dist/doc/assets/images/icons@2x.png +0 -0
  28. package/dist/doc/assets/images/widgets.png +0 -0
  29. package/dist/doc/assets/images/widgets@2x.png +0 -0
  30. package/dist/doc/assets/js/main.js +0 -1
  31. package/dist/doc/assets/js/search.js +0 -3
  32. package/dist/doc/globals.html +0 -169
  33. package/dist/doc/index.html +0 -161
  34. package/dist/doc/modules/_humanfilesize_.html +0 -239
  35. package/dist/doc/modules/_index_.html +0 -158
  36. package/dist/filepicker.d.ts +0 -33
  37. package/dist/filepicker.js +0 -70
  38. package/dist/filepicker.js.map +0 -1
  39. package/dist/humanfilesize.js +0 -41
  40. package/dist/humanfilesize.js.map +0 -1
  41. package/lib/humanfilesize.ts +0 -28
  42. package/lib/index.ts +0 -1
  43. package/test/humanFileSize.test.js +0 -65
  44. package/tsconfig.json +0 -14
package/dist/index.js CHANGED
@@ -1,14 +1,889 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "formatFileSize", {
7
- enumerable: true,
8
- get: function get() {
9
- return _humanfilesize.formatFileSize;
10
- }
11
- });
12
-
13
- var _humanfilesize = require("./humanfilesize");
14
- //# sourceMappingURL=index.js.map
1
+ 'use strict';
2
+
3
+ var l10n = require('@nextcloud/l10n');
4
+ var auth = require('@nextcloud/auth');
5
+ var logger$1 = require('@nextcloud/logger');
6
+ var path = require('path');
7
+
8
+ /**
9
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
10
+ *
11
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
12
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
13
+ *
14
+ * @license AGPL-3.0-or-later
15
+ *
16
+ * This program is free software: you can redistribute it and/or modify
17
+ * it under the terms of the GNU Affero General Public License as
18
+ * published by the Free Software Foundation, either version 3 of the
19
+ * License, or (at your option) any later version.
20
+ *
21
+ * This program is distributed in the hope that it will be useful,
22
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ * GNU Affero General Public License for more details.
25
+ *
26
+ * You should have received a copy of the GNU Affero General Public License
27
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
28
+ *
29
+ */
30
+ var humanList = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
31
+ var humanListBinary = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
32
+ /**
33
+ * Format a file size in a human-like format. e.g. 42GB
34
+ *
35
+ * @param size in bytes
36
+ * @param skipSmallSizes avoid rendering tiny sizes and return '< 1 KB' instead
37
+ */
38
+ function formatFileSize(size, skipSmallSizes, binaryPrefixes) {
39
+ if (skipSmallSizes === void 0) { skipSmallSizes = false; }
40
+ if (binaryPrefixes === void 0) { binaryPrefixes = false; }
41
+ if (typeof size === 'string') {
42
+ size = Number(size);
43
+ }
44
+ /*
45
+ * @note This block previously used Log base 1024, per IEC 80000-13;
46
+ * however, the wrong prefix was used. Now we use decimal calculation
47
+ * with base 1000 per the SI. Base 1024 calculation with binary
48
+ * prefixes is optional, but has yet to be added to the UI.
49
+ */
50
+ // Calculate Log with base 1024 or 1000: size = base ** order
51
+ var order = size > 0 ? Math.floor(Math.log(size) / Math.log(binaryPrefixes ? 1024 : 1000)) : 0;
52
+ // Stay in range of the byte sizes that are defined
53
+ order = Math.min((binaryPrefixes ? humanListBinary.length : humanList.length) - 1, order);
54
+ var readableFormat = binaryPrefixes ? humanListBinary[order] : humanList[order];
55
+ var relativeSize = (size / Math.pow(binaryPrefixes ? 1024 : 1000, order)).toFixed(1);
56
+ if (skipSmallSizes === true && order === 0) {
57
+ return (relativeSize !== '0.0' ? '< 1 ' : '0 ') + (binaryPrefixes ? humanListBinary[1] : humanList[1]);
58
+ }
59
+ if (order < 2) {
60
+ relativeSize = parseFloat(relativeSize).toFixed(0);
61
+ }
62
+ else {
63
+ relativeSize = parseFloat(relativeSize).toLocaleString(l10n.getCanonicalLocale());
64
+ }
65
+ return relativeSize + ' ' + readableFormat;
66
+ }
67
+
68
+ /**
69
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
70
+ *
71
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
72
+ *
73
+ * @license AGPL-3.0-or-later
74
+ *
75
+ * This program is free software: you can redistribute it and/or modify
76
+ * it under the terms of the GNU Affero General Public License as
77
+ * published by the Free Software Foundation, either version 3 of the
78
+ * License, or (at your option) any later version.
79
+ *
80
+ * This program is distributed in the hope that it will be useful,
81
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
82
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83
+ * GNU Affero General Public License for more details.
84
+ *
85
+ * You should have received a copy of the GNU Affero General Public License
86
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
87
+ *
88
+ */
89
+ var getLogger = function (user) {
90
+ if (user === null) {
91
+ return logger$1.getLoggerBuilder()
92
+ .setApp('files')
93
+ .build();
94
+ }
95
+ return logger$1.getLoggerBuilder()
96
+ .setApp('files')
97
+ .setUid(user.uid)
98
+ .build();
99
+ };
100
+ var logger = getLogger(auth.getCurrentUser());
101
+
102
+ /**
103
+ * @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
104
+ *
105
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
106
+ *
107
+ * @license AGPL-3.0-or-later
108
+ *
109
+ * This program is free software: you can redistribute it and/or modify
110
+ * it under the terms of the GNU Affero General Public License as
111
+ * published by the Free Software Foundation, either version 3 of the
112
+ * License, or (at your option) any later version.
113
+ *
114
+ * This program is distributed in the hope that it will be useful,
115
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
116
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
117
+ * GNU Affero General Public License for more details.
118
+ *
119
+ * You should have received a copy of the GNU Affero General Public License
120
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
121
+ *
122
+ */
123
+ var NewFileMenu = /** @class */ (function () {
124
+ function NewFileMenu() {
125
+ this._entries = [];
126
+ }
127
+ NewFileMenu.prototype.registerEntry = function (entry) {
128
+ this.validateEntry(entry);
129
+ this._entries.push(entry);
130
+ };
131
+ NewFileMenu.prototype.unregisterEntry = function (entry) {
132
+ var entryIndex = typeof entry === 'string'
133
+ ? this.getEntryIndex(entry)
134
+ : this.getEntryIndex(entry.id);
135
+ if (entryIndex === -1) {
136
+ logger.warn('Entry not found, nothing removed', { entry: entry, entries: this.getEntries() });
137
+ return;
138
+ }
139
+ this._entries.splice(entryIndex, 1);
140
+ };
141
+ /**
142
+ * Get the list of registered entries
143
+ *
144
+ * @param {FileInfo} context the creation context. Usually the current folder FileInfo
145
+ */
146
+ NewFileMenu.prototype.getEntries = function (context) {
147
+ if (context) {
148
+ return this._entries
149
+ .filter(function (entry) { return typeof entry.if === 'function' ? entry.if(context) : true; });
150
+ }
151
+ return this._entries;
152
+ };
153
+ NewFileMenu.prototype.getEntryIndex = function (id) {
154
+ return this._entries.findIndex(function (entry) { return entry.id === id; });
155
+ };
156
+ NewFileMenu.prototype.validateEntry = function (entry) {
157
+ if (!entry.id || !entry.displayName || !(entry.iconSvgInline || entry.iconClass)) {
158
+ throw new Error('Invalid entry');
159
+ }
160
+ if (typeof entry.id !== 'string'
161
+ || typeof entry.displayName !== 'string') {
162
+ throw new Error('Invalid id or displayName property');
163
+ }
164
+ if ((entry.iconClass && typeof entry.iconClass !== 'string')
165
+ || (entry.iconSvgInline && typeof entry.iconSvgInline !== 'string')) {
166
+ throw new Error('Invalid icon provided');
167
+ }
168
+ if (entry.if !== undefined && typeof entry.if !== 'function') {
169
+ throw new Error('Invalid if property');
170
+ }
171
+ if (entry.templateName && typeof entry.templateName !== 'string') {
172
+ throw new Error('Invalid templateName property');
173
+ }
174
+ if (entry.handler && typeof entry.handler !== 'function') {
175
+ throw new Error('Invalid handler property');
176
+ }
177
+ if (!entry.templateName && !entry.handler) {
178
+ throw new Error('At least a templateName or a handler must be provided');
179
+ }
180
+ if (this.getEntryIndex(entry.id) !== -1) {
181
+ throw new Error('Duplicate entry');
182
+ }
183
+ };
184
+ return NewFileMenu;
185
+ }());
186
+ var getNewFileMenu = function () {
187
+ if (typeof window._nc_newfilemenu === 'undefined') {
188
+ window._nc_newfilemenu = new NewFileMenu();
189
+ logger.debug('NewFileMenu initialized');
190
+ }
191
+ return window._nc_newfilemenu;
192
+ };
193
+
194
+ /**
195
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
196
+ *
197
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
198
+ *
199
+ * @license AGPL-3.0-or-later
200
+ *
201
+ * This program is free software: you can redistribute it and/or modify
202
+ * it under the terms of the GNU Affero General Public License as
203
+ * published by the Free Software Foundation, either version 3 of the
204
+ * License, or (at your option) any later version.
205
+ *
206
+ * This program is distributed in the hope that it will be useful,
207
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
208
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
209
+ * GNU Affero General Public License for more details.
210
+ *
211
+ * You should have received a copy of the GNU Affero General Public License
212
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
213
+ *
214
+ */
215
+ exports.FileType = void 0;
216
+ (function (FileType) {
217
+ FileType["Folder"] = "folder";
218
+ FileType["File"] = "file";
219
+ })(exports.FileType || (exports.FileType = {}));
220
+
221
+ /******************************************************************************
222
+ Copyright (c) Microsoft Corporation.
223
+
224
+ Permission to use, copy, modify, and/or distribute this software for any
225
+ purpose with or without fee is hereby granted.
226
+
227
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
228
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
229
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
230
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
231
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
232
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
233
+ PERFORMANCE OF THIS SOFTWARE.
234
+ ***************************************************************************** */
235
+ /* global Reflect, Promise */
236
+
237
+ var extendStatics = function(d, b) {
238
+ extendStatics = Object.setPrototypeOf ||
239
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
240
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
241
+ return extendStatics(d, b);
242
+ };
243
+
244
+ function __extends(d, b) {
245
+ if (typeof b !== "function" && b !== null)
246
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
247
+ extendStatics(d, b);
248
+ function __() { this.constructor = d; }
249
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
250
+ }
251
+
252
+ var __assign = function() {
253
+ __assign = Object.assign || function __assign(t) {
254
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
255
+ s = arguments[i];
256
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
257
+ }
258
+ return t;
259
+ };
260
+ return __assign.apply(this, arguments);
261
+ };
262
+
263
+ /**
264
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
265
+ *
266
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
267
+ *
268
+ * @license AGPL-3.0-or-later
269
+ *
270
+ * This program is free software: you can redistribute it and/or modify
271
+ * it under the terms of the GNU Affero General Public License as
272
+ * published by the Free Software Foundation, either version 3 of the
273
+ * License, or (at your option) any later version.
274
+ *
275
+ * This program is distributed in the hope that it will be useful,
276
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
277
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
278
+ * GNU Affero General Public License for more details.
279
+ *
280
+ * You should have received a copy of the GNU Affero General Public License
281
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
282
+ *
283
+ */
284
+ exports.Permission = void 0;
285
+ (function (Permission) {
286
+ Permission[Permission["NONE"] = 0] = "NONE";
287
+ Permission[Permission["CREATE"] = 4] = "CREATE";
288
+ Permission[Permission["READ"] = 1] = "READ";
289
+ Permission[Permission["UPDATE"] = 2] = "UPDATE";
290
+ Permission[Permission["DELETE"] = 8] = "DELETE";
291
+ Permission[Permission["SHARE"] = 16] = "SHARE";
292
+ Permission[Permission["ALL"] = 31] = "ALL";
293
+ })(exports.Permission || (exports.Permission = {}));
294
+ /**
295
+ * Parse the webdav permission string to a permission enum
296
+ * @see https://github.com/nextcloud/server/blob/71f698649f578db19a22457cb9d420fb62c10382/lib/public/Files/DavUtil.php#L58-L88
297
+ */
298
+ var parseWebdavPermissions = function (permString) {
299
+ if (permString === void 0) { permString = ''; }
300
+ var permissions = exports.Permission.NONE;
301
+ if (!permString)
302
+ return permissions;
303
+ if (permString.includes('C') || permString.includes('K'))
304
+ permissions |= exports.Permission.CREATE;
305
+ if (permString.includes('G'))
306
+ permissions |= exports.Permission.READ;
307
+ if (permString.includes('W') || permString.includes('N') || permString.includes('V'))
308
+ permissions |= exports.Permission.UPDATE;
309
+ if (permString.includes('D'))
310
+ permissions |= exports.Permission.DELETE;
311
+ if (permString.includes('R'))
312
+ permissions |= exports.Permission.SHARE;
313
+ return permissions;
314
+ };
315
+
316
+ /**
317
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
318
+ *
319
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
320
+ *
321
+ * @license AGPL-3.0-or-later
322
+ *
323
+ * This program is free software: you can redistribute it and/or modify
324
+ * it under the terms of the GNU Affero General Public License as
325
+ * published by the Free Software Foundation, either version 3 of the
326
+ * License, or (at your option) any later version.
327
+ *
328
+ * This program is distributed in the hope that it will be useful,
329
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
330
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
331
+ * GNU Affero General Public License for more details.
332
+ *
333
+ * You should have received a copy of the GNU Affero General Public License
334
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
335
+ *
336
+ */
337
+ var isDavRessource = function (source, davService) {
338
+ return source.match(davService) !== null;
339
+ };
340
+ /**
341
+ * Validate Node construct data
342
+ */
343
+ var validateData = function (data, davService) {
344
+ if ('id' in data && (typeof data.id !== 'number' || data.id < 0)) {
345
+ throw new Error('Invalid id type of value');
346
+ }
347
+ if (!data.source) {
348
+ throw new Error('Missing mandatory source');
349
+ }
350
+ try {
351
+ new URL(data.source);
352
+ }
353
+ catch (e) {
354
+ throw new Error('Invalid source format, source must be a valid URL');
355
+ }
356
+ if (!data.source.startsWith('http')) {
357
+ throw new Error('Invalid source format, only http(s) is supported');
358
+ }
359
+ if ('mtime' in data && !(data.mtime instanceof Date)) {
360
+ throw new Error('Invalid mtime type');
361
+ }
362
+ if ('crtime' in data && !(data.crtime instanceof Date)) {
363
+ throw new Error('Invalid crtime type');
364
+ }
365
+ if (!data.mime || typeof data.mime !== 'string'
366
+ || !data.mime.match(/^[-\w.]+\/[-+\w.]+$/gi)) {
367
+ throw new Error('Missing or invalid mandatory mime');
368
+ }
369
+ if ('size' in data && typeof data.size !== 'number') {
370
+ throw new Error('Invalid size type');
371
+ }
372
+ if ('permissions' in data && !(typeof data.permissions === 'number'
373
+ && data.permissions >= exports.Permission.NONE
374
+ && data.permissions <= exports.Permission.ALL)) {
375
+ throw new Error('Invalid permissions');
376
+ }
377
+ if ('owner' in data
378
+ && data.owner !== null
379
+ && typeof data.owner !== 'string') {
380
+ throw new Error('Invalid owner type');
381
+ }
382
+ if ('attributes' in data && typeof data.attributes !== 'object') {
383
+ throw new Error('Invalid attributes format');
384
+ }
385
+ if ('root' in data && typeof data.root !== 'string') {
386
+ throw new Error('Invalid root format');
387
+ }
388
+ if (data.root && !data.root.startsWith('/')) {
389
+ throw new Error('Root must start with a leading slash');
390
+ }
391
+ if (data.root && !data.source.includes(data.root)) {
392
+ throw new Error('Root must be part of the source');
393
+ }
394
+ if (data.root && isDavRessource(data.source, davService)) {
395
+ var service = data.source.match(davService)[0];
396
+ if (!data.source.includes(path.join(service, data.root))) {
397
+ throw new Error('The root must be relative to the service. e.g /files/emma');
398
+ }
399
+ }
400
+ };
401
+
402
+ var Node = /** @class */ (function () {
403
+ function Node(data, davService) {
404
+ var _this = this;
405
+ this._knownDavService = /(remote|public)\.php\/(web)?dav/i;
406
+ // Validate data
407
+ validateData(data, davService || this._knownDavService);
408
+ this._data = data;
409
+ var handler = {
410
+ set: function (target, prop, value) {
411
+ // Edit modification time
412
+ _this._data['mtime'] = new Date();
413
+ // Apply original changes
414
+ return Reflect.set(target, prop, value);
415
+ },
416
+ deleteProperty: function (target, prop) {
417
+ // Edit modification time
418
+ _this._data['mtime'] = new Date();
419
+ // Apply original changes
420
+ return Reflect.deleteProperty(target, prop);
421
+ },
422
+ };
423
+ // Proxy the attributes to update the mtime on change
424
+ this._attributes = new Proxy(data.attributes || {}, handler);
425
+ delete this._data.attributes;
426
+ if (davService) {
427
+ this._knownDavService = davService;
428
+ }
429
+ }
430
+ Object.defineProperty(Node.prototype, "source", {
431
+ /**
432
+ * Get the source url to this object
433
+ */
434
+ get: function () {
435
+ // strip any ending slash
436
+ return this._data.source.replace(/\/$/i, '');
437
+ },
438
+ enumerable: false,
439
+ configurable: true
440
+ });
441
+ Object.defineProperty(Node.prototype, "basename", {
442
+ /**
443
+ * Get this object name
444
+ */
445
+ get: function () {
446
+ return path.basename(this.source);
447
+ },
448
+ enumerable: false,
449
+ configurable: true
450
+ });
451
+ Object.defineProperty(Node.prototype, "extension", {
452
+ /**
453
+ * Get this object's extension
454
+ */
455
+ get: function () {
456
+ return path.extname(this.source);
457
+ },
458
+ enumerable: false,
459
+ configurable: true
460
+ });
461
+ Object.defineProperty(Node.prototype, "dirname", {
462
+ /**
463
+ * Get the directory path leading to this object
464
+ * Will use the relative path to root if available
465
+ */
466
+ get: function () {
467
+ if (this.root) {
468
+ // Using replace would remove all part matching root
469
+ var firstMatch = this.source.indexOf(this.root);
470
+ return path.dirname(this.source.slice(firstMatch + this.root.length) || '/');
471
+ }
472
+ // This should always be a valid URL
473
+ // as this is tested in the constructor
474
+ var url = new URL(this.source);
475
+ return path.dirname(url.pathname);
476
+ },
477
+ enumerable: false,
478
+ configurable: true
479
+ });
480
+ Object.defineProperty(Node.prototype, "mime", {
481
+ /**
482
+ * Get the file mime
483
+ */
484
+ get: function () {
485
+ return this._data.mime;
486
+ },
487
+ enumerable: false,
488
+ configurable: true
489
+ });
490
+ Object.defineProperty(Node.prototype, "mtime", {
491
+ /**
492
+ * Get the file modification time
493
+ */
494
+ get: function () {
495
+ return this._data.mtime;
496
+ },
497
+ enumerable: false,
498
+ configurable: true
499
+ });
500
+ Object.defineProperty(Node.prototype, "crtime", {
501
+ /**
502
+ * Get the file creation time
503
+ */
504
+ get: function () {
505
+ return this._data.crtime;
506
+ },
507
+ enumerable: false,
508
+ configurable: true
509
+ });
510
+ Object.defineProperty(Node.prototype, "size", {
511
+ /**
512
+ * Get the file size
513
+ */
514
+ get: function () {
515
+ return this._data.size;
516
+ },
517
+ enumerable: false,
518
+ configurable: true
519
+ });
520
+ Object.defineProperty(Node.prototype, "attributes", {
521
+ /**
522
+ * Get the file attribute
523
+ */
524
+ get: function () {
525
+ return this._attributes;
526
+ },
527
+ enumerable: false,
528
+ configurable: true
529
+ });
530
+ Object.defineProperty(Node.prototype, "permissions", {
531
+ /**
532
+ * Get the file permissions
533
+ */
534
+ get: function () {
535
+ // If this is not a dav ressource, we can only read it
536
+ if (this.owner === null && !this.isDavRessource) {
537
+ return exports.Permission.READ;
538
+ }
539
+ // If the permissions are not defined, we have none
540
+ return this._data.permissions !== undefined
541
+ ? this._data.permissions
542
+ : exports.Permission.NONE;
543
+ },
544
+ enumerable: false,
545
+ configurable: true
546
+ });
547
+ Object.defineProperty(Node.prototype, "owner", {
548
+ /**
549
+ * Get the file owner
550
+ */
551
+ get: function () {
552
+ // Remote ressources have no owner
553
+ if (!this.isDavRessource) {
554
+ return null;
555
+ }
556
+ return this._data.owner;
557
+ },
558
+ enumerable: false,
559
+ configurable: true
560
+ });
561
+ Object.defineProperty(Node.prototype, "isDavRessource", {
562
+ /**
563
+ * Is this a dav-related ressource ?
564
+ */
565
+ get: function () {
566
+ return isDavRessource(this.source, this._knownDavService);
567
+ },
568
+ enumerable: false,
569
+ configurable: true
570
+ });
571
+ Object.defineProperty(Node.prototype, "root", {
572
+ /**
573
+ * Get the dav root of this object
574
+ */
575
+ get: function () {
576
+ // If provided (recommended), use the root and strip away the ending slash
577
+ if (this._data.root) {
578
+ return this._data.root.replace(/^(.+)\/$/, '$1');
579
+ }
580
+ // Use the source to get the root from the dav service
581
+ if (this.isDavRessource) {
582
+ var root = path.dirname(this.source);
583
+ return root.split(this._knownDavService).pop() || null;
584
+ }
585
+ return null;
586
+ },
587
+ enumerable: false,
588
+ configurable: true
589
+ });
590
+ Object.defineProperty(Node.prototype, "path", {
591
+ /**
592
+ * Get the absolute path of this object relative to the root
593
+ */
594
+ get: function () {
595
+ if (this.root) {
596
+ // Using replace would remove all part matching root
597
+ var firstMatch = this.source.indexOf(this.root);
598
+ return this.source.slice(firstMatch + this.root.length) || '/';
599
+ }
600
+ return (this.dirname + '/' + this.basename).replace(/\/\//g, '/');
601
+ },
602
+ enumerable: false,
603
+ configurable: true
604
+ });
605
+ Object.defineProperty(Node.prototype, "fileid", {
606
+ /**
607
+ * Get the file id if defined in attributes
608
+ */
609
+ get: function () {
610
+ var _a;
611
+ return (_a = this.attributes) === null || _a === void 0 ? void 0 : _a.fileid;
612
+ },
613
+ enumerable: false,
614
+ configurable: true
615
+ });
616
+ /**
617
+ * Move the node to a new destination
618
+ *
619
+ * @param {string} destination the new source.
620
+ * e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg
621
+ */
622
+ Node.prototype.move = function (destination) {
623
+ validateData(__assign(__assign({}, this._data), { source: destination }), this._knownDavService);
624
+ this._data.source = destination;
625
+ this._data.mtime = new Date();
626
+ };
627
+ /**
628
+ * Rename the node
629
+ * This aliases the move method for easier usage
630
+ */
631
+ Node.prototype.rename = function (basename) {
632
+ if (basename.includes('/')) {
633
+ throw new Error('Invalid basename');
634
+ }
635
+ this.move(path.dirname(this.source) + '/' + basename);
636
+ };
637
+ return Node;
638
+ }());
639
+
640
+ var File = /** @class */ (function (_super) {
641
+ __extends(File, _super);
642
+ function File() {
643
+ return _super !== null && _super.apply(this, arguments) || this;
644
+ }
645
+ Object.defineProperty(File.prototype, "type", {
646
+ get: function () {
647
+ return exports.FileType.File;
648
+ },
649
+ enumerable: false,
650
+ configurable: true
651
+ });
652
+ return File;
653
+ }(Node));
654
+
655
+ var Folder = /** @class */ (function (_super) {
656
+ __extends(Folder, _super);
657
+ function Folder(data) {
658
+ // enforcing mimes
659
+ return _super.call(this, __assign(__assign({}, data), { mime: 'httpd/unix-directory' })) || this;
660
+ }
661
+ Object.defineProperty(Folder.prototype, "type", {
662
+ get: function () {
663
+ return exports.FileType.Folder;
664
+ },
665
+ enumerable: false,
666
+ configurable: true
667
+ });
668
+ Object.defineProperty(Folder.prototype, "extension", {
669
+ get: function () {
670
+ return null;
671
+ },
672
+ enumerable: false,
673
+ configurable: true
674
+ });
675
+ Object.defineProperty(Folder.prototype, "mime", {
676
+ get: function () {
677
+ return 'httpd/unix-directory';
678
+ },
679
+ enumerable: false,
680
+ configurable: true
681
+ });
682
+ return Folder;
683
+ }(Node));
684
+
685
+ /**
686
+ * @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
687
+ *
688
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
689
+ *
690
+ * @license AGPL-3.0-or-later
691
+ *
692
+ * This program is free software: you can redistribute it and/or modify
693
+ * it under the terms of the GNU Affero General Public License as
694
+ * published by the Free Software Foundation, either version 3 of the
695
+ * License, or (at your option) any later version.
696
+ *
697
+ * This program is distributed in the hope that it will be useful,
698
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
699
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
700
+ * GNU Affero General Public License for more details.
701
+ *
702
+ * You should have received a copy of the GNU Affero General Public License
703
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
704
+ *
705
+ */
706
+ var FileAction = /** @class */ (function () {
707
+ function FileAction(action) {
708
+ this.validateAction(action);
709
+ this._action = action;
710
+ }
711
+ Object.defineProperty(FileAction.prototype, "id", {
712
+ get: function () {
713
+ return this._action.id;
714
+ },
715
+ enumerable: false,
716
+ configurable: true
717
+ });
718
+ Object.defineProperty(FileAction.prototype, "displayName", {
719
+ get: function () {
720
+ return this._action.displayName;
721
+ },
722
+ enumerable: false,
723
+ configurable: true
724
+ });
725
+ Object.defineProperty(FileAction.prototype, "iconSvgInline", {
726
+ get: function () {
727
+ return this._action.iconSvgInline;
728
+ },
729
+ enumerable: false,
730
+ configurable: true
731
+ });
732
+ Object.defineProperty(FileAction.prototype, "enabled", {
733
+ get: function () {
734
+ return this._action.enabled;
735
+ },
736
+ enumerable: false,
737
+ configurable: true
738
+ });
739
+ Object.defineProperty(FileAction.prototype, "exec", {
740
+ get: function () {
741
+ return this._action.exec;
742
+ },
743
+ enumerable: false,
744
+ configurable: true
745
+ });
746
+ Object.defineProperty(FileAction.prototype, "execBatch", {
747
+ get: function () {
748
+ return this._action.execBatch;
749
+ },
750
+ enumerable: false,
751
+ configurable: true
752
+ });
753
+ Object.defineProperty(FileAction.prototype, "order", {
754
+ get: function () {
755
+ return this._action.order;
756
+ },
757
+ enumerable: false,
758
+ configurable: true
759
+ });
760
+ Object.defineProperty(FileAction.prototype, "default", {
761
+ get: function () {
762
+ return this._action.default;
763
+ },
764
+ enumerable: false,
765
+ configurable: true
766
+ });
767
+ Object.defineProperty(FileAction.prototype, "inline", {
768
+ get: function () {
769
+ return this._action.inline;
770
+ },
771
+ enumerable: false,
772
+ configurable: true
773
+ });
774
+ Object.defineProperty(FileAction.prototype, "renderInline", {
775
+ get: function () {
776
+ return this._action.renderInline;
777
+ },
778
+ enumerable: false,
779
+ configurable: true
780
+ });
781
+ FileAction.prototype.validateAction = function (action) {
782
+ if (!action.id || typeof action.id !== 'string') {
783
+ throw new Error('Invalid id');
784
+ }
785
+ if (!action.displayName || typeof action.displayName !== 'function') {
786
+ throw new Error('Invalid displayName function');
787
+ }
788
+ if (!action.iconSvgInline || typeof action.iconSvgInline !== 'function') {
789
+ throw new Error('Invalid iconSvgInline function');
790
+ }
791
+ if (!action.exec || typeof action.exec !== 'function') {
792
+ throw new Error('Invalid exec function');
793
+ }
794
+ // Optional properties --------------------------------------------
795
+ if ('enabled' in action && typeof action.enabled !== 'function') {
796
+ throw new Error('Invalid enabled function');
797
+ }
798
+ if ('execBatch' in action && typeof action.execBatch !== 'function') {
799
+ throw new Error('Invalid execBatch function');
800
+ }
801
+ if ('order' in action && typeof action.order !== 'number') {
802
+ throw new Error('Invalid order');
803
+ }
804
+ if ('default' in action && typeof action.default !== 'boolean') {
805
+ throw new Error('Invalid default');
806
+ }
807
+ if ('inline' in action && typeof action.inline !== 'function') {
808
+ throw new Error('Invalid inline function');
809
+ }
810
+ if ('renderInline' in action && typeof action.renderInline !== 'function') {
811
+ throw new Error('Invalid renderInline function');
812
+ }
813
+ };
814
+ return FileAction;
815
+ }());
816
+ var registerFileAction = function (action) {
817
+ if (typeof window._nc_fileactions === 'undefined') {
818
+ window._nc_fileactions = [];
819
+ logger.debug('FileActions initialized');
820
+ }
821
+ // Check duplicates
822
+ if (window._nc_fileactions.find(function (search) { return search.id === action.id; })) {
823
+ logger.error("FileAction ".concat(action.id, " already registered"), { action: action });
824
+ return;
825
+ }
826
+ window._nc_fileactions.push(action);
827
+ };
828
+ var getFileActions = function () {
829
+ return window._nc_fileactions || [];
830
+ };
831
+
832
+ /**
833
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
834
+ *
835
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
836
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
837
+ *
838
+ * @license AGPL-3.0-or-later
839
+ *
840
+ * This program is free software: you can redistribute it and/or modify
841
+ * it under the terms of the GNU Affero General Public License as
842
+ * published by the Free Software Foundation, either version 3 of the
843
+ * License, or (at your option) any later version.
844
+ *
845
+ * This program is distributed in the hope that it will be useful,
846
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
847
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
848
+ * GNU Affero General Public License for more details.
849
+ *
850
+ * You should have received a copy of the GNU Affero General Public License
851
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
852
+ *
853
+ */
854
+ /**
855
+ * Add a new menu entry to the upload manager menu
856
+ */
857
+ var addNewFileMenuEntry = function (entry) {
858
+ var newFileMenu = getNewFileMenu();
859
+ return newFileMenu.registerEntry(entry);
860
+ };
861
+ /**
862
+ * Remove a previously registered entry from the upload menu
863
+ */
864
+ var removeNewFileMenuEntry = function (entry) {
865
+ var newFileMenu = getNewFileMenu();
866
+ return newFileMenu.unregisterEntry(entry);
867
+ };
868
+ /**
869
+ * Get the list of registered entries from the upload menu
870
+ *
871
+ * @param {FileInfo} context the creation context. Usually the current folder FileInfo
872
+ */
873
+ var getNewFileMenuEntries = function (context) {
874
+ var newFileMenu = getNewFileMenu();
875
+ return newFileMenu.getEntries(context);
876
+ };
877
+
878
+ exports.File = File;
879
+ exports.FileAction = FileAction;
880
+ exports.Folder = Folder;
881
+ exports.Node = Node;
882
+ exports.addNewFileMenuEntry = addNewFileMenuEntry;
883
+ exports.formatFileSize = formatFileSize;
884
+ exports.getFileActions = getFileActions;
885
+ exports.getNewFileMenuEntries = getNewFileMenuEntries;
886
+ exports.parseWebdavPermissions = parseWebdavPermissions;
887
+ exports.registerFileAction = registerFileAction;
888
+ exports.removeNewFileMenuEntry = removeNewFileMenuEntry;
889
+ //# sourceMappingURL=index.js.map