hfs 0.26.4 → 0.26.6

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.
@@ -1,4 +1,4 @@
1
- import{c as SF}from"./index.bbe713bb.js";function OF(sF,hF){for(var eF=0;eF<hF.length;eF++){const tF=hF[eF];if(typeof tF!="string"&&!Array.isArray(tF)){for(const w in tF)if(w!=="default"&&!(w in sF)){const lF=Object.getOwnPropertyDescriptor(tF,w);lF&&Object.defineProperty(sF,w,lF.get?lF:{enumerable:!0,get:()=>tF[w]})}}}return Object.freeze(Object.defineProperty(sF,Symbol.toStringTag,{value:"Module"}))}var yF={exports:{}};/*
1
+ import{c as SF}from"./index.1151988f.js";function OF(sF,hF){for(var eF=0;eF<hF.length;eF++){const tF=hF[eF];if(typeof tF!="string"&&!Array.isArray(tF)){for(const w in tF)if(w!=="default"&&!(w in sF)){const lF=Object.getOwnPropertyDescriptor(tF,w);lF&&Object.defineProperty(sF,w,lF.get?lF:{enumerable:!0,get:()=>tF[w]})}}}return Object.freeze(Object.defineProperty(sF,Symbol.toStringTag,{value:"Module"}))}var yF={exports:{}};/*
2
2
  * [js-sha512]{@link https://github.com/emn178/js-sha512}
3
3
  *
4
4
  * @version 0.8.0
@@ -6,7 +6,7 @@
6
6
  <link href="fontello.css" rel="stylesheet" />
7
7
  <script>SESSION = _HFS_SESSION_</script>
8
8
  <title>File Server</title>
9
- <script type="module" crossorigin src="/assets/index.bbe713bb.js"></script>
9
+ <script type="module" crossorigin src="/assets/index.1151988f.js"></script>
10
10
  <link rel="stylesheet" href="/assets/index.93366732.css">
11
11
  </head>
12
12
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hfs",
3
- "version": "0.26.4",
3
+ "version": "0.26.6",
4
4
  "description": "HTTP File Server",
5
5
  "keywords": [
6
6
  "file server",
@@ -30,7 +30,6 @@
30
30
  "dist-bin": "npm run dist-modules && cd dist && pkg . -C gzip && mv -f hfs-win-x64.exe hfs.exe && zip hfs-windows.zip hfs.exe -r plugins && cp -f hfs-linux-x64 hfs && zip hfs-linux.zip hfs -r plugins && cp -f hfs-macos-x64 hfs && zip hfs-mac.zip hfs -r plugins && cp -f hfs-macos-arm64 hfs && zip hfs-mac-arm.zip hfs -r plugins && rm hfs",
31
31
  "dist-modules": "cp package*.json dist && cd dist && npm ci --omit=dev && npm i -f --no-save --omit=dev @node-rs/crc32-win32-x64-msvc && rm package-lock.json && cd .. && node prune_modules",
32
32
  "dist-win": "npm run dist-modules && cd dist && pkg . -C gzip -t node16-win-x64 && zip hfs-windows.zip hfs.exe -r plugins",
33
- "dist-mac": "cd dist && pkg . -C gzip -t node16-mac-arm64",
34
33
  "dist-node": "npm run dist-modules && cd dist && zip hfs-node.zip -r * -x *.zip *.exe hfs-* *.log logs"
35
34
  },
36
35
  "engines": {
package/src/index.js CHANGED
@@ -4,6 +4,7 @@
4
4
  var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
6
6
  };
7
+ var _a;
7
8
  Object.defineProperty(exports, "__esModule", { value: true });
8
9
  exports.app = void 0;
9
10
  const koa_1 = __importDefault(require("koa"));
@@ -21,8 +22,9 @@ const adminApis_1 = require("./adminApis");
21
22
  const config_1 = require("./config");
22
23
  const assert_1 = require("assert");
23
24
  const lodash_1 = __importDefault(require("lodash"));
25
+ const misc_1 = require("./misc");
24
26
  (0, assert_1.ok)(lodash_1.default.intersection(Object.keys(frontEndApis_1.frontEndApis), Object.keys(adminApis_1.adminApis)).length === 0); // they share same endpoints
25
- const keys = ['hfs-keys-test'];
27
+ const keys = ((_a = process.env.COOKIE_SIGN_KEYS) === null || _a === void 0 ? void 0 : _a.split(',')) || [(0, misc_1.randomId)(30)];
26
28
  exports.app = new koa_1.default({ keys });
27
29
  exports.app.use(middlewares_1.someSecurity)
28
30
  .use((0, middlewares_1.sessions)(exports.app))
package/src/misc.js CHANGED
@@ -60,10 +60,10 @@ function getOrSet(o, k, creator) {
60
60
  : (o[k] = creator());
61
61
  }
62
62
  exports.getOrSet = getOrSet;
63
+ // 10 chars is 51+bits, 8 is 41+bits
63
64
  function randomId(len = 10) {
64
- // 10 chars is 51+bits, the max we can give. 8 is 41+bits
65
65
  if (len > 10)
66
- throw Error('bad length');
66
+ return randomId(10) + randomId(len - 10);
67
67
  return Math.random()
68
68
  .toString(36)
69
69
  .substring(2, 2 + len)
package/src/util-files.js CHANGED
@@ -91,23 +91,25 @@ function adjustStaticPathForGlob(path) {
91
91
  return fast_glob_1.default.escapePath(path.replace(/\\/g, '/'));
92
92
  }
93
93
  exports.adjustStaticPathForGlob = adjustStaticPathForGlob;
94
- async function* dirStream(path) {
95
- const stats = await promises_1.default.stat(path);
96
- if (!stats.isDirectory())
94
+ async function* dirStream(path, deep) {
95
+ if (!await isDirectory(path))
97
96
  throw Error('ENOTDIR');
98
- const dirStream = fast_glob_1.default.stream('*', {
97
+ const dirStream = fast_glob_1.default.stream(deep ? '**/*' : '*', {
99
98
  cwd: path,
100
99
  dot: true,
100
+ deep,
101
101
  onlyFiles: false,
102
102
  suppressErrors: true,
103
+ objectMode: true,
103
104
  });
104
105
  const skip = await getItemsToSkip(path);
105
- for await (let path of dirStream) {
106
- if (path instanceof Buffer)
107
- path = path.toString('utf8');
108
- if (skip === null || skip === void 0 ? void 0 : skip.includes(path))
106
+ for await (const entry of dirStream) {
107
+ let { path, dirent } = entry;
108
+ if (!dirent.isDirectory() && !dirent.isFile())
109
109
  continue;
110
- yield path;
110
+ path = String(path);
111
+ if (!(skip === null || skip === void 0 ? void 0 : skip.includes(path)))
112
+ yield path;
111
113
  }
112
114
  async function getItemsToSkip(path) {
113
115
  if (!const_1.IS_WINDOWS)
package/src/vfs.js CHANGED
@@ -115,6 +115,7 @@ function hasPermission(node, perm, ctx) {
115
115
  }
116
116
  exports.hasPermission = hasPermission;
117
117
  async function* walkNode(parent, ctx, depth = 0, prefixPath = '') {
118
+ var _a;
118
119
  const { children, source } = parent;
119
120
  if (children)
120
121
  for (let idx = 0; idx < children.length; idx++) {
@@ -122,60 +123,58 @@ async function* walkNode(parent, ctx, depth = 0, prefixPath = '') {
122
123
  yield* workItem({
123
124
  ...child,
124
125
  name: prefixPath ? (prefixPath + getNodeName(child)) : child.name
125
- });
126
+ }, depth > 0 && await nodeIsDirectory(child).catch(() => false));
126
127
  }
127
128
  if (!source)
128
129
  return;
129
130
  try {
130
- for await (const path of (0, misc_1.dirStream)(source)) {
131
- if (ctx.req.aborted)
131
+ for await (const path of (0, misc_1.dirStream)(source, depth)) {
132
+ if (ctx === null || ctx === void 0 ? void 0 : ctx.req.aborted)
132
133
  return;
133
- let { rename } = parent;
134
- const renamed = rename === null || rename === void 0 ? void 0 : rename[path];
134
+ const renamed = (_a = parent.rename) === null || _a === void 0 ? void 0 : _a[path];
135
135
  yield* workItem({
136
- name: (prefixPath || renamed) && prefixPath + (renamed || path),
136
+ name: prefixPath + (renamed || path),
137
137
  source: (0, path_1.join)(source, path),
138
- rename: renameUnderPath(rename, path),
138
+ rename: renameUnderPath(parent.rename, path),
139
139
  });
140
140
  }
141
141
  }
142
142
  catch (e) {
143
143
  console.debug('glob', source, e); // ENOTDIR, or lacking permissions
144
144
  }
145
- async function* workItem(item) {
145
+ // item will be changed, so be sure to pass a temp node
146
+ async function* workItem(item, recur = false) {
147
+ const name = getNodeName(item);
146
148
  // we basename for depth>0 where we already have the rest of the path in the parent's url, and would be duplicated
147
- const name = (0, path_1.basename)(getNodeName(item));
148
- const url = (0, misc_1.enforceFinal)('/', parent.url || '') + name;
149
- const temp = inheritFromParent(parent, {
150
- ...item,
149
+ const virtualBasename = (0, path_1.basename)(name);
150
+ const url = (0, misc_1.enforceFinal)('/', parent.url || '') + virtualBasename;
151
+ Object.assign(item, {
151
152
  isTemp: true,
152
153
  url,
153
154
  parents: [...parent.parents || [], parent],
154
155
  });
155
- applyMasks(temp, parent, name);
156
- if (!hasPermission(temp, 'can_see', ctx))
156
+ inheritFromParent(parent, item);
157
+ applyMasks(item, parent, virtualBasename);
158
+ if (ctx && !hasPermission(item, 'can_see', ctx))
157
159
  return;
158
- yield temp;
159
- try {
160
- if (!depth || !await nodeIsDirectory(temp))
161
- return;
162
- inheritMasks(temp, parent, name);
163
- yield* walkNode(temp, ctx, depth - 1, getNodeName(temp) + '/');
164
- }
165
- catch (_a) { } // stat failed in nodeIsDirectory, ignore
160
+ yield item;
161
+ if (!recur)
162
+ return;
163
+ inheritMasks(item, parent, virtualBasename);
164
+ yield* walkNode(item, ctx, depth - 1, name + '/');
166
165
  }
167
166
  }
168
167
  exports.walkNode = walkNode;
169
- function applyMasks(item, parent, name) {
168
+ function applyMasks(item, parent, virtualBasename) {
170
169
  const { masks } = parent;
171
170
  if (!masks)
172
171
  return;
173
172
  for (const k in masks)
174
- if (k.startsWith('**/') && (0, micromatch_1.isMatch)(name, k.slice(3))
175
- || !k.includes('/') && (0, micromatch_1.isMatch)(name, k))
173
+ if (k.startsWith('**/') && (0, micromatch_1.isMatch)(virtualBasename, k.slice(3))
174
+ || !k.includes('/') && (0, micromatch_1.isMatch)(virtualBasename, k))
176
175
  Object.assign(item, masks[k]);
177
176
  }
178
- function inheritMasks(item, parent, name) {
177
+ function inheritMasks(item, parent, virtualBasename) {
179
178
  const { masks } = parent;
180
179
  if (!masks)
181
180
  return;
@@ -183,8 +182,8 @@ function inheritMasks(item, parent, name) {
183
182
  for (const k in masks)
184
183
  if (k.startsWith('**/'))
185
184
  o[k.slice(3)] = masks[k];
186
- else if (k.startsWith(name + '/'))
187
- o[k.slice(name.length + 1)] = masks[k];
185
+ else if (k.startsWith(virtualBasename + '/'))
186
+ o[k.slice(virtualBasename.length + 1)] = masks[k];
188
187
  if (Object.keys(o).length)
189
188
  item.masks = o;
190
189
  }