hfs 0.38.3 → 0.40.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/src/vfs.js CHANGED
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.cantReadStatusCode = exports.walkNode = exports.hasPermission = exports.nodeIsDirectory = exports.getNodeName = exports.saveVfs = exports.vfs = exports.urlToNode = exports.MIME_AUTO = exports.defaultPerms = void 0;
7
+ exports.cantReadStatusCode = exports.walkNode = exports.hasPermission = exports.nodeIsDirectory = exports.getNodeName = exports.saveVfs = exports.vfs = exports.urlToNode = exports.isSameFilenameAs = exports.MIME_AUTO = exports.defaultPerms = void 0;
8
8
  const promises_1 = __importDefault(require("fs/promises"));
9
9
  const path_1 = require("path");
10
10
  const micromatch_1 = require("micromatch");
@@ -14,7 +14,6 @@ const config_1 = require("./config");
14
14
  const const_1 = require("./const");
15
15
  const events_1 = __importDefault(require("./events"));
16
16
  const perm_1 = require("./perm");
17
- const misc_2 = require("./misc");
18
17
  const WHO_ANYONE = true;
19
18
  const WHO_NO_ONE = false;
20
19
  const WHO_ANY_ACCOUNT = '*';
@@ -38,6 +37,11 @@ function inheritFromParent(parent, child) {
38
37
  child.mime || (child.mime = parent.mime);
39
38
  return child;
40
39
  }
40
+ function isSameFilenameAs(name) {
41
+ const lc = name.toLowerCase();
42
+ return (other) => lc === (typeof other === 'string' ? other : getNodeName(other)).toLowerCase();
43
+ }
44
+ exports.isSameFilenameAs = isSameFilenameAs;
41
45
  async function urlToNode(url, ctx, parent = exports.vfs, getRest) {
42
46
  var _a;
43
47
  let initialSlashes = 0;
@@ -54,9 +58,7 @@ async function urlToNode(url, ctx, parent = exports.vfs, getRest) {
54
58
  return;
55
59
  }
56
60
  // does the tree node have a child that goes by this name?
57
- const sameName = !const_1.IS_WINDOWS ? (x) => x === name // easy
58
- : (0, misc_2.with_)(name.toLowerCase(), lc => (x) => x.toLowerCase() === lc);
59
- const child = (_a = parent.children) === null || _a === void 0 ? void 0 : _a.find(x => sameName(getNodeName(x)));
61
+ const child = (_a = parent.children) === null || _a === void 0 ? void 0 : _a.find(isSameFilenameAs(name));
60
62
  const ret = {
61
63
  ...child,
62
64
  original: child,
@@ -124,8 +126,7 @@ exports.nodeIsDirectory = nodeIsDirectory;
124
126
  function hasPermission(node, perm, ctx) {
125
127
  var _a;
126
128
  return (node.source || perm !== 'can_upload') // Upload possible only if we know where to store. First check node.source because is supposedly faster.
127
- && matchWho((_a = node[perm]) !== null && _a !== void 0 ? _a : exports.defaultPerms[perm], ctx)
128
- && (perm !== 'can_see' || hasPermission(node, 'can_read', ctx)); // can_see is used to hide something you nonetheless can_read, so you MUST also can_read
129
+ && matchWho((_a = node[perm]) !== null && _a !== void 0 ? _a : exports.defaultPerms[perm], ctx);
129
130
  }
130
131
  exports.hasPermission = hasPermission;
131
132
  async function* walkNode(parent, ctx, depth = 0, prefixPath = '') {