hfs 0.48.0-beta6 → 0.48.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.
@@ -1,4 +1,4 @@
1
- import{g as OF,c as UF}from"./index-d266c6e7.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-e24651da.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
File without changes
File without changes
@@ -5,8 +5,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
7
 
8
- <script type="module" crossorigin src="/assets/index-ad985b09.js"></script>
9
- <link rel="stylesheet" href="/assets/index-05dfd82f.css">
8
+ <script type="module" crossorigin src="/assets/index-e24651da.js"></script>
9
+ <link rel="stylesheet" href="/assets/index-cadcb0e9.css">
10
10
  </head>
11
11
  <body>
12
12
  <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.48.0-beta6",
3
+ "version": "0.48.2",
4
4
  "description": "HTTP File Server",
5
5
  "keywords": [
6
6
  "file server",
@@ -9,12 +9,7 @@
9
9
  "homepage": "https://rejetto.com/hfs",
10
10
  "license": "GPL-3.0",
11
11
  "author": "Massimo Melina <a@rejetto.com>",
12
- "workspaces": [
13
- "admin",
14
- "frontend",
15
- "shared",
16
- "mui-grid-form"
17
- ],
12
+ "workspaces": [ "admin", "frontend", "shared", "mui-grid-form" ],
18
13
  "scripts": {
19
14
  "watch-server": "cross-env DEV=1 nodemon --ignore tests/ --watch src -e ts,tsx --exec ts-node src",
20
15
  "watch-server-proxied": "cross-env FRONTEND_PROXY=3005 ADMIN_PROXY=3006 npm run watch-server",
@@ -40,6 +35,7 @@
40
35
  "node": ">=18.12.0"
41
36
  },
42
37
  "files": [
38
+ "central.json",
43
39
  "src/*",
44
40
  "admin/*",
45
41
  "frontend/*",
package/src/api.net.js CHANGED
@@ -35,7 +35,7 @@ const getNatInfo = (0, misc_1.debounceAsync)(async () => {
35
35
  const gettingIp = getPublicIp(); // don't wait, do it in parallel
36
36
  const res = await client.getGateway().catch(() => null);
37
37
  const status = await (0, listen_1.getServerStatus)();
38
- const mappings = res && await client.getMappings().catch(() => null);
38
+ const mappings = res && await (0, misc_1.haveTimeout)(5000, client.getMappings()).catch(() => null);
39
39
  console.debug('mappings found', mappings);
40
40
  const gatewayIp = res ? new URL(res.gateway.description).hostname : await findGateway().catch(() => null);
41
41
  const localIp = (res === null || res === void 0 ? void 0 : res.address) || (await (0, listen_1.getIps)())[0];
@@ -115,19 +115,21 @@ async function checkDomain(domain) {
115
115
  async function generateSSLCert(domain, email) {
116
116
  await checkDomain(domain);
117
117
  // will answer challenge through our koa app (if on port 80) or must we spawn a dedicated server?
118
+ const { upnp, externalPort } = await getNatInfo();
118
119
  const { http } = await (0, listen_1.getServerStatus)();
119
- const tempSrv = http.listening && http.port === 80 ? undefined : (0, http_1.createServer)(acmeListener);
120
+ const tempSrv = externalPort === 80 || http.listening && http.port === 80 ? undefined : (0, http_1.createServer)(acmeListener);
120
121
  if (tempSrv)
121
- await new Promise((resolve, reject) => tempSrv.listen(80, resolve).on('error', (e) => reject(e.code || e)));
122
- else
123
- acmeMiddlewareEnabled = true;
122
+ await new Promise((resolve) => tempSrv.listen(80, resolve).on('error', (e) => {
123
+ console.debug("cannot listen on 80", e.code || e);
124
+ resolve(); // go on anyway
125
+ }));
126
+ acmeMiddlewareEnabled = true;
124
127
  console.debug('acme challenge server ready');
125
128
  try {
126
- const { upnp, externalPort } = await getNatInfo(); // do this before stopping the server
127
129
  let check = await checkPort(domain, 80); // some check services may not consider the domain, but we already verified that
128
130
  if (check && !check.success && upnp && externalPort !== 80) { // consider a short-lived mapping
129
131
  // @ts-ignore
130
- await client.createMapping({ private: 80, public: { host: '', port: 80 }, description: 'hfs challenge', ttl: 0 }).catch(() => { });
132
+ await client.createMapping({ private: 80, public: { host: '', port: 80 }, description: 'hfs temporary', ttl: 30 }).catch(() => { });
131
133
  check = await checkPort(domain, 80); // repeat test
132
134
  }
133
135
  if (!check)
package/src/config.js CHANGED
@@ -124,7 +124,7 @@ exports.getWholeConfig = getWholeConfig;
124
124
  function setConfig(newCfg, save) {
125
125
  const version = lodash_1.default.isString(newCfg.version) ? new Version(newCfg.version) : undefined;
126
126
  // first time we consider also CLI args
127
- const argCfg = !started && lodash_1.default.pickBy((0, misc_1.newObj)(configProps, (x, k) => const_1.argv[k]), x => x !== undefined);
127
+ const argCfg = !started && lodash_1.default.pickBy((0, misc_1.newObj)(configProps, (x, k) => { var _a; return (_a = const_1.argv[k]) !== null && _a !== void 0 ? _a : (0, misc_1.tryJson)(process.env['HFS_' + k.toUpperCase()], lodash_1.default.identity); }), x => x !== undefined);
128
128
  if (!lodash_1.default.isEmpty(argCfg)) {
129
129
  (0, exports.saveConfigAsap)(); // don't set `save` argument, as it would interfere below at check `save===false`
130
130
  Object.assign(newCfg, argCfg);
package/src/const.js CHANGED
@@ -38,11 +38,11 @@ exports.DEV = process.env.DEV || exports.argv.dev ? 'DEV' : '';
38
38
  exports.ORIGINAL_CWD = process.cwd();
39
39
  exports.HFS_STARTED = new Date();
40
40
  const PKG_PATH = (0, path_1.join)(__dirname, '..', 'package.json');
41
- exports.BUILD_TIMESTAMP = "2023-09-17T18:48:53.971Z";
41
+ exports.BUILD_TIMESTAMP = "2023-09-20T22:00:36.550Z";
42
42
  const pkg = JSON.parse(fs.readFileSync(PKG_PATH, 'utf8'));
43
43
  exports.VERSION = pkg.version;
44
44
  exports.RUNNING_BETA = exports.VERSION.includes('-');
45
- exports.API_VERSION = 8.3;
45
+ exports.API_VERSION = 8.4;
46
46
  exports.COMPATIBLE_API_VERSION = 1; // while changes in the api are not breaking, this number stays the same, otherwise it is made equal to API_VERSION
47
47
  exports.HFS_REPO = 'rejetto/hfs';
48
48
  exports.HFS_REPO_BRANCH = exports.RUNNING_BETA ? 'next' : 'main';
package/src/cross.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.xlate = exports.isEqualLax = exports.isWindowsDrive = exports.isIP = exports.isPrimitive = exports.formatTimestamp = exports.repeat = exports.asyncGeneratorToArray = exports.filterMapGenerator = exports.throw_ = exports.hasProp = exports.typedEntries = exports.typedKeys = exports.objRenameKey = exports.randomId = exports.getOrSet = exports.waitFor = exports.newObj = exports.removeStarting = exports.findDefined = exports.isOrderedEqual = exports.swap = exports.tryJson = exports.basename = exports.pendingPromise = exports._log = exports.wantArray = exports.formatPerc = exports.with_ = exports.try_ = exports.setHidden = exports.onlyTruthy = exports.truthy = exports.enforceFinal = exports.objSameKeys = exports.wait = exports.prefix = exports.formatBytes = exports.DAY = exports.HOUR = exports.MINUTE = exports.WIKI_URL = exports.REPO_URL = void 0;
6
+ exports.xlate = exports.isEqualLax = exports.isWindowsDrive = exports.isIP = exports.isPrimitive = exports.formatTimestamp = exports.repeat = exports.asyncGeneratorToArray = exports.filterMapGenerator = exports.throw_ = exports.hasProp = exports.typedEntries = exports.typedKeys = exports.objRenameKey = exports.randomId = exports.getOrSet = exports.waitFor = exports.newObj = exports.removeStarting = exports.findDefined = exports.isOrderedEqual = exports.swap = exports.tryJson = exports.basename = exports.pendingPromise = exports._log = exports.wantArray = exports.formatPerc = exports.with_ = exports.try_ = exports.setHidden = exports.onlyTruthy = exports.truthy = exports.enforceFinal = exports.objSameKeys = exports.haveTimeout = exports.wait = exports.prefix = exports.formatBytes = exports.MAX_TILES_SIZE = exports.DAY = exports.HOUR = exports.MINUTE = exports.WIKI_URL = exports.REPO_URL = void 0;
7
7
  // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
8
8
  // all content here is shared between client and server
9
9
  const lodash_1 = __importDefault(require("lodash"));
@@ -12,6 +12,7 @@ exports.WIKI_URL = exports.REPO_URL + 'wiki/';
12
12
  exports.MINUTE = 60000;
13
13
  exports.HOUR = 60 * exports.MINUTE;
14
14
  exports.DAY = 24 * exports.HOUR;
15
+ exports.MAX_TILES_SIZE = 10;
15
16
  const MULTIPLIERS = ['', 'K', 'M', 'G', 'T'];
16
17
  function formatBytes(n, { post = 'B', k = 1024, digits = NaN } = {}) {
17
18
  if (isNaN(Number(n)) || n < 0)
@@ -31,6 +32,10 @@ function wait(ms, val) {
31
32
  return new Promise(res => setTimeout(res, ms, val));
32
33
  }
33
34
  exports.wait = wait;
35
+ function haveTimeout(ms, job, error) {
36
+ return Promise.race([job, wait(ms).then(() => { throw error; })]);
37
+ }
38
+ exports.haveTimeout = haveTimeout;
34
39
  function objSameKeys(src, newValue) {
35
40
  return Object.fromEntries(Object.entries(src).map(([k, v]) => [k, newValue(v, k)]));
36
41
  }
@@ -91,11 +96,13 @@ function basename(path) {
91
96
  return path.slice(path.lastIndexOf('/') + 1 || path.lastIndexOf('\\') + 1);
92
97
  }
93
98
  exports.basename = basename;
94
- function tryJson(s) {
99
+ function tryJson(s, except) {
95
100
  try {
96
101
  return s && JSON.parse(s);
97
102
  }
98
- catch (_a) { }
103
+ catch (_a) {
104
+ return except === null || except === void 0 ? void 0 : except(s);
105
+ }
99
106
  }
100
107
  exports.tryJson = tryJson;
101
108
  function swap(obj, k1, k2) {
package/src/plugins.js CHANGED
@@ -155,7 +155,11 @@ const pluginsMiddleware = async (ctx, next) => {
155
155
  var _a;
156
156
  const after = {};
157
157
  // run middleware plugins
158
- for (const [id, pl] of Object.entries(plugins).concat([['.', await serverCode.compiled()]]))
158
+ const entries = Object.entries(plugins);
159
+ const sc = await serverCode.compiled();
160
+ if (sc)
161
+ entries.push(['.', await serverCode.compiled()]);
162
+ for (const [id, pl] of entries)
159
163
  try {
160
164
  const res = await ((_a = pl.middleware) === null || _a === void 0 ? void 0 : _a.call(pl, ctx));
161
165
  if (res === true)
@@ -119,6 +119,7 @@ async function treatIndex(ctx, filesUri, body) {
119
119
  prefixUrl: ctx.state.revProxyPath,
120
120
  customHtml: lodash_1.default.omit(Object.fromEntries(customHtml_1.customHtmlState.sections), ['top', 'bottom']),
121
121
  fileMenuOnLink: fileMenuOnLink.get(),
122
+ tilesSize: tilesSize.get(),
122
123
  lang
123
124
  }, null, 4)
124
125
  .replace(/<(\/script)/g, '<"+"$1') /*avoid breaking our script container*/}
@@ -174,3 +175,4 @@ function serveGuiFiles(proxyPort, uri) {
174
175
  }
175
176
  exports.serveGuiFiles = serveGuiFiles;
176
177
  const fileMenuOnLink = (0, config_1.defineConfig)('file_menu_on_link', true);
178
+ const tilesSize = (0, config_1.defineConfig)('tiles_size', 0);
package/src/update.js CHANGED
@@ -20,7 +20,8 @@ async function getUpdates() {
20
20
  const stable = await (0, github_1.getRepoInfo)(const_1.HFS_REPO + '/releases/latest');
21
21
  const verStable = ver(stable);
22
22
  const ret = await getBetas();
23
- if (stable && (config_1.currentVersion.olderThan(stable.tag_name) || const_1.RUNNING_BETA)) // if we are running a beta, also offer the latest stable
23
+ stable.isNewer = config_1.currentVersion.olderThan(stable.tag_name) || const_1.RUNNING_BETA;
24
+ if (stable.isNewer)
24
25
  ret.push(stable);
25
26
  return ret;
26
27
  function ver(x) {