hfs 0.47.2 → 0.48.0-alpha1
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/admin/assets/index-12bfad23.js +520 -0
- package/admin/assets/{index-62247236.css → index-5f04953d.css} +1 -1
- package/{frontend/assets/sha512-108e3b0a.js → admin/assets/sha512-888f0eaa.js} +1 -1
- package/admin/index.html +2 -2
- package/frontend/assets/index-05dfd82f.css +1 -0
- package/frontend/assets/{index-7eec0199.js → index-12411ff6.js} +15 -15
- package/{admin/assets/sha512-0935647a.js → frontend/assets/sha512-549e6c3a.js} +1 -1
- package/frontend/index.html +2 -2
- package/package.json +20 -13
- package/plugins/vhosting/plugin.js +15 -15
- package/src/adminApis.js +4 -2
- package/src/api.auth.js +0 -3
- package/src/api.file_list.js +8 -7
- package/src/api.lang.js +1 -1
- package/src/api.net.js +133 -0
- package/src/api.plugins.js +31 -36
- package/src/api.vfs.js +1 -1
- package/src/apiMiddleware.js +22 -20
- package/src/config.js +2 -16
- package/src/const.js +4 -2
- package/src/cross.js +221 -0
- package/src/customHtml.js +7 -22
- package/src/debounceAsync.js +12 -9
- package/src/frontEndApis.js +2 -4
- package/src/github.js +86 -40
- package/src/langs/embedded.js +2 -1
- package/src/langs/hfs-lang-de.json +131 -0
- package/src/langs/hfs-lang-it.json +1 -1
- package/src/listen.js +49 -40
- package/src/log.js +3 -3
- package/src/middlewares.js +9 -6
- package/src/misc.js +33 -137
- package/src/plugins.js +46 -26
- package/src/update.js +1 -1
- package/src/util-http.js +11 -8
- package/src/util-os.js +1 -1
- package/admin/assets/index-ca5ac85e.js +0 -518
- package/frontend/assets/index-0ea37f5f.css +0 -1
- 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 =>
|
|
118
|
-
|| lodash_1.default.find(availablePlugins,
|
|
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
|
|
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(
|
|
331
|
-
if (
|
|
332
|
-
console.log("plugin", id,
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
374
|
-
const
|
|
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 *= *
|
|
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/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.
|
|
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/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.
|
|
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
|
|
11
|
-
return
|
|
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.
|
|
21
|
-
function
|
|
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
|
|
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(
|
|
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.
|
|
42
|
+
exports.httpStream = httpStream;
|
package/src/util-os.js
CHANGED
|
@@ -16,7 +16,7 @@ function getFreeDiskSync(path) {
|
|
|
16
16
|
throw Error('miss');
|
|
17
17
|
return Number((_a = /FreeSpace=(\d+)/.exec(one)) === null || _a === void 0 ? void 0 : _a[1]);
|
|
18
18
|
}
|
|
19
|
-
const out = (0, misc_1.try_)(() => (0, child_process_1.execSync)(`df -k ${path}`).toString(), err => {
|
|
19
|
+
const out = (0, misc_1.try_)(() => (0, child_process_1.execSync)(`df -k "${path}"`).toString(), err => {
|
|
20
20
|
throw err.status === 1 ? Error('miss')
|
|
21
21
|
: err.status === 127 ? Error('unsupported')
|
|
22
22
|
: err;
|