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