hfs 3.1.1 → 3.1.2

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/first.js CHANGED
@@ -1,31 +1,39 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.quitting = void 0;
4
7
  exports.onProcessExit = onProcessExit;
5
8
  exports.onFirstEvent = onFirstEvent;
9
+ const lodash_1 = __importDefault(require("lodash"));
10
+ const assert_1 = __importDefault(require("assert"));
6
11
  const cbsOnExit = new Set();
7
- function onProcessExit(cb) {
8
- cbsOnExit.add(cb);
9
- return () => cbsOnExit.delete(cb);
12
+ function onProcessExit(cb, order = 10) {
13
+ (0, assert_1.default)(Number.isInteger(order) && order >= 0, 'order must be an integer >= 0');
14
+ const rec = { cb, order };
15
+ cbsOnExit.add(rec);
16
+ return () => cbsOnExit.delete(rec);
10
17
  }
11
18
  exports.quitting = false;
12
19
  // 'exit' event is handled as the last resort, but it's not compatible with async callbacks
13
- onFirstEvent(process, ['exit', 'SIGQUIT', 'SIGTERM', 'SIGINT', 'SIGHUP'], signal => {
20
+ onFirstEvent(process, ['exit', 'SIGQUIT', 'SIGTERM', 'SIGINT', 'SIGHUP'], async (signal) => {
14
21
  console.log('Quitting with signal:', signal || 'unknown');
15
22
  exports.quitting = true;
16
- return Promise.allSettled(Array.from(cbsOnExit).map(cb => {
17
- try {
18
- return cb(signal);
19
- }
20
- // keep exit moving even when a synchronous cleanup fails after partially shutting down
21
- catch (e) {
22
- console.error("Error while quitting", e);
23
- return Promise.reject(e);
24
- }
25
- })).then(() => {
26
- console.debug('Process exit');
27
- process.exit(0);
28
- });
23
+ const byOrder = lodash_1.default.groupBy(Array.from(cbsOnExit), 'order'); // this will be inherently ordered because keys are positive integers
24
+ for (const recs of Object.values(byOrder))
25
+ await Promise.allSettled(recs.map(({ cb }) => {
26
+ try {
27
+ return cb(signal);
28
+ }
29
+ // keep exit moving even when a synchronous cleanup fails after partially shutting down
30
+ catch (e) {
31
+ console.error("Error while quitting", e);
32
+ return Promise.reject(e);
33
+ }
34
+ }));
35
+ console.debug('Process exit');
36
+ process.exit(0);
29
37
  });
30
38
  // keep calling cb in a sync fashion – returning a promise instead would break the code for argv.updating (update.ts)
31
39
  function onFirstEvent(emitter, events, cb) {
package/src/listen.js CHANGED
@@ -70,8 +70,8 @@ const consoleLog_1 = require("./consoleLog");
70
70
  const first_1 = require("./first");
71
71
  let httpSrv;
72
72
  let httpsSrv;
73
- // update relaunch can keep a bridge process alive, so we proactively close listeners here to release ports before the next binary binds
74
- (0, first_1.onProcessExit)(() => Promise.all([stopServer(httpSrv), stopServer(httpsSrv)]));
73
+ // the update relaunch can keep a bridge process alive, so we proactively close listeners here to release ports before the next binary binds; do it before (5) the storage file is closed, because sockets write there
74
+ (0, first_1.onProcessExit)(() => Promise.all([stopServer(httpSrv), stopServer(httpsSrv)]), 5);
75
75
  const openBrowserAtStart = (0, config_1.defineConfig)('open_browser_at_start', true);
76
76
  exports.baseUrl = (0, config_1.defineConfig)(misc_1.CFG.base_url, '', x => /(?<=\/\/)[^\/]+/.exec(x)?.[0]); // compiled is host only
77
77
  async function getBaseUrlOrDefault() {
package/src/nat.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getNatInfo = exports.getPublicIps = exports.upnpClient = exports.defaultBaseUrl = void 0;
7
7
  const valtio_1 = require("valtio");
8
- const nat_upnp_rejetto_1 = require("nat-upnp-rejetto");
8
+ const nat_upnp_1 = require("@rejetto/nat-upnp");
9
9
  const debounceAsync_1 = require("./debounceAsync");
10
10
  const cross_1 = require("./cross");
11
11
  const github_1 = require("./github");
@@ -30,7 +30,7 @@ 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: 4_000 });
33
+ exports.upnpClient = new nat_upnp_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
36
  exports.upnpClient.getGateway = (0, debounceAsync_1.debounceAsync)(() => originalMethod.apply(exports.upnpClient), { retain: cross_1.HOUR, retainFailure: 30_000 });
package/src/webdav.js CHANGED
@@ -75,9 +75,12 @@ const webdav = async (ctx, next) => {
75
75
  const ua = ctx.get('user-agent');
76
76
  if (path.includes('/._') && ua?.startsWith('WebDAVFS')) { // too much spam from Finder for these files that can contain metas
77
77
  ctx.state.dontLog = true;
78
+ ctx.state.webdavDetected = true;
78
79
  return ctx.status = cross_1.HTTP_FORBIDDEN;
79
80
  }
80
81
  const isWebdavAuthRequest = WEBDAV_METHODS.has(ctx.method) || WEBDAV_HINT_HEADERS.some(h => ctx.get(h));
82
+ if (isWebdavAuthRequest)
83
+ ctx.state.webdavDetected = true;
81
84
  if (isWebdavAuthRequest && ua && (0, auth_1.getCurrentUsername)(ctx))
82
85
  webdavDetectedAgents.try(webdavAgentKey(ctx, ua), () => true);
83
86
  if (ctx.method === 'OPTIONS') {