hfs 0.52.7 → 0.52.8

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{g as OF,c as UF}from"./index-TFLZ9zHK.js";function gF(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 dF={exports:{}};/*
1
+ import{g as OF,c as UF}from"./index-N5vN7bBW.js";function gF(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 dF={exports:{}};/*
2
2
  * [js-sha512]{@link https://github.com/emn178/js-sha512}
3
3
  *
4
4
  * @version 0.8.0
@@ -4,8 +4,8 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=0" />
6
6
  <link href="/fontello.css" rel="stylesheet" />
7
- <script type="module" crossorigin src="/assets/index-TFLZ9zHK.js"></script>
8
- <link rel="stylesheet" crossorigin href="/assets/index-dsMqb07K.css">
7
+ <script type="module" crossorigin src="/assets/index-N5vN7bBW.js"></script>
8
+ <link rel="stylesheet" crossorigin href="/assets/index-Bnwe3ltN.css">
9
9
  </head>
10
10
  <body>
11
11
  <noscript>You need to enable JavaScript to run this app.</noscript>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hfs",
3
- "version": "0.52.7",
3
+ "version": "0.52.8",
4
4
  "description": "HTTP File Server",
5
5
  "keywords": [
6
6
  "file server",
@@ -20,12 +20,12 @@ const get_file_list = async ({ uri = '/', offset, limit, search, c, onlyFolders,
20
20
  if (!node)
21
21
  return fail(const_1.HTTP_NOT_FOUND);
22
22
  admin && (admin = (0, adminApis_1.ctxAdminAccess)(ctx)); // validate 'admin' flag
23
- if (!admin && (0, vfs_1.statusCodeForMissingPerm)(node, 'can_list', ctx))
24
- return fail();
25
23
  if ((0, misc_1.dirTraversal)(search))
26
24
  return fail(const_1.HTTP_FOOL);
27
25
  if (await hasDefaultFile(node) || !await (0, vfs_1.nodeIsDirectory)(node))
28
26
  return fail(const_1.HTTP_METHOD_NOT_ALLOWED);
27
+ if (!admin && (0, vfs_1.statusCodeForMissingPerm)(node, 'can_list', ctx))
28
+ return fail();
29
29
  offset = Number(offset);
30
30
  limit = Number(limit);
31
31
  const filter = (0, misc_1.pattern2filter)(String(search || ''));
@@ -71,7 +71,7 @@ exports.default = {
71
71
  : s.uploadPath ? { op: 'upload', path: decodeURIComponent(s.uploadPath) }
72
72
  : {
73
73
  op: !s.considerAsGui && s.op || undefined,
74
- path: decodeURIComponent(ctx.originalUrl)
74
+ path: (0, misc_1.try_)(() => decodeURIComponent(ctx.originalUrl), () => ctx.originalUrl),
75
75
  },
76
76
  opProgress: lodash_1.default.isNumber(s.opProgress) ? lodash_1.default.round(s.opProgress, 3) : undefined,
77
77
  opTotal: s.opTotal,
@@ -62,8 +62,7 @@ const apis = {
62
62
  if ((0, plugins_1.isPluginRunning)(id))
63
63
  return { msg: 'already running' };
64
64
  await (0, plugins_1.stopPlugin)(id);
65
- await (0, plugins_1.startPlugin)(id);
66
- return {};
65
+ return (0, plugins_1.startPlugin)(id).then(() => 0, e => new apiMiddleware_1.ApiError(const_1.HTTP_SERVER_ERROR, e.message));
67
66
  },
68
67
  async stop_plugin({ id }) {
69
68
  if (!(0, plugins_1.isPluginRunning)(id))
package/src/api.vfs.js CHANGED
@@ -34,7 +34,7 @@ const apis = {
34
34
  : { size: source ? -1 : undefined };
35
35
  if (copyStats.mtime && Number(copyStats.mtime) === Number(copyStats.ctime))
36
36
  delete copyStats.mtime;
37
- const inherited = node.parent && (0, vfs_1.permsFromParent)(node.parent, node.original || node);
37
+ const inherited = node.parent && (0, vfs_1.permsFromParent)(node.parent, {});
38
38
  const byMasks = node.original && lodash_1.default.pickBy(node, (v, k) => v !== node.original[k] // something is changing me...
39
39
  && !(inherited && k in inherited) // ...and it's not inheritance...
40
40
  && misc_1.PERM_KEYS.includes(k)); // ...must be masks. Please limit this to perms
package/src/commands.js CHANGED
@@ -102,7 +102,7 @@ const commands = {
102
102
  'check-update': {
103
103
  params: '',
104
104
  async cb() {
105
- const update = lodash_1.default.find(await (0, update_1.getUpdates)(), x => x.isNewer);
105
+ const update = (await (0, update_1.getUpdates)(true))[0];
106
106
  if (!update)
107
107
  throw "you already have the latest version: " + const_1.VERSION;
108
108
  console.log("new version available", update.name);
package/src/const.js CHANGED
@@ -45,7 +45,7 @@ exports.DEV = process.env.DEV || exports.argv.dev ? 'DEV' : '';
45
45
  exports.ORIGINAL_CWD = process.cwd();
46
46
  exports.HFS_STARTED = new Date();
47
47
  const PKG_PATH = (0, path_1.join)(__dirname, '..', 'package.json');
48
- exports.BUILD_TIMESTAMP = "2024-05-12T17:10:39.346Z";
48
+ exports.BUILD_TIMESTAMP = "2024-06-09T08:38:32.389Z";
49
49
  const pkg = JSON.parse(fs.readFileSync(PKG_PATH, 'utf8'));
50
50
  exports.VERSION = pkg.version;
51
51
  exports.RUNNING_BETA = exports.VERSION.includes('-');
package/src/cross.js CHANGED
@@ -108,11 +108,11 @@ function objSameKeys(src, newValue) {
108
108
  }
109
109
  exports.objSameKeys = objSameKeys;
110
110
  function enforceFinal(sub, s, evenEmpty = false) {
111
- return evenEmpty && !s || !s.endsWith(sub) ? s + sub : s;
111
+ return (s ? !s.endsWith(sub) : evenEmpty) ? s + sub : s;
112
112
  }
113
113
  exports.enforceFinal = enforceFinal;
114
114
  function enforceStarting(sub, s, evenEmpty = false) {
115
- return evenEmpty && !s || !s.startsWith(sub) ? sub + s : s;
115
+ return (s ? !s.startsWith(sub) : evenEmpty) ? sub + s : s;
116
116
  }
117
117
  exports.enforceStarting = enforceStarting;
118
118
  function removeStarting(sub, s) {
package/src/listen.js CHANGED
@@ -144,8 +144,9 @@ const considerHttps = (0, misc_1.debounceAsync)(async () => {
144
144
  }
145
145
  }
146
146
  catch (e) {
147
+ httpsSrv || (httpsSrv = Object.assign(https.createServer({}), { name: 'https' })); // a dummy container, in case creation failed because of certificate errors
147
148
  httpsSrv.error = "bad private key or certificate";
148
- console.log("failed to create https server: check your private key and certificate", String(e));
149
+ console.error("failed to create https server: check your private key and certificate", e.message);
149
150
  return;
150
151
  }
151
152
  port = await startServer(httpsSrv, { port, host: listenInterface.get() });
package/src/plugins.js CHANGED
@@ -246,6 +246,11 @@ class Plugin {
246
246
  exports.Plugin = Plugin;
247
247
  const SERVER_CODE_ID = '.';
248
248
  const serverCode = (0, config_1.defineConfig)('server_code', '', async (script, { k }) => {
249
+ var _a;
250
+ try {
251
+ (_a = (await serverCode.compiled())) === null || _a === void 0 ? void 0 : _a.unload();
252
+ }
253
+ catch (_b) { }
249
254
  const res = {};
250
255
  try {
251
256
  new Function('exports', script)(res); // parse
@@ -316,7 +321,7 @@ exports.rescan = rescan;
316
321
  function watchPlugin(id, path) {
317
322
  const module = (0, path_1.resolve)(path);
318
323
  let starting;
319
- exports.enablePlugins.sub(() => {
324
+ const unsub = exports.enablePlugins.sub(() => {
320
325
  if (!getPluginInfo(id))
321
326
  return; // not loaded yet
322
327
  const enabled = isPluginEnabled(id);
@@ -336,6 +341,7 @@ function watchPlugin(id, path) {
336
341
  events_1.default.emit(notRunning ? 'pluginUpdated' : 'pluginInstalled', p);
337
342
  });
338
343
  return () => {
344
+ unsub();
339
345
  unwatch();
340
346
  return onUninstalled();
341
347
  };
package/src/update.js CHANGED
@@ -17,14 +17,14 @@ const open_1 = __importDefault(require("open"));
17
17
  const config_1 = require("./config");
18
18
  const util_os_1 = require("./util-os");
19
19
  const updateToBeta = (0, config_1.defineConfig)('update_to_beta', false);
20
- async function getUpdates() {
20
+ async function getUpdates(strict = false) {
21
21
  const stable = await (0, github_1.getRepoInfo)(const_1.HFS_REPO + '/releases/latest');
22
22
  const verStable = ver(stable);
23
23
  const ret = await getBetas();
24
24
  stable.isNewer = config_1.currentVersion.olderThan(stable.tag_name);
25
25
  if (stable.isNewer || const_1.RUNNING_BETA)
26
26
  ret.push(stable);
27
- return ret;
27
+ return ret.filter(x => !strict || x.isNewer);
28
28
  function ver(x) {
29
29
  return (0, config_1.versionToScalar)(x.name);
30
30
  }
@@ -72,7 +72,7 @@ async function update(tagOrUrl = '') {
72
72
  if (!updateSource) {
73
73
  if (/^\d/.test(tagOrUrl)) // work even if the tag is passed without the initial 'v' (useful for console commands)
74
74
  tagOrUrl = 'v' + tagOrUrl;
75
- const update = !tagOrUrl ? (await getUpdates())[0]
75
+ const update = !tagOrUrl ? (await getUpdates(true))[0]
76
76
  : await (0, github_1.getRepoInfo)(const_1.HFS_REPO + '/releases/tags/' + tagOrUrl).catch(e => {
77
77
  if (e.message === '404')
78
78
  console.error("version not found");
package/src/util-os.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RUNNING_AS_SERVICE = exports.runCmd = exports.getDrives = exports.getDiskSpaces = exports.getDiskSpaceSync = void 0;
7
7
  const path_1 = require("path");
8
+ const fs_1 = require("fs");
8
9
  const child_process_1 = require("child_process");
9
10
  const misc_1 = require("./misc");
10
11
  const lodash_1 = __importDefault(require("lodash"));
@@ -20,6 +21,8 @@ function getDiskSpaceSync(path) {
20
21
  throw Error('miss');
21
22
  return { free: Number(one.FreeSpace), total: Number(one.Size) };
22
23
  }
24
+ while (path && !(0, fs_1.existsSync)(path))
25
+ path = (0, path_1.dirname)(path);
23
26
  const out = (0, misc_1.try_)(() => (0, child_process_1.execSync)(`df -k "${path}"`).toString(), err => { throw err.status === 1 ? Error('miss') : err.status === 127 ? Error('unsupported') : err; });
24
27
  if (!(out === null || out === void 0 ? void 0 : out.startsWith('Filesystem')))
25
28
  throw Error('unsupported');