hfs 0.47.3 → 0.48.0-alpha2

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 (41) hide show
  1. package/admin/assets/index-1c2b890b.css +1 -0
  2. package/admin/assets/index-344723f8.js +520 -0
  3. package/{frontend/assets/sha512-108e3b0a.js → admin/assets/sha512-136b5a7c.js} +1 -1
  4. package/admin/index.html +2 -2
  5. package/frontend/assets/index-05dfd82f.css +1 -0
  6. package/frontend/assets/{index-7eec0199.js → index-12411ff6.js} +15 -15
  7. package/{admin/assets/sha512-0935647a.js → frontend/assets/sha512-549e6c3a.js} +1 -1
  8. package/frontend/index.html +2 -2
  9. package/package.json +20 -13
  10. package/plugins/vhosting/plugin.js +15 -15
  11. package/src/adminApis.js +7 -4
  12. package/src/api.auth.js +0 -3
  13. package/src/api.file_list.js +8 -7
  14. package/src/api.lang.js +1 -1
  15. package/src/api.net.js +136 -0
  16. package/src/api.plugins.js +31 -36
  17. package/src/api.vfs.js +1 -1
  18. package/src/apiMiddleware.js +22 -20
  19. package/src/config.js +2 -16
  20. package/src/const.js +4 -2
  21. package/src/cross.js +221 -0
  22. package/src/customHtml.js +7 -22
  23. package/src/debounceAsync.js +12 -9
  24. package/src/frontEndApis.js +2 -4
  25. package/src/github.js +86 -40
  26. package/src/langs/embedded.js +2 -1
  27. package/src/langs/hfs-lang-de.json +131 -0
  28. package/src/langs/hfs-lang-it.json +1 -1
  29. package/src/listen.js +44 -37
  30. package/src/log.js +8 -5
  31. package/src/middlewares.js +1 -3
  32. package/src/misc.js +33 -137
  33. package/src/plugins.js +46 -26
  34. package/src/serveFile.js +1 -0
  35. package/src/update.js +1 -1
  36. package/src/upload.js +2 -1
  37. package/src/util-http.js +11 -8
  38. package/admin/assets/index-62247236.css +0 -1
  39. package/admin/assets/index-ca5ac85e.js +0 -518
  40. package/frontend/assets/index-0ea37f5f.css +0 -1
  41. package/src/util-generators.js +0 -31
package/src/plugins.js CHANGED
@@ -114,8 +114,12 @@ function mapPlugins(cb) {
114
114
  }
115
115
  exports.mapPlugins = mapPlugins;
116
116
  function findPluginByRepo(repo) {
117
- return lodash_1.default.find(plugins, pl => { var _a; return ((_a = pl.getData()) === null || _a === void 0 ? void 0 : _a.repo) === repo; })
118
- || lodash_1.default.find(availablePlugins, { repo });
117
+ return lodash_1.default.find(plugins, pl => match(pl.getData()))
118
+ || lodash_1.default.find(availablePlugins, match);
119
+ function match(rec) {
120
+ var _a, _b;
121
+ return repo === ((_b = (_a = rec === null || rec === void 0 ? void 0 : rec.repo) === null || _a === void 0 ? void 0 : _a.main) !== null && _b !== void 0 ? _b : rec === null || rec === void 0 ? void 0 : rec.repo);
122
+ }
119
123
  }
120
124
  exports.findPluginByRepo = findPluginByRepo;
121
125
  function getPluginConfigFields(id) {
@@ -123,11 +127,35 @@ function getPluginConfigFields(id) {
123
127
  return (_a = plugins[id]) === null || _a === void 0 ? void 0 : _a.getData().config;
124
128
  }
125
129
  exports.getPluginConfigFields = getPluginConfigFields;
130
+ const serverCode = (0, config_1.defineConfig)('server_code', '', async (script, { k }) => {
131
+ const res = {};
132
+ try {
133
+ new Function('exports', script)(res); // parse
134
+ return await initPlugin(res);
135
+ }
136
+ catch (e) {
137
+ return console.error(k + ':', e.message || String(e));
138
+ }
139
+ });
140
+ async function initPlugin(pl, more) {
141
+ var _a;
142
+ return Object.assign(pl, await ((_a = pl.init) === null || _a === void 0 ? void 0 : _a.call(pl, {
143
+ const: Const,
144
+ Const,
145
+ require,
146
+ getConnections: connections_1.getConnections,
147
+ events: events_1.default,
148
+ log: console.log,
149
+ getHfsConfig: config_1.getConfig,
150
+ customApiCall,
151
+ ...more
152
+ })));
153
+ }
126
154
  const pluginsMiddleware = async (ctx, next) => {
127
155
  var _a;
128
156
  const after = {};
129
157
  // run middleware plugins
130
- for (const [id, pl] of Object.entries(plugins))
158
+ for (const [id, pl] of Object.entries(plugins).concat([['.', await serverCode.compiled()]]))
131
159
  try {
132
160
  const res = await ((_a = pl.middleware) === null || _a === void 0 ? void 0 : _a.call(pl, ctx));
133
161
  if (res === true)
@@ -324,27 +352,22 @@ function watchPlugin(id, path) {
324
352
  setError(id, '');
325
353
  const alreadyRunning = plugins[id];
326
354
  console.log(alreadyRunning ? "reloading plugin" : "loading plugin", id);
327
- const { init, ...data } = await (_a = module, Promise.resolve().then(() => __importStar(require(_a))));
328
- delete data.default;
355
+ const pluginData = await (_a = module, Promise.resolve().then(() => __importStar(require(_a))));
329
356
  deleteModule(require.resolve(module)); // avoid caching at next import
330
- calculateBadApi(data);
331
- if (data.badApi)
332
- console.log("plugin", id, data.badApi);
357
+ calculateBadApi(pluginData);
358
+ if (pluginData.badApi)
359
+ console.log("plugin", id, pluginData.badApi);
333
360
  await (alreadyRunning === null || alreadyRunning === void 0 ? void 0 : alreadyRunning.unload(true));
334
361
  console.debug("starting plugin", id);
335
362
  const storageDir = (0, path_1.resolve)(module, '..', exports.STORAGE_FOLDER) + (const_1.IS_WINDOWS ? '\\' : '/');
336
363
  await (0, promises_1.mkdir)(storageDir, { recursive: true });
337
- const res = await (init === null || init === void 0 ? void 0 : init.call(null, {
364
+ await initPlugin(pluginData, {
338
365
  srcDir: __dirname,
339
366
  storageDir,
340
- const: Const,
341
- require,
342
- getConnections: connections_1.getConnections,
343
- events: events_1.default,
344
367
  log(...args) {
345
368
  console.log('plugin', id + ':', ...args);
346
369
  },
347
- getConfig: (cfgKey) => { var _a, _b, _c, _d, _e; return (_c = (_b = (_a = exports.pluginsConfig.get()) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b[cfgKey]) !== null && _c !== void 0 ? _c : (_e = (_d = data.config) === null || _d === void 0 ? void 0 : _d[cfgKey]) === null || _e === void 0 ? void 0 : _e.defaultValue; },
370
+ getConfig: (cfgKey) => { var _a, _b, _c, _d, _e; return (_c = (_b = (_a = exports.pluginsConfig.get()) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b[cfgKey]) !== null && _c !== void 0 ? _c : (_e = (_d = pluginData.config) === null || _d === void 0 ? void 0 : _d[cfgKey]) === null || _e === void 0 ? void 0 : _e.defaultValue; },
348
371
  setConfig: (cfgKey, value) => setPluginConfig(id, { [cfgKey]: value }),
349
372
  subscribeConfig(cfgKey, cb) {
350
373
  let last = this.getConfig(cfgKey);
@@ -357,21 +380,15 @@ function watchPlugin(id, path) {
357
380
  cb(last = now);
358
381
  }
359
382
  catch (e) {
360
- console.log('plugin', id, String(e));
383
+ this.log(String(e));
361
384
  }
362
385
  });
363
386
  },
364
- getHfsConfig: config_1.getConfig,
365
- customApiCall(method, params) {
366
- return mapPlugins(pl => { var _a, _b; return (_b = (_a = pl.getData().customApi) === null || _a === void 0 ? void 0 : _a[method]) === null || _b === void 0 ? void 0 : _b.call(_a, params); });
367
- }
368
- }));
369
- const folder = (0, path_1.dirname)(module);
370
- Object.assign(data, res, {
371
- customHtml: (0, customHtml_1.newCustomHtmlState)()
372
387
  });
373
- const customHtmlWatcher = (0, customHtml_1.watchLoadCustomHtml)(data.customHtml, folder);
374
- const plugin = plugins[id] = new Plugin(id, folder, data, customHtmlWatcher.unwatch);
388
+ const folder = (0, path_1.dirname)(module);
389
+ const { state, unwatch } = (0, customHtml_1.watchLoadCustomHtml)(folder);
390
+ pluginData.customHtml = state;
391
+ const plugin = plugins[id] = new Plugin(id, folder, pluginData, unwatch);
375
392
  if (alreadyRunning)
376
393
  events_1.default.emit('pluginUpdated', Object.assign(lodash_1.default.pick(plugin, 'started'), getPluginInfo(id)));
377
394
  else {
@@ -393,6 +410,9 @@ function watchPlugin(id, path) {
393
410
  }
394
411
  }
395
412
  }
413
+ function customApiCall(method, params) {
414
+ return mapPlugins(pl => { var _a, _b; return (_b = (_a = pl.getData().customApi) === null || _a === void 0 ? void 0 : _a[method]) === null || _b === void 0 ? void 0 : _b.call(_a, params); });
415
+ }
396
416
  function getError(id) {
397
417
  return getPluginInfo(id).error;
398
418
  }
@@ -428,7 +448,7 @@ function parsePluginSource(id, source) {
428
448
  var _a, _b, _c, _d, _e, _f, _g, _h;
429
449
  const pl = { id };
430
450
  pl.description = (0, misc_1.tryJson)((_a = /exports.description *= *(".*")/.exec(source)) === null || _a === void 0 ? void 0 : _a[1]);
431
- pl.repo = (_b = /exports.repo *= *"(.*)"/.exec(source)) === null || _b === void 0 ? void 0 : _b[1];
451
+ pl.repo = (0, misc_1.tryJson)((_b = /exports.repo *= *(.*);? *$/m.exec(source)) === null || _b === void 0 ? void 0 : _b[1]);
432
452
  pl.version = (_d = Number((_c = /exports.version *= *(\d*\.?\d+)/.exec(source)) === null || _c === void 0 ? void 0 : _c[1])) !== null && _d !== void 0 ? _d : undefined;
433
453
  pl.apiRequired = (_f = (0, misc_1.tryJson)((_e = /exports.apiRequired *= *([ \d.,[\]]+)/.exec(source)) === null || _e === void 0 ? void 0 : _e[1])) !== null && _f !== void 0 ? _f : undefined;
434
454
  pl.depend = (_h = (0, misc_1.tryJson)((_g = /exports.depend *= *(\[.*\])/m.exec(source)) === null || _g === void 0 ? void 0 : _g[1])) === null || _h === void 0 ? void 0 : _h.filter((x) => typeof x.repo === 'string' && x.version === undefined || typeof x.version === 'number'
package/src/serveFile.js CHANGED
@@ -86,6 +86,7 @@ function getRange(ctx, totalSize) {
86
86
  ctx.set('Accept-Ranges', 'bytes');
87
87
  const { range } = ctx.request.header;
88
88
  if (!range) {
89
+ ctx.state.includesLastByte = true;
89
90
  ctx.response.length = totalSize;
90
91
  return;
91
92
  }
package/src/update.js CHANGED
@@ -79,7 +79,7 @@ async function update(tag) {
79
79
  throw "asset not found";
80
80
  const url = asset.browser_download_url;
81
81
  console.log("downloading", url);
82
- updateSource = await (0, misc_1.httpsStream)(url);
82
+ updateSource = await (0, misc_1.httpStream)(url);
83
83
  }
84
84
  const bin = process.execPath;
85
85
  const binPath = (0, path_1.dirname)(bin);
package/src/upload.js CHANGED
@@ -117,8 +117,9 @@ function uploadWriter(base, path, ctx) {
117
117
  const conn = (0, connections_1.socket2connection)(ctx.socket);
118
118
  if (!conn)
119
119
  return () => { };
120
- ctx.state.uploadPath = ctx.path + path;
121
120
  const opTotal = reqSize + resume;
121
+ ctx.state.uploadPath = ctx.path + path;
122
+ ctx.state.uploadSize = opTotal;
122
123
  (0, connections_1.updateConnection)(conn, { ctx, op: 'upload', opTotal, opOffset: resume / opTotal });
123
124
  const h = setInterval(() => {
124
125
  const now = Date.now();
package/src/util-http.js CHANGED
@@ -4,11 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.httpsStream = exports.httpsString = void 0;
7
+ exports.httpStream = exports.httpString = void 0;
8
+ const node_http_1 = __importDefault(require("node:http"));
8
9
  const node_https_1 = __importDefault(require("node:https"));
9
10
  const const_1 = require("./const");
10
- function httpsString(url, options) {
11
- return httpsStream(url, options).then(res => new Promise(resolve => {
11
+ function httpString(url, options) {
12
+ return httpStream(url, options).then(res => new Promise(resolve => {
12
13
  let buf = '';
13
14
  res.on('data', chunk => buf += chunk.toString());
14
15
  res.on('end', () => resolve(Object.assign(res, {
@@ -17,16 +18,18 @@ function httpsString(url, options) {
17
18
  })));
18
19
  }));
19
20
  }
20
- exports.httpsString = httpsString;
21
- function httpsStream(url, { body, ...options } = {}) {
21
+ exports.httpString = httpString;
22
+ function httpStream(url, { body, ...options } = {}) {
22
23
  return new Promise((resolve, reject) => {
23
24
  if (body)
24
25
  options.method || (options.method = 'POST');
25
- const req = node_https_1.default.request(url, options, res => {
26
+ const proto = url.startsWith('https:') ? node_https_1.default : node_http_1.default;
27
+ const req = proto.request(url, options, res => {
28
+ console.debug("http responded", res.statusCode, "to", url);
26
29
  if (!res.statusCode || res.statusCode >= 400)
27
30
  return reject(new Error(String(res.statusCode), { cause: res }));
28
31
  if (res.statusCode === const_1.HTTP_TEMPORARY_REDIRECT && res.headers.location)
29
- return resolve(httpsStream(res.headers.location, options));
32
+ return resolve(httpStream(res.headers.location, options));
30
33
  resolve(res);
31
34
  }).on('error', e => {
32
35
  reject(req.res || e);
@@ -36,4 +39,4 @@ function httpsStream(url, { body, ...options } = {}) {
36
39
  req.end();
37
40
  });
38
41
  }
39
- exports.httpsStream = httpsStream;
42
+ exports.httpStream = httpStream;
@@ -1 +0,0 @@
1
- :root{height:100dvh}body{margin:0;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;height:100vh;background:#000}#root{min-height:100%;display:flex}main{word-break:break-word}code{font-family:source-code-pro,Menlo,Monaco,Consolas,Courier New,monospace}.MuiTreeItem-content{box-sizing:border-box}.MuiDataGrid-columnHeaders{background-color:#8882}ol,ul{margin-top:.2em}