hfs 0.57.24 → 0.57.27-beta2

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.
Files changed (72) hide show
  1. package/admin/assets/{index-CMArzROW.js → index-DSkhXlWX.js} +129 -129
  2. package/admin/assets/{sha512-BbjMQS_R.js → sha512-CoddZKeD.js} +1 -1
  3. package/admin/index.html +1 -1
  4. package/frontend/assets/{index-legacy-uM-kzXmI.js → index-legacy-C4Gclsbz.js} +4 -4
  5. package/frontend/assets/{sha512-legacy-CWlrw4EZ.js → sha512-legacy-C-FMk44u.js} +1 -1
  6. package/frontend/index.html +1 -1
  7. package/package.json +5 -4
  8. package/src/QuickZipStream.js +11 -8
  9. package/src/SendList.js +10 -8
  10. package/src/ThrottledStream.js +8 -6
  11. package/src/acme.js +5 -7
  12. package/src/adminApis.js +6 -7
  13. package/src/api.accounts.js +7 -9
  14. package/src/api.auth.js +7 -11
  15. package/src/api.get_file_list.js +13 -19
  16. package/src/api.lang.js +1 -1
  17. package/src/api.log.js +1 -2
  18. package/src/api.monitor.js +2 -3
  19. package/src/api.net.js +2 -3
  20. package/src/api.plugins.js +8 -10
  21. package/src/api.vfs.js +15 -20
  22. package/src/apiMiddleware.js +4 -4
  23. package/src/auth.js +6 -9
  24. package/src/basicWeb.js +1 -2
  25. package/src/block.js +1 -1
  26. package/src/commands.js +9 -9
  27. package/src/comments.js +4 -5
  28. package/src/config.js +10 -10
  29. package/src/connections.js +11 -6
  30. package/src/consoleLog.js +6 -6
  31. package/src/const.js +4 -4
  32. package/src/cross.js +19 -21
  33. package/src/customHtml.js +3 -4
  34. package/src/ddns.js +4 -4
  35. package/src/debounceAsync.js +3 -3
  36. package/src/errorPages.js +2 -3
  37. package/src/events.js +7 -10
  38. package/src/fileAttr.js +12 -8
  39. package/src/first.js +13 -8
  40. package/src/frontEndApis.js +5 -5
  41. package/src/geo.js +5 -7
  42. package/src/github.js +14 -17
  43. package/src/i18n.js +3 -4
  44. package/src/icons.js +1 -1
  45. package/src/index.js +2 -3
  46. package/src/lang.js +5 -6
  47. package/src/listen.js +25 -28
  48. package/src/log.js +20 -20
  49. package/src/middlewares.js +12 -15
  50. package/src/misc.js +15 -14
  51. package/src/nat.js +14 -16
  52. package/src/outboundProxy.js +7 -7
  53. package/src/perm.js +12 -13
  54. package/src/persistence.js +1 -1
  55. package/src/plugins.js +62 -73
  56. package/src/roots.js +1 -2
  57. package/src/selfCheck.js +5 -4
  58. package/src/serveFile.js +7 -8
  59. package/src/serveGuiAndSharedFiles.js +7 -9
  60. package/src/serveGuiFiles.js +11 -21
  61. package/src/stat.js +40 -0
  62. package/src/statWorker.js +11 -0
  63. package/src/throttler.js +5 -7
  64. package/src/update.js +9 -9
  65. package/src/upload.js +11 -13
  66. package/src/util-files.js +48 -32
  67. package/src/util-http.js +80 -29
  68. package/src/util-os.js +5 -8
  69. package/src/vfs.js +77 -68
  70. package/src/walkDir.js +9 -9
  71. package/src/watchLoad.js +4 -4
  72. package/src/zip.js +5 -10
package/src/misc.js CHANGED
@@ -51,12 +51,10 @@ function isLocalHost(c) {
51
51
  }
52
52
  // this will memory-leak over mask, so be careful with what you use this. Object is 3x faster than _.memoize
53
53
  function netMatches(ip, mask, emptyMaskReturns = false) {
54
- var _a, _b;
55
- const cache = (_a = netMatches).cache || (_a.cache = {});
56
- return (cache[_b = mask + (emptyMaskReturns ? '1' : '0')] || (cache[_b] = makeNetMatcher(mask, emptyMaskReturns)))(ip); // cache the matcher
54
+ const cache = netMatches.cache ||= {};
55
+ return (cache[mask + (emptyMaskReturns ? '1' : '0')] ||= makeNetMatcher(mask, emptyMaskReturns))(ip); // cache the matcher
57
56
  }
58
57
  function makeNetMatcher(mask, emptyMaskReturns = false) {
59
- var _a;
60
58
  if (!mask)
61
59
  return () => emptyMaskReturns;
62
60
  mask = mask.replaceAll(' ', '');
@@ -68,7 +66,7 @@ function makeNetMatcher(mask, emptyMaskReturns = false) {
68
66
  return (0, cross_1.makeMatcher)(mask);
69
67
  }
70
68
  const all = mask.split('|');
71
- const neg = ((_a = all[0]) === null || _a === void 0 ? void 0 : _a[0]) === '!';
69
+ const neg = all[0]?.[0] === '!';
72
70
  if (neg)
73
71
  all[0] = all[0].slice(1);
74
72
  const bl = new node_net_1.BlockList();
@@ -83,15 +81,15 @@ function makeNetMatcher(mask, emptyMaskReturns = false) {
83
81
  try {
84
82
  bl.addSubnet(address, Number(m[2]));
85
83
  }
86
- catch (_b) {
84
+ catch {
87
85
  throw x;
88
86
  }
89
87
  else if (m[3])
90
88
  try {
91
- bl.addRange(address, parseAddress(m[2]));
89
+ bl.addRange(address, parseAddress(m[3]));
92
90
  }
93
- catch (_c) {
94
- throw m[2];
91
+ catch {
92
+ throw m[3];
95
93
  }
96
94
  else
97
95
  bl.addAddress(address);
@@ -100,7 +98,7 @@ function makeNetMatcher(mask, emptyMaskReturns = false) {
100
98
  try {
101
99
  return neg !== bl.check(parseAddress(ip));
102
100
  }
103
- catch (_a) {
101
+ catch {
104
102
  console.error("invalid address ", ip);
105
103
  return false;
106
104
  }
@@ -122,8 +120,7 @@ function asyncGeneratorToReadable(generator) {
122
120
  return new stream_1.Readable({
123
121
  objectMode: true,
124
122
  destroy() {
125
- var _a;
126
- void ((_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator));
123
+ void iterator.return?.();
127
124
  },
128
125
  read() {
129
126
  iterator.next().then(it => {
@@ -136,10 +133,11 @@ function asyncGeneratorToReadable(generator) {
136
133
  }
137
134
  // produces as promises resolve, not sequentially
138
135
  class AsapStream extends stream_1.Readable {
136
+ promises;
137
+ finished = false;
139
138
  constructor(promises) {
140
139
  super({ objectMode: true });
141
140
  this.promises = promises;
142
- this.finished = false;
143
141
  }
144
142
  _read() {
145
143
  if (this.finished)
@@ -152,10 +150,13 @@ class AsapStream extends stream_1.Readable {
152
150
  }
153
151
  exports.AsapStream = AsapStream;
154
152
  function apiAssertTypes(paramsByType) {
155
- for (const [types, params] of Object.entries(paramsByType))
153
+ for (const [types, params] of Object.entries(paramsByType)) {
154
+ if (!lodash_1.default.isPlainObject(params))
155
+ throw "invalid apiAssertTypes call";
156
156
  for (const [name, val] of Object.entries(params))
157
157
  if (!types.split('_').some(type => type === 'array' ? Array.isArray(val) : typeof val === type))
158
158
  throw new apiMiddleware_1.ApiError(const_1.HTTP_BAD_REQUEST, 'bad ' + name);
159
+ }
159
160
  }
160
161
  function createStreamLimiter(limit) {
161
162
  let got = 0;
package/src/nat.js CHANGED
@@ -30,10 +30,10 @@ exports.defaultBaseUrl = (0, valtio_1.proxy)({
30
30
  return `${this.proto}://${(0, cross_1.ipForUrl)(ip || 'localhost')}${!port || port === defPort ? '' : ':' + port}`;
31
31
  }
32
32
  });
33
- exports.upnpClient = new nat_upnp_rejetto_1.Client({ timeout: 4000 });
33
+ exports.upnpClient = new nat_upnp_rejetto_1.Client({ timeout: 4_000 });
34
34
  const originalMethod = exports.upnpClient.getGateway;
35
35
  // other client methods call getGateway too, so this will ensure they reuse this same result
36
- exports.upnpClient.getGateway = (0, debounceAsync_1.debounceAsync)(() => originalMethod.apply(exports.upnpClient), { retain: cross_1.HOUR, retainFailure: 30000 });
36
+ exports.upnpClient.getGateway = (0, debounceAsync_1.debounceAsync)(() => originalMethod.apply(exports.upnpClient), { retain: cross_1.HOUR, retainFailure: 30_000 });
37
37
  exports.upnpClient.getGateway().then(res => {
38
38
  console.log("upnp found", res.gateway.description);
39
39
  }, e => console.debug('upnp failed:', e.message || String(e)));
@@ -46,16 +46,16 @@ exports.upnpClient.getGateway().then(res => {
46
46
  }, () => { }));
47
47
  exports.getPublicIps = (0, debounceAsync_1.debounceAsync)(async () => {
48
48
  const res = await (0, github_1.getProjectInfo)();
49
- const groupedByVersion = Object.values(lodash_1.default.groupBy(res.publicIpServices, x => { var _a; return (_a = x.v) !== null && _a !== void 0 ? _a : 4; }));
49
+ const groupedByVersion = Object.values(lodash_1.default.groupBy(res.publicIpServices, x => x.v ?? 4));
50
50
  const ips = await (0, cross_1.promiseBestEffort)(groupedByVersion.map(singleVersion => Promise.any(singleVersion.map(async (svc) => {
51
51
  if (typeof svc === 'string')
52
52
  svc = { type: 'http', url: svc };
53
53
  console.debug("trying ip service", svc.url || svc.name);
54
54
  if (svc.type === 'http')
55
- return (0, util_http_1.httpString)(svc.url, { timeout: 5000 });
55
+ return (0, util_http_1.httpString)(svc.url, { timeout: 5_000 });
56
56
  if (svc.type !== 'dns')
57
57
  throw "unsupported";
58
- const resolver = new promises_1.Resolver({ timeout: 2000 });
58
+ const resolver = new promises_1.Resolver({ timeout: 2_000 });
59
59
  resolver.setServers(svc.ips);
60
60
  return resolver.resolve(svc.name, svc.dnsRecord);
61
61
  }).map(async (ret) => {
@@ -67,18 +67,17 @@ exports.getPublicIps = (0, debounceAsync_1.debounceAsync)(async () => {
67
67
  return exports.defaultBaseUrl.publicIps = lodash_1.default.uniq(ips.flat());
68
68
  }, { retain: 10 * cross_1.MINUTE });
69
69
  exports.getNatInfo = (0, debounceAsync_1.debounceAsync)(async () => {
70
- var _a, _b, _c, _d;
71
70
  const gatewayIpPromise = findGateway().catch(() => undefined);
72
- const res = await (0, cross_1.haveTimeout)(10000, exports.upnpClient.getGateway()).catch(() => null);
71
+ const res = await (0, cross_1.haveTimeout)(10_000, exports.upnpClient.getGateway()).catch(() => null);
73
72
  const status = await (0, listen_1.getServerStatus)();
74
- const mappings = res && await (0, cross_1.haveTimeout)(5000, exports.upnpClient.getMappings()).catch(() => null);
75
- console.debug("mappings found:", (mappings === null || mappings === void 0 ? void 0 : mappings.map(x => x.description).join(', ')) || "none");
73
+ const mappings = res && await (0, cross_1.haveTimeout)(5_000, exports.upnpClient.getMappings()).catch(() => null);
74
+ console.debug("mappings found:", mappings?.map(x => x.description).join(', ') || "none");
76
75
  const localIps = await (0, listen_1.getIps)(false);
77
76
  const gatewayIp = await gatewayIpPromise;
78
- const localIp = (res === null || res === void 0 ? void 0 : res.address) || (gatewayIp ? lodash_1.default.maxBy(localIps, x => (0, cross_1.inCommon)(x, gatewayIp)) : localIps[0]);
79
- const internalPort = ((_a = status === null || status === void 0 ? void 0 : status.https) === null || _a === void 0 ? void 0 : _a.listening) && status.https.port || ((_b = status === null || status === void 0 ? void 0 : status.http) === null || _b === void 0 ? void 0 : _b.listening) && status.http.port || undefined;
77
+ const localIp = res?.address || (gatewayIp ? lodash_1.default.maxBy(localIps, x => (0, cross_1.inCommon)(x, gatewayIp)) : localIps[0]);
78
+ const internalPort = status?.https?.listening && status.https.port || status?.http?.listening && status.http.port || undefined;
80
79
  const mapped = lodash_1.default.find(mappings, x => x.private.host === localIp && x.private.port === internalPort);
81
- const externalPort = mapped === null || mapped === void 0 ? void 0 : mapped.public.port;
80
+ const externalPort = mapped?.public.port;
82
81
  if (localIp)
83
82
  exports.defaultBaseUrl.localIp = localIp;
84
83
  exports.defaultBaseUrl.port = externalPort || internalPort || 0;
@@ -91,18 +90,17 @@ exports.getNatInfo = (0, debounceAsync_1.debounceAsync)(async () => {
91
90
  mapped80: lodash_1.default.find(mappings, x => x.private.host === localIp && x.private.port === 80 && x.public.port === 80),
92
91
  internalPort,
93
92
  externalPort,
94
- proto: ((_c = status === null || status === void 0 ? void 0 : status.https) === null || _c === void 0 ? void 0 : _c.listening) ? 'https' : ((_d = status === null || status === void 0 ? void 0 : status.http) === null || _d === void 0 ? void 0 : _d.listening) ? 'http' : '',
93
+ proto: status?.https?.listening ? 'https' : status?.http?.listening ? 'http' : '',
95
94
  };
96
95
  }, { reuseRunning: true });
97
96
  (0, exports.getNatInfo)();
98
97
  function findGateway() {
99
98
  return new Promise((resolve, reject) => (0, child_process_1.exec)(const_1.IS_WINDOWS || const_1.IS_MAC ? 'netstat -rn' : 'route -n', (err, out) => {
100
- var _a, _b;
101
99
  if (err)
102
100
  return reject(err);
103
101
  if (!const_1.IS_WINDOWS)
104
- return resolve((_a = out.match(const_1.IS_MAC ? /default +([\d.]+)/ : /^0\.0\.0\.0 +([\d.]+)/)) === null || _a === void 0 ? void 0 : _a[1]);
102
+ return resolve(out.match(const_1.IS_MAC ? /default +([\d.]+)/ : /^0\.0\.0\.0 +([\d.]+)/)?.[1]);
105
103
  const sortedByMetric = lodash_1.default.sortBy([...out.matchAll(/(?:0\.0\.0\.0 +){2}([\d.]+)\s+[\d.]+\s+(\d+)/g)], x => Number(x[2]));
106
- resolve((_b = sortedByMetric[0]) === null || _b === void 0 ? void 0 : _b[1]); // take ip with lowest metric
104
+ resolve(sortedByMetric[0]?.[1]); // take ip with lowest metric
107
105
  }));
108
106
  }
@@ -13,27 +13,27 @@ const outboundProxy = (0, config_1.defineConfig)(cross_1.CFG.outbound_proxy, '',
13
13
  if (!v || process.env.HFS_SKIP_PROXY_TEST)
14
14
  return;
15
15
  const test = 'https://google.com';
16
- (0, util_http_1.httpString)(test).catch(e => { var _a; return console.error(`proxy failed for ${test} : ${((_a = e === null || e === void 0 ? void 0 : e.errors) === null || _a === void 0 ? void 0 : _a[0]) || e}`); }); // `.errors` in case of AggregateError
16
+ console.debug("testing proxy using", test);
17
+ (0, util_http_1.httpString)(test, { noRedirect: true }).catch(e => console.error(`proxy test failed on ${test} : ${e?.errors?.[0] || e}`)); // `.errors` in case of AggregateError
17
18
  }
18
- catch (_a) {
19
+ catch {
19
20
  console.warn("invalid URL", v);
20
21
  return '';
21
22
  }
22
23
  });
23
24
  config_1.configReady.then(async ([startedWithoutConfig]) => {
24
- var _a, _b, _c, _d;
25
25
  if (!const_1.IS_WINDOWS || !startedWithoutConfig)
26
26
  return;
27
27
  // try to read Windows system setting for proxy
28
28
  const out = await (0, util_os_1.reg)('query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings');
29
- if (!Number((_a = /ProxyEnable\s+\w+\s+(.+)/.exec(out)) === null || _a === void 0 ? void 0 : _a[1]))
29
+ if (!Number(/ProxyEnable\s+\w+\s+(.+)/.exec(out)?.[1]))
30
30
  return;
31
- const read = (_b = /ProxyServer\s+\w+\s+(.+)/.exec(out)) === null || _b === void 0 ? void 0 : _b[1];
31
+ const read = /ProxyServer\s+\w+\s+(.+)/.exec(out)?.[1];
32
32
  if (!read)
33
33
  return;
34
34
  // it can be like "IP:PORT" or "http=IP:PORT;https=IP:PORT;ftp=IP:PORT"
35
- const url = (0, cross_1.prefix)('https://', (_c = /https=([\d:.]+)/.exec(out)) === null || _c === void 0 ? void 0 : _c[1]) // prefer https
36
- || (0, cross_1.prefix)('http://', (_d = /http=([\d:.]+)/.exec(out)) === null || _d === void 0 ? void 0 : _d[1])
35
+ const url = (0, cross_1.prefix)('https://', /https=([\d:.]+)/.exec(out)?.[1]) // prefer https
36
+ || (0, cross_1.prefix)('http://', /http=([\d:.]+)/.exec(out)?.[1])
37
37
  || !read.includes('=') && 'http://' + read; // simpler form
38
38
  if (!url)
39
39
  return;
package/src/perm.js CHANGED
@@ -46,8 +46,7 @@ function expandUsername(who) {
46
46
  }
47
47
  // check if current username or any ancestor match the provided usernames
48
48
  function ctxBelongsTo(ctx, usernames) {
49
- var _a;
50
- return ((_a = ctx.state).usernames || (_a.usernames = expandUsername((0, auth_1.getCurrentUsername)(ctx)))) // cache ancestors' usernames inside context state
49
+ return (ctx.state.usernames ||= expandUsername((0, auth_1.getCurrentUsername)(ctx))) // cache ancestors' usernames inside context state
51
50
  .some((u) => usernames.includes(u));
52
51
  }
53
52
  function getUsernames() {
@@ -78,9 +77,13 @@ async function updateAccount(account, change) {
78
77
  const jsonWas = JSON.stringify(account);
79
78
  const { username: usernameWas } = account;
80
79
  if (typeof change === 'function')
81
- await (change === null || change === void 0 ? void 0 : change(account));
82
- else
80
+ await change?.(account);
81
+ else {
82
+ const u = normalizeUsername(change.username || '');
83
+ if (u && u !== usernameWas && getAccount(u))
84
+ throw "username already exists";
83
85
  Object.assign(account, (0, misc_1.objSameKeys)(change, x => x || undefined));
86
+ }
84
87
  for (const [k, v] of (0, misc_1.typedEntries)(account))
85
88
  if (!v)
86
89
  delete account[k]; // we consider all account fields, when falsy, as equivalent to be missing (so, default value applies)
@@ -102,7 +105,7 @@ async function updateAccount(account, change) {
102
105
  if (!account.belongs.length)
103
106
  delete account.belongs;
104
107
  }
105
- account.expire && (account.expire = new Date(account.expire));
108
+ account.expire &&= new Date(account.expire);
106
109
  if (username !== usernameWas)
107
110
  renameAccount(usernameWas, username);
108
111
  if (jsonWas !== JSON.stringify(account)) // this test will miss the 'username' field, because hidden, but renameAccount is already calling saveAccountsASAP
@@ -114,7 +117,7 @@ exports.accounts.sub(lodash_1.default.debounce(obj => {
114
117
  // consider some validation here, in case of manual edit of the config
115
118
  lodash_1.default.each(obj, (rec, k) => {
116
119
  const norm = normalizeUsername(k);
117
- if ((rec === null || rec === void 0 ? void 0 : rec.username) !== norm) {
120
+ if (rec?.username !== norm) {
118
121
  if (!rec) // an empty object in yaml is parsed as null
119
122
  rec = obj[norm] = { username: norm };
120
123
  else if ((0, misc_1.objRenameKey)(obj, k, norm))
@@ -128,7 +131,6 @@ function normalizeUsername(username) {
128
131
  return username.toLocaleLowerCase();
129
132
  }
130
133
  function renameAccount(from, to) {
131
- var _a;
132
134
  from = normalizeUsername(from);
133
135
  const as = exports.accounts.get();
134
136
  to = normalizeUsername(to);
@@ -140,7 +142,7 @@ function renameAccount(from, to) {
140
142
  (0, misc_1.setHidden)(as[to], { username: to });
141
143
  // update references
142
144
  for (const a of Object.values(as)) {
143
- const idx = (_a = a.belongs) === null || _a === void 0 ? void 0 : _a.indexOf(from);
145
+ const idx = a.belongs?.indexOf(from);
144
146
  if (idx !== undefined && idx >= 0)
145
147
  a.belongs[idx] = to;
146
148
  }
@@ -186,15 +188,12 @@ function accountHasPassword(account) {
186
188
  return Boolean(account.password || account.srp);
187
189
  }
188
190
  function accountCanLogin(account) {
189
- var _a;
190
- return (accountHasPassword(account) || ((_a = account.plugin) === null || _a === void 0 ? void 0 : _a.auth)) && !accountIsDisabled(account);
191
+ return (accountHasPassword(account) || account.plugin?.auth) && !accountIsDisabled(account);
191
192
  }
192
193
  function accountIsDisabled(account) {
193
- var _a;
194
194
  return Boolean(account.disabled
195
195
  || account.expire < Date.now()
196
- || ((_a = account.belongs) === null || _a === void 0 ? void 0 : _a.length // don't every() on empty array, as it returns true
197
- )
196
+ || account.belongs?.length // don't every() on empty array, as it returns true
198
197
  && account.belongs.map(u => getAccount(u, false)).every(a => a && accountIsDisabled(a)));
199
198
  }
200
199
  function accountCanLoginAdmin(account) {
@@ -9,7 +9,7 @@ exports.storedMap = new kvstorage_1.KvStorage({
9
9
  maxPutDelay: misc_1.MINUTE,
10
10
  maxPutDelayCreate: 1000,
11
11
  rewriteLater: true,
12
- bucketThreshold: 10000,
12
+ bucketThreshold: 10_000,
13
13
  });
14
14
  exports.storedMap.open('data.kv');
15
15
  (0, first_1.onProcessExit)(() => exports.storedMap.flush());