@nextcloud/files 3.0.0-beta.8 → 3.0.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/index.js DELETED
@@ -1,841 +0,0 @@
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
- /**
338
- * Validate Node construct data
339
- */
340
- var validateData = function (data) {
341
- if ('id' in data && (typeof data.id !== 'number' || data.id < 0)) {
342
- throw new Error('Invalid id type of value');
343
- }
344
- if (!data.source) {
345
- throw new Error('Missing mandatory source');
346
- }
347
- if (!data.source.startsWith('http')) {
348
- throw new Error('Invalid source format');
349
- }
350
- if ('mtime' in data && !(data.mtime instanceof Date)) {
351
- throw new Error('Invalid mtime type');
352
- }
353
- if ('crtime' in data && !(data.crtime instanceof Date)) {
354
- throw new Error('Invalid crtime type');
355
- }
356
- if (!data.mime || typeof data.mime !== 'string'
357
- || !data.mime.match(/^[-\w.]+\/[-+\w.]+$/gi)) {
358
- throw new Error('Missing or invalid mandatory mime');
359
- }
360
- if ('size' in data && typeof data.size !== 'number') {
361
- throw new Error('Invalid size type');
362
- }
363
- if ('permissions' in data && !(typeof data.permissions === 'number'
364
- && data.permissions >= exports.Permission.NONE
365
- && data.permissions <= exports.Permission.ALL)) {
366
- throw new Error('Invalid permissions');
367
- }
368
- if ('owner' in data
369
- && data.owner !== null
370
- && typeof data.owner !== 'string') {
371
- throw new Error('Invalid owner type');
372
- }
373
- if ('attributes' in data && typeof data.attributes !== 'object') {
374
- throw new Error('Invalid attributes format');
375
- }
376
- if ('root' in data && typeof data.root !== 'string') {
377
- throw new Error('Invalid root format');
378
- }
379
- if (data.root && !data.root.startsWith('/')) {
380
- throw new Error('Root must start with a leading slash');
381
- }
382
- };
383
-
384
- /**
385
- * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
386
- *
387
- * @author John Molakvoæ <skjnldsv@protonmail.com>
388
- *
389
- * @license AGPL-3.0-or-later
390
- *
391
- * This program is free software: you can redistribute it and/or modify
392
- * it under the terms of the GNU Affero General Public License as
393
- * published by the Free Software Foundation, either version 3 of the
394
- * License, or (at your option) any later version.
395
- *
396
- * This program is distributed in the hope that it will be useful,
397
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
398
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
399
- * GNU Affero General Public License for more details.
400
- *
401
- * You should have received a copy of the GNU Affero General Public License
402
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
403
- *
404
- */
405
- var Node = /** @class */ (function () {
406
- function Node(data, davService) {
407
- this._knownDavService = /(remote|public)\.php\/(web)?dav/i;
408
- // Validate data
409
- validateData(data);
410
- this._data = data;
411
- this._attributes = data.attributes || {};
412
- delete this._data.attributes;
413
- if (davService) {
414
- this._knownDavService = davService;
415
- }
416
- }
417
- Object.defineProperty(Node.prototype, "source", {
418
- /**
419
- * Get the source url to this object
420
- */
421
- get: function () {
422
- // strip any ending slash
423
- return this._data.source.replace(/\/$/i, '');
424
- },
425
- enumerable: false,
426
- configurable: true
427
- });
428
- Object.defineProperty(Node.prototype, "basename", {
429
- /**
430
- * Get this object name
431
- */
432
- get: function () {
433
- return path.basename(this.source);
434
- },
435
- enumerable: false,
436
- configurable: true
437
- });
438
- Object.defineProperty(Node.prototype, "extension", {
439
- /**
440
- * Get this object's extension
441
- */
442
- get: function () {
443
- return path.extname(this.source);
444
- },
445
- enumerable: false,
446
- configurable: true
447
- });
448
- Object.defineProperty(Node.prototype, "dirname", {
449
- /**
450
- * Get the directory path leading to this object
451
- * Will use the relative path to root if available
452
- */
453
- get: function () {
454
- if (this.root) {
455
- return path.dirname(this.source.split(this.root).pop() || '/');
456
- }
457
- return path.dirname(this.source);
458
- },
459
- enumerable: false,
460
- configurable: true
461
- });
462
- Object.defineProperty(Node.prototype, "mime", {
463
- /**
464
- * Get the file mime
465
- */
466
- get: function () {
467
- return this._data.mime;
468
- },
469
- enumerable: false,
470
- configurable: true
471
- });
472
- Object.defineProperty(Node.prototype, "size", {
473
- /**
474
- * Get the file size
475
- */
476
- get: function () {
477
- return this._data.size;
478
- },
479
- enumerable: false,
480
- configurable: true
481
- });
482
- Object.defineProperty(Node.prototype, "attributes", {
483
- /**
484
- * Get the file attribute
485
- */
486
- get: function () {
487
- return this._attributes;
488
- },
489
- enumerable: false,
490
- configurable: true
491
- });
492
- Object.defineProperty(Node.prototype, "permissions", {
493
- /**
494
- * Get the file permissions
495
- */
496
- get: function () {
497
- // If this is not a dav ressource, we can only read it
498
- if (this.owner === null && !this.isDavRessource) {
499
- return exports.Permission.READ;
500
- }
501
- return this._data.permissions || exports.Permission.READ;
502
- },
503
- enumerable: false,
504
- configurable: true
505
- });
506
- Object.defineProperty(Node.prototype, "owner", {
507
- /**
508
- * Get the file owner
509
- */
510
- get: function () {
511
- // Remote ressources have no owner
512
- if (!this.isDavRessource) {
513
- return null;
514
- }
515
- return this._data.owner;
516
- },
517
- enumerable: false,
518
- configurable: true
519
- });
520
- Object.defineProperty(Node.prototype, "isDavRessource", {
521
- /**
522
- * Is this a dav-related ressource ?
523
- */
524
- get: function () {
525
- return this.source.match(this._knownDavService) !== null;
526
- },
527
- enumerable: false,
528
- configurable: true
529
- });
530
- Object.defineProperty(Node.prototype, "root", {
531
- /**
532
- * Get the dav root of this object
533
- */
534
- get: function () {
535
- // If provided (recommended), use the root and strip away the ending slash
536
- if (this._data.root) {
537
- return this._data.root.replace(/^(.+)\/$/, '$1');
538
- }
539
- // Use the source to get the root from the dav service
540
- if (this.isDavRessource) {
541
- var root = path.dirname(this.source);
542
- return root.split(this._knownDavService).pop() || null;
543
- }
544
- return null;
545
- },
546
- enumerable: false,
547
- configurable: true
548
- });
549
- Object.defineProperty(Node.prototype, "path", {
550
- /**
551
- * Get the absolute path of this object relative to the root
552
- */
553
- get: function () {
554
- return (this.dirname + '/' + this.basename).replace(/\/\//g, '/');
555
- },
556
- enumerable: false,
557
- configurable: true
558
- });
559
- Object.defineProperty(Node.prototype, "fileid", {
560
- /**
561
- * Get the file id if defined in attributes
562
- */
563
- get: function () {
564
- var _a;
565
- return (_a = this.attributes) === null || _a === void 0 ? void 0 : _a.fileid;
566
- },
567
- enumerable: false,
568
- configurable: true
569
- });
570
- /**
571
- * Move the node to a new destination
572
- *
573
- * @param {string} destination the new source.
574
- * e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg
575
- */
576
- Node.prototype.move = function (destination) {
577
- this._data.source = destination;
578
- };
579
- /**
580
- * Rename the node
581
- * This aliases the move method for easier usage
582
- */
583
- Node.prototype.rename = function (basename) {
584
- if (basename.includes('/')) {
585
- throw new Error('Invalid basename');
586
- }
587
- this.move(path.dirname(this.source) + '/' + basename);
588
- };
589
- return Node;
590
- }());
591
-
592
- var File = /** @class */ (function (_super) {
593
- __extends(File, _super);
594
- function File() {
595
- return _super !== null && _super.apply(this, arguments) || this;
596
- }
597
- Object.defineProperty(File.prototype, "type", {
598
- get: function () {
599
- return exports.FileType.File;
600
- },
601
- enumerable: false,
602
- configurable: true
603
- });
604
- return File;
605
- }(Node));
606
-
607
- var Folder = /** @class */ (function (_super) {
608
- __extends(Folder, _super);
609
- function Folder(data) {
610
- // enforcing mimes
611
- return _super.call(this, __assign(__assign({}, data), { mime: 'httpd/unix-directory' })) || this;
612
- }
613
- Object.defineProperty(Folder.prototype, "type", {
614
- get: function () {
615
- return exports.FileType.Folder;
616
- },
617
- enumerable: false,
618
- configurable: true
619
- });
620
- Object.defineProperty(Folder.prototype, "extension", {
621
- get: function () {
622
- return null;
623
- },
624
- enumerable: false,
625
- configurable: true
626
- });
627
- Object.defineProperty(Folder.prototype, "mime", {
628
- get: function () {
629
- return 'httpd/unix-directory';
630
- },
631
- enumerable: false,
632
- configurable: true
633
- });
634
- return Folder;
635
- }(Node));
636
-
637
- /**
638
- * @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
639
- *
640
- * @author John Molakvoæ <skjnldsv@protonmail.com>
641
- *
642
- * @license AGPL-3.0-or-later
643
- *
644
- * This program is free software: you can redistribute it and/or modify
645
- * it under the terms of the GNU Affero General Public License as
646
- * published by the Free Software Foundation, either version 3 of the
647
- * License, or (at your option) any later version.
648
- *
649
- * This program is distributed in the hope that it will be useful,
650
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
651
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
652
- * GNU Affero General Public License for more details.
653
- *
654
- * You should have received a copy of the GNU Affero General Public License
655
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
656
- *
657
- */
658
- var FileAction = /** @class */ (function () {
659
- function FileAction(action) {
660
- this.validateAction(action);
661
- this._action = action;
662
- }
663
- Object.defineProperty(FileAction.prototype, "id", {
664
- get: function () {
665
- return this._action.id;
666
- },
667
- enumerable: false,
668
- configurable: true
669
- });
670
- Object.defineProperty(FileAction.prototype, "displayName", {
671
- get: function () {
672
- return this._action.displayName;
673
- },
674
- enumerable: false,
675
- configurable: true
676
- });
677
- Object.defineProperty(FileAction.prototype, "iconSvgInline", {
678
- get: function () {
679
- return this._action.iconSvgInline;
680
- },
681
- enumerable: false,
682
- configurable: true
683
- });
684
- Object.defineProperty(FileAction.prototype, "enabled", {
685
- get: function () {
686
- return this._action.enabled;
687
- },
688
- enumerable: false,
689
- configurable: true
690
- });
691
- Object.defineProperty(FileAction.prototype, "exec", {
692
- get: function () {
693
- return this._action.exec;
694
- },
695
- enumerable: false,
696
- configurable: true
697
- });
698
- Object.defineProperty(FileAction.prototype, "execBatch", {
699
- get: function () {
700
- return this._action.execBatch;
701
- },
702
- enumerable: false,
703
- configurable: true
704
- });
705
- Object.defineProperty(FileAction.prototype, "order", {
706
- get: function () {
707
- return this._action.order;
708
- },
709
- enumerable: false,
710
- configurable: true
711
- });
712
- Object.defineProperty(FileAction.prototype, "default", {
713
- get: function () {
714
- return this._action.default;
715
- },
716
- enumerable: false,
717
- configurable: true
718
- });
719
- Object.defineProperty(FileAction.prototype, "inline", {
720
- get: function () {
721
- return this._action.inline;
722
- },
723
- enumerable: false,
724
- configurable: true
725
- });
726
- Object.defineProperty(FileAction.prototype, "renderInline", {
727
- get: function () {
728
- return this._action.renderInline;
729
- },
730
- enumerable: false,
731
- configurable: true
732
- });
733
- FileAction.prototype.validateAction = function (action) {
734
- if (!action.id || typeof action.id !== 'string') {
735
- throw new Error('Invalid id');
736
- }
737
- if (!action.displayName || typeof action.displayName !== 'function') {
738
- throw new Error('Invalid displayName function');
739
- }
740
- if (!action.iconSvgInline || typeof action.iconSvgInline !== 'function') {
741
- throw new Error('Invalid iconSvgInline function');
742
- }
743
- if (!action.exec || typeof action.exec !== 'function') {
744
- throw new Error('Invalid exec function');
745
- }
746
- // Optional properties --------------------------------------------
747
- if ('enabled' in action && typeof action.enabled !== 'function') {
748
- throw new Error('Invalid enabled function');
749
- }
750
- if ('execBatch' in action && typeof action.execBatch !== 'function') {
751
- throw new Error('Invalid execBatch function');
752
- }
753
- if ('order' in action && typeof action.order !== 'number') {
754
- throw new Error('Invalid order');
755
- }
756
- if ('default' in action && typeof action.default !== 'boolean') {
757
- throw new Error('Invalid default');
758
- }
759
- if ('inline' in action && typeof action.inline !== 'function') {
760
- throw new Error('Invalid inline function');
761
- }
762
- if ('renderInline' in action && typeof action.renderInline !== 'function') {
763
- throw new Error('Invalid renderInline function');
764
- }
765
- };
766
- return FileAction;
767
- }());
768
- var registerFileAction = function (action) {
769
- if (typeof window._nc_fileactions === 'undefined') {
770
- window._nc_fileactions = [];
771
- logger.debug('FileActions initialized');
772
- }
773
- // Check duplicates
774
- if (window._nc_fileactions.find(function (search) { return search.id === action.id; })) {
775
- logger.error("FileAction ".concat(action.id, " already registered"), { action: action });
776
- return;
777
- }
778
- window._nc_fileactions.push(action);
779
- };
780
- var getFileActions = function () {
781
- return window._nc_fileactions || [];
782
- };
783
-
784
- /**
785
- * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
786
- *
787
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
788
- * @author John Molakvoæ <skjnldsv@protonmail.com>
789
- *
790
- * @license AGPL-3.0-or-later
791
- *
792
- * This program is free software: you can redistribute it and/or modify
793
- * it under the terms of the GNU Affero General Public License as
794
- * published by the Free Software Foundation, either version 3 of the
795
- * License, or (at your option) any later version.
796
- *
797
- * This program is distributed in the hope that it will be useful,
798
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
799
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
800
- * GNU Affero General Public License for more details.
801
- *
802
- * You should have received a copy of the GNU Affero General Public License
803
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
804
- *
805
- */
806
- /**
807
- * Add a new menu entry to the upload manager menu
808
- */
809
- var addNewFileMenuEntry = function (entry) {
810
- var newFileMenu = getNewFileMenu();
811
- return newFileMenu.registerEntry(entry);
812
- };
813
- /**
814
- * Remove a previously registered entry from the upload menu
815
- */
816
- var removeNewFileMenuEntry = function (entry) {
817
- var newFileMenu = getNewFileMenu();
818
- return newFileMenu.unregisterEntry(entry);
819
- };
820
- /**
821
- * Get the list of registered entries from the upload menu
822
- *
823
- * @param {FileInfo} context the creation context. Usually the current folder FileInfo
824
- */
825
- var getNewFileMenuEntries = function (context) {
826
- var newFileMenu = getNewFileMenu();
827
- return newFileMenu.getEntries(context);
828
- };
829
-
830
- exports.File = File;
831
- exports.FileAction = FileAction;
832
- exports.Folder = Folder;
833
- exports.Node = Node;
834
- exports.addNewFileMenuEntry = addNewFileMenuEntry;
835
- exports.formatFileSize = formatFileSize;
836
- exports.getFileActions = getFileActions;
837
- exports.getNewFileMenuEntries = getNewFileMenuEntries;
838
- exports.parseWebdavPermissions = parseWebdavPermissions;
839
- exports.registerFileAction = registerFileAction;
840
- exports.removeNewFileMenuEntry = removeNewFileMenuEntry;
841
- //# sourceMappingURL=index.js.map