@nextcloud/files 3.9.2 → 3.10.1

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.cjs CHANGED
@@ -1,17 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const logger$1 = require("@nextcloud/logger");
4
- const auth = require("@nextcloud/auth");
5
- const path = require("path");
6
- const paths = require("@nextcloud/paths");
7
- const router = require("@nextcloud/router");
8
- const cancelablePromise = require("cancelable-promise");
9
- const webdav = require("webdav");
10
- const _public = require("@nextcloud/sharing/public");
3
+ const dav = require("./chunks/dav-CtqjqS4O.cjs");
11
4
  const capabilities = require("@nextcloud/capabilities");
5
+ const path = require("path");
12
6
  const l10n = require("@nextcloud/l10n");
13
7
  const typescriptEventTarget = require("typescript-event-target");
14
- const logger = logger$1.getLoggerBuilder().setApp("@nextcloud/files").detectUser().build();
15
8
  var NewMenuEntryCategory = /* @__PURE__ */ ((NewMenuEntryCategory2) => {
16
9
  NewMenuEntryCategory2[NewMenuEntryCategory2["UploadFromDevice"] = 0] = "UploadFromDevice";
17
10
  NewMenuEntryCategory2[NewMenuEntryCategory2["CreateNew"] = 1] = "CreateNew";
@@ -28,7 +21,7 @@ class NewFileMenu {
28
21
  unregisterEntry(entry) {
29
22
  const entryIndex = typeof entry === "string" ? this.getEntryIndex(entry) : this.getEntryIndex(entry.id);
30
23
  if (entryIndex === -1) {
31
- logger.warn("Entry not found, nothing removed", { entry, entries: this.getEntries() });
24
+ dav.logger.warn("Entry not found, nothing removed", { entry, entries: this.getEntries() });
32
25
  return;
33
26
  }
34
27
  this._entries.splice(entryIndex, 1);
@@ -74,7 +67,7 @@ class NewFileMenu {
74
67
  const getNewFileMenu = function() {
75
68
  if (typeof window._nc_newfilemenu === "undefined") {
76
69
  window._nc_newfilemenu = new NewFileMenu();
77
- logger.debug("NewFileMenu initialized");
70
+ dav.logger.debug("NewFileMenu initialized");
78
71
  }
79
72
  return window._nc_newfilemenu;
80
73
  };
@@ -119,6 +112,9 @@ class FileAction {
119
112
  get default() {
120
113
  return this._action.default;
121
114
  }
115
+ get destructive() {
116
+ return this._action.destructive;
117
+ }
122
118
  get inline() {
123
119
  return this._action.inline;
124
120
  }
@@ -150,6 +146,9 @@ class FileAction {
150
146
  if ("order" in action && typeof action.order !== "number") {
151
147
  throw new Error("Invalid order");
152
148
  }
149
+ if (action.destructive !== void 0 && typeof action.destructive !== "boolean") {
150
+ throw new Error("Invalid destructive flag");
151
+ }
153
152
  if ("parent" in action && typeof action.parent !== "string") {
154
153
  throw new Error("Invalid parent");
155
154
  }
@@ -167,10 +166,10 @@ class FileAction {
167
166
  const registerFileAction = function(action) {
168
167
  if (typeof window._nc_fileactions === "undefined") {
169
168
  window._nc_fileactions = [];
170
- logger.debug("FileActions initialized");
169
+ dav.logger.debug("FileActions initialized");
171
170
  }
172
171
  if (window._nc_fileactions.find((search) => search.id === action.id)) {
173
- logger.error(`FileAction ${action.id} already registered`, { action });
172
+ dav.logger.error(`FileAction ${action.id} already registered`, { action });
174
173
  return;
175
174
  }
176
175
  window._nc_fileactions.push(action);
@@ -178,10 +177,71 @@ const registerFileAction = function(action) {
178
177
  const getFileActions = function() {
179
178
  if (typeof window._nc_fileactions === "undefined") {
180
179
  window._nc_fileactions = [];
181
- logger.debug("FileActions initialized");
180
+ dav.logger.debug("FileActions initialized");
182
181
  }
183
182
  return window._nc_fileactions;
184
183
  };
184
+ class FileListAction {
185
+ _action;
186
+ constructor(action) {
187
+ this.validateAction(action);
188
+ this._action = action;
189
+ }
190
+ get id() {
191
+ return this._action.id;
192
+ }
193
+ get displayName() {
194
+ return this._action.displayName;
195
+ }
196
+ get iconSvgInline() {
197
+ return this._action.iconSvgInline;
198
+ }
199
+ get order() {
200
+ return this._action.order;
201
+ }
202
+ get enabled() {
203
+ return this._action.enabled;
204
+ }
205
+ get exec() {
206
+ return this._action.exec;
207
+ }
208
+ validateAction(action) {
209
+ if (!action.id || typeof action.id !== "string") {
210
+ throw new Error("Invalid id");
211
+ }
212
+ if (!action.displayName || typeof action.displayName !== "function") {
213
+ throw new Error("Invalid displayName function");
214
+ }
215
+ if ("iconSvgInline" in action && typeof action.iconSvgInline !== "function") {
216
+ throw new Error("Invalid iconSvgInline function");
217
+ }
218
+ if ("order" in action && typeof action.order !== "number") {
219
+ throw new Error("Invalid order");
220
+ }
221
+ if ("enabled" in action && typeof action.enabled !== "function") {
222
+ throw new Error("Invalid enabled function");
223
+ }
224
+ if (!action.exec || typeof action.exec !== "function") {
225
+ throw new Error("Invalid exec function");
226
+ }
227
+ }
228
+ }
229
+ const registerFileListAction = (action) => {
230
+ if (typeof window._nc_filelistactions === "undefined") {
231
+ window._nc_filelistactions = [];
232
+ }
233
+ if (window._nc_filelistactions.find((listAction) => listAction.id === action.id)) {
234
+ dav.logger.error(`FileListAction with id "${action.id}" is already registered`, { action });
235
+ return;
236
+ }
237
+ window._nc_filelistactions.push(action);
238
+ };
239
+ const getFileListActions = () => {
240
+ if (typeof window._nc_filelistactions === "undefined") {
241
+ window._nc_filelistactions = [];
242
+ }
243
+ return window._nc_filelistactions;
244
+ };
185
245
  class Header {
186
246
  _header;
187
247
  constructor(header) {
@@ -224,10 +284,10 @@ class Header {
224
284
  const registerFileListHeaders = function(header) {
225
285
  if (typeof window._nc_filelistheader === "undefined") {
226
286
  window._nc_filelistheader = [];
227
- logger.debug("FileListHeaders initialized");
287
+ dav.logger.debug("FileListHeaders initialized");
228
288
  }
229
289
  if (window._nc_filelistheader.find((search) => search.id === header.id)) {
230
- logger.error(`Header ${header.id} already registered`, { header });
290
+ dav.logger.error(`Header ${header.id} already registered`, { header });
231
291
  return;
232
292
  }
233
293
  window._nc_filelistheader.push(header);
@@ -235,659 +295,10 @@ const registerFileListHeaders = function(header) {
235
295
  const getFileListHeaders = function() {
236
296
  if (typeof window._nc_filelistheader === "undefined") {
237
297
  window._nc_filelistheader = [];
238
- logger.debug("FileListHeaders initialized");
298
+ dav.logger.debug("FileListHeaders initialized");
239
299
  }
240
300
  return window._nc_filelistheader;
241
301
  };
242
- var Permission = /* @__PURE__ */ ((Permission2) => {
243
- Permission2[Permission2["NONE"] = 0] = "NONE";
244
- Permission2[Permission2["CREATE"] = 4] = "CREATE";
245
- Permission2[Permission2["READ"] = 1] = "READ";
246
- Permission2[Permission2["UPDATE"] = 2] = "UPDATE";
247
- Permission2[Permission2["DELETE"] = 8] = "DELETE";
248
- Permission2[Permission2["SHARE"] = 16] = "SHARE";
249
- Permission2[Permission2["ALL"] = 31] = "ALL";
250
- return Permission2;
251
- })(Permission || {});
252
- const defaultDavProperties = [
253
- "d:getcontentlength",
254
- "d:getcontenttype",
255
- "d:getetag",
256
- "d:getlastmodified",
257
- "d:creationdate",
258
- "d:displayname",
259
- "d:quota-available-bytes",
260
- "d:resourcetype",
261
- "nc:has-preview",
262
- "nc:is-encrypted",
263
- "nc:mount-type",
264
- "oc:comments-unread",
265
- "oc:favorite",
266
- "oc:fileid",
267
- "oc:owner-display-name",
268
- "oc:owner-id",
269
- "oc:permissions",
270
- "oc:size"
271
- ];
272
- const defaultDavNamespaces = {
273
- d: "DAV:",
274
- nc: "http://nextcloud.org/ns",
275
- oc: "http://owncloud.org/ns",
276
- ocs: "http://open-collaboration-services.org/ns"
277
- };
278
- const registerDavProperty = function(prop, namespace = { nc: "http://nextcloud.org/ns" }) {
279
- if (typeof window._nc_dav_properties === "undefined") {
280
- window._nc_dav_properties = [...defaultDavProperties];
281
- window._nc_dav_namespaces = { ...defaultDavNamespaces };
282
- }
283
- const namespaces = { ...window._nc_dav_namespaces, ...namespace };
284
- if (window._nc_dav_properties.find((search) => search === prop)) {
285
- logger.warn(`${prop} already registered`, { prop });
286
- return false;
287
- }
288
- if (prop.startsWith("<") || prop.split(":").length !== 2) {
289
- logger.error(`${prop} is not valid. See example: 'oc:fileid'`, { prop });
290
- return false;
291
- }
292
- const ns = prop.split(":")[0];
293
- if (!namespaces[ns]) {
294
- logger.error(`${prop} namespace unknown`, { prop, namespaces });
295
- return false;
296
- }
297
- window._nc_dav_properties.push(prop);
298
- window._nc_dav_namespaces = namespaces;
299
- return true;
300
- };
301
- const getDavProperties = function() {
302
- if (typeof window._nc_dav_properties === "undefined") {
303
- window._nc_dav_properties = [...defaultDavProperties];
304
- }
305
- return window._nc_dav_properties.map((prop) => `<${prop} />`).join(" ");
306
- };
307
- const getDavNameSpaces = function() {
308
- if (typeof window._nc_dav_namespaces === "undefined") {
309
- window._nc_dav_namespaces = { ...defaultDavNamespaces };
310
- }
311
- return Object.keys(window._nc_dav_namespaces).map((ns) => `xmlns:${ns}="${window._nc_dav_namespaces?.[ns]}"`).join(" ");
312
- };
313
- const davGetDefaultPropfind = function() {
314
- return `<?xml version="1.0"?>
315
- <d:propfind ${getDavNameSpaces()}>
316
- <d:prop>
317
- ${getDavProperties()}
318
- </d:prop>
319
- </d:propfind>`;
320
- };
321
- const davGetFavoritesReport = function() {
322
- return `<?xml version="1.0"?>
323
- <oc:filter-files ${getDavNameSpaces()}>
324
- <d:prop>
325
- ${getDavProperties()}
326
- </d:prop>
327
- <oc:filter-rules>
328
- <oc:favorite>1</oc:favorite>
329
- </oc:filter-rules>
330
- </oc:filter-files>`;
331
- };
332
- const davGetRecentSearch = function(lastModified) {
333
- return `<?xml version="1.0" encoding="UTF-8"?>
334
- <d:searchrequest ${getDavNameSpaces()}
335
- xmlns:ns="https://github.com/icewind1991/SearchDAV/ns">
336
- <d:basicsearch>
337
- <d:select>
338
- <d:prop>
339
- ${getDavProperties()}
340
- </d:prop>
341
- </d:select>
342
- <d:from>
343
- <d:scope>
344
- <d:href>/files/${auth.getCurrentUser()?.uid}/</d:href>
345
- <d:depth>infinity</d:depth>
346
- </d:scope>
347
- </d:from>
348
- <d:where>
349
- <d:and>
350
- <d:or>
351
- <d:not>
352
- <d:eq>
353
- <d:prop>
354
- <d:getcontenttype/>
355
- </d:prop>
356
- <d:literal>httpd/unix-directory</d:literal>
357
- </d:eq>
358
- </d:not>
359
- <d:eq>
360
- <d:prop>
361
- <oc:size/>
362
- </d:prop>
363
- <d:literal>0</d:literal>
364
- </d:eq>
365
- </d:or>
366
- <d:gt>
367
- <d:prop>
368
- <d:getlastmodified/>
369
- </d:prop>
370
- <d:literal>${lastModified}</d:literal>
371
- </d:gt>
372
- </d:and>
373
- </d:where>
374
- <d:orderby>
375
- <d:order>
376
- <d:prop>
377
- <d:getlastmodified/>
378
- </d:prop>
379
- <d:descending/>
380
- </d:order>
381
- </d:orderby>
382
- <d:limit>
383
- <d:nresults>100</d:nresults>
384
- <ns:firstresult>0</ns:firstresult>
385
- </d:limit>
386
- </d:basicsearch>
387
- </d:searchrequest>`;
388
- };
389
- const davParsePermissions = function(permString = "") {
390
- let permissions = Permission.NONE;
391
- if (!permString) {
392
- return permissions;
393
- }
394
- if (permString.includes("C") || permString.includes("K")) {
395
- permissions |= Permission.CREATE;
396
- }
397
- if (permString.includes("G")) {
398
- permissions |= Permission.READ;
399
- }
400
- if (permString.includes("W") || permString.includes("N") || permString.includes("V")) {
401
- permissions |= Permission.UPDATE;
402
- }
403
- if (permString.includes("D")) {
404
- permissions |= Permission.DELETE;
405
- }
406
- if (permString.includes("R")) {
407
- permissions |= Permission.SHARE;
408
- }
409
- return permissions;
410
- };
411
- var FileType = /* @__PURE__ */ ((FileType2) => {
412
- FileType2["Folder"] = "folder";
413
- FileType2["File"] = "file";
414
- return FileType2;
415
- })(FileType || {});
416
- const isDavRessource = function(source, davService) {
417
- return source.match(davService) !== null;
418
- };
419
- const validateData = (data, davService) => {
420
- if (data.id && typeof data.id !== "number") {
421
- throw new Error("Invalid id type of value");
422
- }
423
- if (!data.source) {
424
- throw new Error("Missing mandatory source");
425
- }
426
- try {
427
- new URL(data.source);
428
- } catch (e) {
429
- throw new Error("Invalid source format, source must be a valid URL");
430
- }
431
- if (!data.source.startsWith("http")) {
432
- throw new Error("Invalid source format, only http(s) is supported");
433
- }
434
- if (data.displayname && typeof data.displayname !== "string") {
435
- throw new Error("Invalid displayname type");
436
- }
437
- if (data.mtime && !(data.mtime instanceof Date)) {
438
- throw new Error("Invalid mtime type");
439
- }
440
- if (data.crtime && !(data.crtime instanceof Date)) {
441
- throw new Error("Invalid crtime type");
442
- }
443
- if (!data.mime || typeof data.mime !== "string" || !data.mime.match(/^[-\w.]+\/[-+\w.]+$/gi)) {
444
- throw new Error("Missing or invalid mandatory mime");
445
- }
446
- if ("size" in data && typeof data.size !== "number" && data.size !== void 0) {
447
- throw new Error("Invalid size type");
448
- }
449
- if ("permissions" in data && data.permissions !== void 0 && !(typeof data.permissions === "number" && data.permissions >= Permission.NONE && data.permissions <= Permission.ALL)) {
450
- throw new Error("Invalid permissions");
451
- }
452
- if (data.owner && data.owner !== null && typeof data.owner !== "string") {
453
- throw new Error("Invalid owner type");
454
- }
455
- if (data.attributes && typeof data.attributes !== "object") {
456
- throw new Error("Invalid attributes type");
457
- }
458
- if (data.root && typeof data.root !== "string") {
459
- throw new Error("Invalid root type");
460
- }
461
- if (data.root && !data.root.startsWith("/")) {
462
- throw new Error("Root must start with a leading slash");
463
- }
464
- if (data.root && !data.source.includes(data.root)) {
465
- throw new Error("Root must be part of the source");
466
- }
467
- if (data.root && isDavRessource(data.source, davService)) {
468
- const service = data.source.match(davService)[0];
469
- if (!data.source.includes(path.join(service, data.root))) {
470
- throw new Error("The root must be relative to the service. e.g /files/emma");
471
- }
472
- }
473
- if (data.status && !Object.values(NodeStatus).includes(data.status)) {
474
- throw new Error("Status must be a valid NodeStatus");
475
- }
476
- };
477
- var NodeStatus = /* @__PURE__ */ ((NodeStatus2) => {
478
- NodeStatus2["NEW"] = "new";
479
- NodeStatus2["FAILED"] = "failed";
480
- NodeStatus2["LOADING"] = "loading";
481
- NodeStatus2["LOCKED"] = "locked";
482
- return NodeStatus2;
483
- })(NodeStatus || {});
484
- class Node {
485
- _data;
486
- _attributes;
487
- _knownDavService = /(remote|public)\.php\/(web)?dav/i;
488
- readonlyAttributes = Object.entries(Object.getOwnPropertyDescriptors(Node.prototype)).filter((e) => typeof e[1].get === "function" && e[0] !== "__proto__").map((e) => e[0]);
489
- handler = {
490
- set: (target, prop, value) => {
491
- if (this.readonlyAttributes.includes(prop)) {
492
- return false;
493
- }
494
- return Reflect.set(target, prop, value);
495
- },
496
- deleteProperty: (target, prop) => {
497
- if (this.readonlyAttributes.includes(prop)) {
498
- return false;
499
- }
500
- return Reflect.deleteProperty(target, prop);
501
- },
502
- // TODO: This is deprecated and only needed for files v3
503
- get: (target, prop, receiver) => {
504
- if (this.readonlyAttributes.includes(prop)) {
505
- logger.warn(`Accessing "Node.attributes.${prop}" is deprecated, access it directly on the Node instance.`);
506
- return Reflect.get(this, prop);
507
- }
508
- return Reflect.get(target, prop, receiver);
509
- }
510
- };
511
- constructor(data, davService) {
512
- validateData(data, davService || this._knownDavService);
513
- this._data = {
514
- // TODO: Remove with next major release, this is just for compatibility
515
- displayname: data.attributes?.displayname,
516
- ...data,
517
- attributes: {}
518
- };
519
- this._attributes = new Proxy(this._data.attributes, this.handler);
520
- this.update(data.attributes ?? {});
521
- if (davService) {
522
- this._knownDavService = davService;
523
- }
524
- }
525
- /**
526
- * Get the source url to this object
527
- * There is no setter as the source is not meant to be changed manually.
528
- * You can use the rename or move method to change the source.
529
- */
530
- get source() {
531
- return this._data.source.replace(/\/$/i, "");
532
- }
533
- /**
534
- * Get the encoded source url to this object for requests purposes
535
- */
536
- get encodedSource() {
537
- const { origin } = new URL(this.source);
538
- return origin + paths.encodePath(this.source.slice(origin.length));
539
- }
540
- /**
541
- * Get this object name
542
- * There is no setter as the source is not meant to be changed manually.
543
- * You can use the rename or move method to change the source.
544
- */
545
- get basename() {
546
- return path.basename(this.source);
547
- }
548
- /**
549
- * The nodes displayname
550
- * By default the display name and the `basename` are identical,
551
- * but it is possible to have a different name. This happens
552
- * on the files app for example for shared folders.
553
- */
554
- get displayname() {
555
- return this._data.displayname || this.basename;
556
- }
557
- /**
558
- * Set the displayname
559
- */
560
- set displayname(displayname) {
561
- this._data.displayname = displayname;
562
- }
563
- /**
564
- * Get this object's extension
565
- * There is no setter as the source is not meant to be changed manually.
566
- * You can use the rename or move method to change the source.
567
- */
568
- get extension() {
569
- return path.extname(this.source);
570
- }
571
- /**
572
- * Get the directory path leading to this object
573
- * Will use the relative path to root if available
574
- *
575
- * There is no setter as the source is not meant to be changed manually.
576
- * You can use the rename or move method to change the source.
577
- */
578
- get dirname() {
579
- if (this.root) {
580
- let source = this.source;
581
- if (this.isDavRessource) {
582
- source = source.split(this._knownDavService).pop();
583
- }
584
- const firstMatch = source.indexOf(this.root);
585
- const root = this.root.replace(/\/$/, "");
586
- return path.dirname(source.slice(firstMatch + root.length) || "/");
587
- }
588
- const url = new URL(this.source);
589
- return path.dirname(url.pathname);
590
- }
591
- /**
592
- * Get the file mime
593
- * There is no setter as the mime is not meant to be changed
594
- */
595
- get mime() {
596
- return this._data.mime;
597
- }
598
- /**
599
- * Get the file modification time
600
- */
601
- get mtime() {
602
- return this._data.mtime;
603
- }
604
- /**
605
- * Set the file modification time
606
- */
607
- set mtime(mtime) {
608
- this._data.mtime = mtime;
609
- }
610
- /**
611
- * Get the file creation time
612
- * There is no setter as the creation time is not meant to be changed
613
- */
614
- get crtime() {
615
- return this._data.crtime;
616
- }
617
- /**
618
- * Get the file size
619
- */
620
- get size() {
621
- return this._data.size;
622
- }
623
- /**
624
- * Set the file size
625
- */
626
- set size(size) {
627
- this.updateMtime();
628
- this._data.size = size;
629
- }
630
- /**
631
- * Get the file attribute
632
- * This contains all additional attributes not provided by the Node class
633
- */
634
- get attributes() {
635
- return this._attributes;
636
- }
637
- /**
638
- * Get the file permissions
639
- */
640
- get permissions() {
641
- if (this.owner === null && !this.isDavRessource) {
642
- return Permission.READ;
643
- }
644
- return this._data.permissions !== void 0 ? this._data.permissions : Permission.NONE;
645
- }
646
- /**
647
- * Set the file permissions
648
- */
649
- set permissions(permissions) {
650
- this.updateMtime();
651
- this._data.permissions = permissions;
652
- }
653
- /**
654
- * Get the file owner
655
- * There is no setter as the owner is not meant to be changed
656
- */
657
- get owner() {
658
- if (!this.isDavRessource) {
659
- return null;
660
- }
661
- return this._data.owner;
662
- }
663
- /**
664
- * Is this a dav-related ressource ?
665
- */
666
- get isDavRessource() {
667
- return isDavRessource(this.source, this._knownDavService);
668
- }
669
- /**
670
- * Get the dav root of this object
671
- * There is no setter as the root is not meant to be changed
672
- */
673
- get root() {
674
- if (this._data.root) {
675
- return this._data.root.replace(/^(.+)\/$/, "$1");
676
- }
677
- if (this.isDavRessource) {
678
- const root = path.dirname(this.source);
679
- return root.split(this._knownDavService).pop() || null;
680
- }
681
- return null;
682
- }
683
- /**
684
- * Get the absolute path of this object relative to the root
685
- */
686
- get path() {
687
- if (this.root) {
688
- let source = this.source;
689
- if (this.isDavRessource) {
690
- source = source.split(this._knownDavService).pop();
691
- }
692
- const firstMatch = source.indexOf(this.root);
693
- const root = this.root.replace(/\/$/, "");
694
- return source.slice(firstMatch + root.length) || "/";
695
- }
696
- return (this.dirname + "/" + this.basename).replace(/\/\//g, "/");
697
- }
698
- /**
699
- * Get the node id if defined.
700
- * There is no setter as the fileid is not meant to be changed
701
- */
702
- get fileid() {
703
- return this._data?.id;
704
- }
705
- /**
706
- * Get the node status.
707
- */
708
- get status() {
709
- return this._data?.status;
710
- }
711
- /**
712
- * Set the node status.
713
- */
714
- set status(status) {
715
- this._data.status = status;
716
- }
717
- /**
718
- * Move the node to a new destination
719
- *
720
- * @param {string} destination the new source.
721
- * e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg
722
- */
723
- move(destination) {
724
- validateData({ ...this._data, source: destination }, this._knownDavService);
725
- const oldBasename = this.basename;
726
- this._data.source = destination;
727
- if (this.displayname === oldBasename && this.basename !== oldBasename) {
728
- this.displayname = this.basename;
729
- }
730
- this.updateMtime();
731
- }
732
- /**
733
- * Rename the node
734
- * This aliases the move method for easier usage
735
- *
736
- * @param basename The new name of the node
737
- */
738
- rename(basename2) {
739
- if (basename2.includes("/")) {
740
- throw new Error("Invalid basename");
741
- }
742
- this.move(path.dirname(this.source) + "/" + basename2);
743
- }
744
- /**
745
- * Update the mtime if exists
746
- */
747
- updateMtime() {
748
- if (this._data.mtime) {
749
- this._data.mtime = /* @__PURE__ */ new Date();
750
- }
751
- }
752
- /**
753
- * Update the attributes of the node
754
- * Warning, updating attributes will NOT automatically update the mtime.
755
- *
756
- * @param attributes The new attributes to update on the Node attributes
757
- */
758
- update(attributes) {
759
- for (const [name, value] of Object.entries(attributes)) {
760
- try {
761
- if (value === void 0) {
762
- delete this.attributes[name];
763
- } else {
764
- this.attributes[name] = value;
765
- }
766
- } catch (e) {
767
- if (e instanceof TypeError) {
768
- continue;
769
- }
770
- throw e;
771
- }
772
- }
773
- }
774
- }
775
- class File extends Node {
776
- get type() {
777
- return FileType.File;
778
- }
779
- }
780
- class Folder extends Node {
781
- constructor(data) {
782
- super({
783
- ...data,
784
- mime: "httpd/unix-directory"
785
- });
786
- }
787
- get type() {
788
- return FileType.Folder;
789
- }
790
- get extension() {
791
- return null;
792
- }
793
- get mime() {
794
- return "httpd/unix-directory";
795
- }
796
- }
797
- function davGetRootPath() {
798
- if (_public.isPublicShare()) {
799
- return `/files/${_public.getSharingToken()}`;
800
- }
801
- return `/files/${auth.getCurrentUser()?.uid}`;
802
- }
803
- const davRootPath = davGetRootPath();
804
- function davGetRemoteURL() {
805
- const url = router.generateRemoteUrl("dav");
806
- if (_public.isPublicShare()) {
807
- return url.replace("remote.php", "public.php");
808
- }
809
- return url;
810
- }
811
- const davRemoteURL = davGetRemoteURL();
812
- const davGetClient = function(remoteURL = davRemoteURL, headers = {}) {
813
- const client = webdav.createClient(remoteURL, { headers });
814
- function setHeaders(token) {
815
- client.setHeaders({
816
- ...headers,
817
- // Add this so the server knows it is an request from the browser
818
- "X-Requested-With": "XMLHttpRequest",
819
- // Inject user auth
820
- requesttoken: token ?? ""
821
- });
822
- }
823
- auth.onRequestTokenUpdate(setHeaders);
824
- setHeaders(auth.getRequestToken());
825
- const patcher = webdav.getPatcher();
826
- patcher.patch("fetch", (url, options) => {
827
- const headers2 = options.headers;
828
- if (headers2?.method) {
829
- options.method = headers2.method;
830
- delete headers2.method;
831
- }
832
- return fetch(url, options);
833
- });
834
- return client;
835
- };
836
- const getFavoriteNodes = (davClient, path2 = "/", davRoot = davRootPath) => {
837
- const controller = new AbortController();
838
- return new cancelablePromise.CancelablePromise(async (resolve, reject, onCancel) => {
839
- onCancel(() => controller.abort());
840
- try {
841
- const contentsResponse = await davClient.getDirectoryContents(`${davRoot}${path2}`, {
842
- signal: controller.signal,
843
- details: true,
844
- data: davGetFavoritesReport(),
845
- headers: {
846
- // see davGetClient for patched webdav client
847
- method: "REPORT"
848
- },
849
- includeSelf: true
850
- });
851
- const nodes = contentsResponse.data.filter((node) => node.filename !== path2).map((result) => davResultToNode(result, davRoot));
852
- resolve(nodes);
853
- } catch (error) {
854
- reject(error);
855
- }
856
- });
857
- };
858
- const davResultToNode = function(node, filesRoot = davRootPath, remoteURL = davRemoteURL) {
859
- let userId = auth.getCurrentUser()?.uid;
860
- if (_public.isPublicShare()) {
861
- userId = userId ?? "anonymous";
862
- } else if (!userId) {
863
- throw new Error("No user id found");
864
- }
865
- const props = node.props;
866
- const permissions = davParsePermissions(props?.permissions);
867
- const owner = String(props?.["owner-id"] || userId);
868
- const id = props.fileid || 0;
869
- const nodeData = {
870
- id,
871
- source: `${remoteURL}${node.filename}`,
872
- mtime: new Date(Date.parse(node.lastmod)),
873
- mime: node.mime || "application/octet-stream",
874
- // Manually cast to work around for https://github.com/perry-mitchell/webdav-client/pull/380
875
- displayname: props.displayname !== void 0 ? String(props.displayname) : void 0,
876
- size: props?.size || Number.parseInt(props.getcontentlength || "0"),
877
- // The fileid is set to -1 for failed requests
878
- status: id < 0 ? NodeStatus.FAILED : void 0,
879
- permissions,
880
- owner,
881
- root: filesRoot,
882
- attributes: {
883
- ...node,
884
- ...props,
885
- hasPreview: props?.["has-preview"]
886
- }
887
- };
888
- delete nodeData.attributes?.props;
889
- return node.type === "file" ? new File(nodeData) : new Folder(nodeData);
890
- };
891
302
  var InvalidFilenameErrorReason = /* @__PURE__ */ ((InvalidFilenameErrorReason2) => {
892
303
  InvalidFilenameErrorReason2["ReservedName"] = "reserved name";
893
304
  InvalidFilenameErrorReason2["Character"] = "character";
@@ -1074,7 +485,7 @@ function sortNodes(nodes, options = {}) {
1074
485
  // 3: Use sorting mode if NOT basename (to be able to use display name too)
1075
486
  ...sortingOptions.sortingMode !== "basename" ? [(v) => v[sortingOptions.sortingMode]] : [],
1076
487
  // 4: Use display name if available, fallback to name
1077
- (v) => basename(v.attributes?.displayname || v.basename),
488
+ (v) => basename(v.displayname || v.attributes?.displayname || v.basename),
1078
489
  // 5: Finally, use basename if all previous sorting methods failed
1079
490
  (v) => v.basename
1080
491
  ];
@@ -1146,7 +557,7 @@ class Navigation extends typescriptEventTarget.TypedEventTarget {
1146
557
  const getNavigation = function() {
1147
558
  if (typeof window._nc_navigation === "undefined") {
1148
559
  window._nc_navigation = new Navigation();
1149
- logger.debug("Navigation service initialized");
560
+ dav.logger.debug("Navigation service initialized");
1150
561
  }
1151
562
  return window._nc_navigation;
1152
563
  };
@@ -2891,8 +2302,8 @@ const isValidView = function(view) {
2891
2302
  if (!view.name || typeof view.name !== "string") {
2892
2303
  throw new Error("View name is required and must be a string");
2893
2304
  }
2894
- if (view.columns && view.columns.length > 0 && (!view.caption || typeof view.caption !== "string")) {
2895
- throw new Error("View caption is required for top-level views and must be a string");
2305
+ if ("caption" in view && typeof view.caption !== "string") {
2306
+ throw new Error("View caption must be a string");
2896
2307
  }
2897
2308
  if (!view.getContents || typeof view.getContents !== "function") {
2898
2309
  throw new Error("View getContents is required and must be a function");
@@ -3475,41 +2886,44 @@ const getNewFileMenuEntries = function(context) {
3475
2886
  return a.displayName.localeCompare(b.displayName, void 0, { numeric: true, sensitivity: "base" });
3476
2887
  });
3477
2888
  };
2889
+ exports.File = dav.File;
2890
+ exports.FileType = dav.FileType;
2891
+ exports.Folder = dav.Folder;
2892
+ exports.Node = dav.Node;
2893
+ exports.NodeStatus = dav.NodeStatus;
2894
+ exports.Permission = dav.Permission;
2895
+ exports.davGetClient = dav.getClient;
2896
+ exports.davGetDefaultPropfind = dav.getDefaultPropfind;
2897
+ exports.davGetFavoritesReport = dav.getFavoritesReport;
2898
+ exports.davGetRecentSearch = dav.getRecentSearch;
2899
+ exports.davGetRemoteURL = dav.getRemoteURL;
2900
+ exports.davGetRootPath = dav.getRootPath;
2901
+ exports.davParsePermissions = dav.parsePermissions;
2902
+ exports.davRemoteURL = dav.defaultRemoteURL;
2903
+ exports.davResultToNode = dav.resultToNode;
2904
+ exports.davRootPath = dav.defaultRootPath;
2905
+ exports.defaultDavNamespaces = dav.defaultDavNamespaces;
2906
+ exports.defaultDavProperties = dav.defaultDavProperties;
2907
+ exports.getDavNameSpaces = dav.getDavNameSpaces;
2908
+ exports.getDavProperties = dav.getDavProperties;
2909
+ exports.getFavoriteNodes = dav.getFavoriteNodes;
2910
+ exports.registerDavProperty = dav.registerDavProperty;
3478
2911
  exports.Column = Column;
3479
2912
  exports.DefaultType = DefaultType;
3480
- exports.File = File;
3481
2913
  exports.FileAction = FileAction;
2914
+ exports.FileListAction = FileListAction;
3482
2915
  exports.FileListFilter = FileListFilter;
3483
- exports.FileType = FileType;
3484
2916
  exports.FilesSortingMode = FilesSortingMode;
3485
- exports.Folder = Folder;
3486
2917
  exports.Header = Header;
3487
2918
  exports.InvalidFilenameError = InvalidFilenameError;
3488
2919
  exports.InvalidFilenameErrorReason = InvalidFilenameErrorReason;
3489
2920
  exports.Navigation = Navigation;
3490
2921
  exports.NewMenuEntryCategory = NewMenuEntryCategory;
3491
- exports.Node = Node;
3492
- exports.NodeStatus = NodeStatus;
3493
- exports.Permission = Permission;
3494
2922
  exports.View = View;
3495
2923
  exports.addNewFileMenuEntry = addNewFileMenuEntry;
3496
- exports.davGetClient = davGetClient;
3497
- exports.davGetDefaultPropfind = davGetDefaultPropfind;
3498
- exports.davGetFavoritesReport = davGetFavoritesReport;
3499
- exports.davGetRecentSearch = davGetRecentSearch;
3500
- exports.davGetRemoteURL = davGetRemoteURL;
3501
- exports.davGetRootPath = davGetRootPath;
3502
- exports.davParsePermissions = davParsePermissions;
3503
- exports.davRemoteURL = davRemoteURL;
3504
- exports.davResultToNode = davResultToNode;
3505
- exports.davRootPath = davRootPath;
3506
- exports.defaultDavNamespaces = defaultDavNamespaces;
3507
- exports.defaultDavProperties = defaultDavProperties;
3508
2924
  exports.formatFileSize = formatFileSize;
3509
- exports.getDavNameSpaces = getDavNameSpaces;
3510
- exports.getDavProperties = getDavProperties;
3511
- exports.getFavoriteNodes = getFavoriteNodes;
3512
2925
  exports.getFileActions = getFileActions;
2926
+ exports.getFileListActions = getFileListActions;
3513
2927
  exports.getFileListFilters = getFileListFilters;
3514
2928
  exports.getFileListHeaders = getFileListHeaders;
3515
2929
  exports.getNavigation = getNavigation;
@@ -3518,8 +2932,8 @@ exports.getUniqueName = getUniqueName;
3518
2932
  exports.isFilenameValid = isFilenameValid;
3519
2933
  exports.orderBy = orderBy;
3520
2934
  exports.parseFileSize = parseFileSize;
3521
- exports.registerDavProperty = registerDavProperty;
3522
2935
  exports.registerFileAction = registerFileAction;
2936
+ exports.registerFileListAction = registerFileListAction;
3523
2937
  exports.registerFileListFilter = registerFileListFilter;
3524
2938
  exports.registerFileListHeaders = registerFileListHeaders;
3525
2939
  exports.removeNewFileMenuEntry = removeNewFileMenuEntry;