@nextcloud/files 3.5.0 → 3.5.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/dav/dav.d.ts CHANGED
@@ -2,12 +2,23 @@ import { FileStat, WebDAVClient } from 'webdav';
2
2
  import { Node } from '../files/node';
3
3
  import { CancelablePromise } from 'cancelable-promise';
4
4
 
5
+ /**
6
+ * Get the DAV root path for the current user or public share
7
+ */
8
+ export declare function davGetRootPath(): string;
5
9
  /**
6
10
  * The DAV root path for the current user
11
+ * This is a cached version of `davGetRemoteURL`
7
12
  */
8
13
  export declare const davRootPath: string;
14
+ /**
15
+ * Get the DAV remote URL used as base URL for the WebDAV client
16
+ * It also handles public shares
17
+ */
18
+ export declare function davGetRemoteURL(): string;
9
19
  /**
10
20
  * The DAV remote URL used as base URL for the WebDAV client
21
+ * This is a cached version of `davGetRemoteURL`
11
22
  */
12
23
  export declare const davRemoteURL: string;
13
24
  /**
package/dist/index.cjs CHANGED
@@ -1,21 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const auth = require("@nextcloud/auth");
4
3
  const logger$1 = require("@nextcloud/logger");
4
+ const auth = require("@nextcloud/auth");
5
5
  const path = require("path");
6
6
  const paths = require("@nextcloud/paths");
7
7
  const router = require("@nextcloud/router");
8
- const webdav = require("webdav");
9
8
  const cancelablePromise = require("cancelable-promise");
9
+ const webdav = require("webdav");
10
+ const _public = require("@nextcloud/sharing/public");
10
11
  const l10n = require("@nextcloud/l10n");
11
12
  const typescriptEventTarget = require("typescript-event-target");
12
- const getLogger = (user) => {
13
- if (user === null) {
14
- return logger$1.getLoggerBuilder().setApp("files").build();
15
- }
16
- return logger$1.getLoggerBuilder().setApp("files").setUid(user.uid).build();
17
- };
18
- const logger = getLogger(auth.getCurrentUser());
13
+ const logger = logger$1.getLoggerBuilder().setApp("@nextcloud/files").detectUser().build();
19
14
  var NewMenuEntryCategory = /* @__PURE__ */ ((NewMenuEntryCategory2) => {
20
15
  NewMenuEntryCategory2[NewMenuEntryCategory2["UploadFromDevice"] = 0] = "UploadFromDevice";
21
16
  NewMenuEntryCategory2[NewMenuEntryCategory2["CreateNew"] = 1] = "CreateNew";
@@ -258,6 +253,8 @@ const defaultDavProperties = [
258
253
  "d:getcontenttype",
259
254
  "d:getetag",
260
255
  "d:getlastmodified",
256
+ "d:creationdate",
257
+ "d:displayname",
261
258
  "d:quota-available-bytes",
262
259
  "d:resourcetype",
263
260
  "nc:has-preview",
@@ -410,6 +407,11 @@ const davParsePermissions = function(permString = "") {
410
407
  }
411
408
  return permissions;
412
409
  };
410
+ var FileType = /* @__PURE__ */ ((FileType2) => {
411
+ FileType2["Folder"] = "folder";
412
+ FileType2["File"] = "file";
413
+ return FileType2;
414
+ })(FileType || {});
413
415
  const isDavRessource = function(source, davService) {
414
416
  return source.match(davService) !== null;
415
417
  };
@@ -742,11 +744,6 @@ class Node {
742
744
  }
743
745
  }
744
746
  }
745
- var FileType = /* @__PURE__ */ ((FileType2) => {
746
- FileType2["Folder"] = "folder";
747
- FileType2["File"] = "file";
748
- return FileType2;
749
- })(FileType || {});
750
747
  class File extends Node {
751
748
  get type() {
752
749
  return FileType.File;
@@ -769,8 +766,21 @@ class Folder extends Node {
769
766
  return "httpd/unix-directory";
770
767
  }
771
768
  }
772
- const davRootPath = `/files/${auth.getCurrentUser()?.uid}`;
773
- const davRemoteURL = router.generateRemoteUrl("dav");
769
+ function davGetRootPath() {
770
+ if (_public.isPublicShare()) {
771
+ return `/files/${_public.getSharingToken()}`;
772
+ }
773
+ return `/files/${auth.getCurrentUser()?.uid}`;
774
+ }
775
+ const davRootPath = davGetRootPath();
776
+ function davGetRemoteURL() {
777
+ const url = router.generateRemoteUrl("dav");
778
+ if (_public.isPublicShare()) {
779
+ return url.replace("remote.php", "public.php");
780
+ }
781
+ return url;
782
+ }
783
+ const davRemoteURL = davGetRemoteURL();
774
784
  const davGetClient = function(remoteURL = davRemoteURL, headers = {}) {
775
785
  const client = webdav.createClient(remoteURL, { headers });
776
786
  function setHeaders(token) {
@@ -819,9 +829,7 @@ const getFavoriteNodes = (davClient, path2 = "/", davRoot = davRootPath) => {
819
829
  };
820
830
  const davResultToNode = function(node, filesRoot = davRootPath, remoteURL = davRemoteURL) {
821
831
  let userId = auth.getCurrentUser()?.uid;
822
- const isPublic = document.querySelector("input#isPublic")?.value;
823
- if (isPublic) {
824
- userId = userId ?? document.querySelector("input#sharingUserId")?.value;
832
+ if (_public.isPublicShare()) {
825
833
  userId = userId ?? "anonymous";
826
834
  } else if (!userId) {
827
835
  throw new Error("No user id found");
@@ -968,10 +976,10 @@ function sortNodes(nodes, options = {}) {
968
976
  ...sortingOptions.sortFavoritesFirst ? [(v) => v.attributes?.favorite !== 1] : [],
969
977
  // 2: Sort folders first if sorting by name
970
978
  ...sortingOptions.sortFoldersFirst ? [(v) => v.type !== "folder"] : [],
971
- // 3: Use sorting mode if NOT basename (to be able to use displayName too)
979
+ // 3: Use sorting mode if NOT basename (to be able to use displayname too)
972
980
  ...sortingOptions.sortingMode !== "basename" ? [(v) => v[sortingOptions.sortingMode]] : [],
973
- // 4: Use displayName if available, fallback to name
974
- (v) => basename(v.attributes?.displayName || v.basename),
981
+ // 4: Use displayname if available, fallback to name
982
+ (v) => basename(v.attributes?.displayname || v.basename),
975
983
  // 5: Finally, use basename if all previous sorting methods failed
976
984
  (v) => v.basename
977
985
  ];
@@ -2816,6 +2824,8 @@ exports.davGetClient = davGetClient;
2816
2824
  exports.davGetDefaultPropfind = davGetDefaultPropfind;
2817
2825
  exports.davGetFavoritesReport = davGetFavoritesReport;
2818
2826
  exports.davGetRecentSearch = davGetRecentSearch;
2827
+ exports.davGetRemoteURL = davGetRemoteURL;
2828
+ exports.davGetRootPath = davGetRootPath;
2819
2829
  exports.davParsePermissions = davParsePermissions;
2820
2830
  exports.davRemoteURL = davRemoteURL;
2821
2831
  exports.davResultToNode = davResultToNode;