@nextcloud/files 3.0.0-beta.11 → 3.0.0-beta.13

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