hfs 0.38.2 → 0.40.0
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/README.md +27 -2
- package/admin/assets/index-d654b69c.js +510 -0
- package/{frontend/assets/sha512-57b80c96.js → admin/assets/sha512-e2cf8296.js} +1 -1
- package/admin/index.html +1 -1
- package/frontend/assets/index-31f0430a.js +94 -0
- package/frontend/assets/index-ffbcd4c9.css +1 -0
- package/{admin/assets/sha512-7ecaaeed.js → frontend/assets/sha512-5acbfc40.js} +1 -1
- package/frontend/fontello.css +10 -12
- package/frontend/fontello.woff2 +0 -0
- package/frontend/index.html +2 -2
- package/package.json +1 -1
- package/plugins/vhosting/plugin.js +1 -1
- package/src/api.auth.js +1 -1
- package/src/api.file_list.js +3 -1
- package/src/api.lang.js +8 -4
- package/src/api.monitor.js +9 -4
- package/src/api.vfs.js +7 -2
- package/src/apiMiddleware.js +4 -2
- package/src/const.js +1 -1
- package/src/index.js +1 -0
- package/src/log.js +39 -35
- package/src/middlewares.js +7 -6
- package/src/misc.js +6 -2
- package/src/plugins.js +17 -8
- package/src/serveFile.js +47 -49
- package/src/serveGuiFiles.js +14 -12
- package/src/throttler.js +2 -0
- package/src/vfs.js +8 -7
- package/admin/assets/index-c7c100fa.js +0 -509
- package/frontend/assets/index-4b763f31.js +0 -94
- package/frontend/assets/index-6d4e81f7.css +0 -1
package/src/serveGuiFiles.js
CHANGED
|
@@ -59,14 +59,14 @@ function serveStatic(uri) {
|
|
|
59
59
|
const content = await (0, misc_1.getOrSet)(cache, ctx.path, async () => {
|
|
60
60
|
const data = await promises_1.default.readFile(fullPath).catch(() => null);
|
|
61
61
|
return serveApp || !data ? data
|
|
62
|
-
: adjustBundlerLinks(ctx
|
|
62
|
+
: adjustBundlerLinks(ctx, uri, data);
|
|
63
63
|
});
|
|
64
64
|
if (content === null)
|
|
65
65
|
return ctx.status = const_1.HTTP_NOT_FOUND;
|
|
66
66
|
if (!serveApp)
|
|
67
|
-
return (0, serveFile_1.serveFile)(fullPath, 'auto', content)
|
|
67
|
+
return (0, serveFile_1.serveFile)(ctx, fullPath, 'auto', content);
|
|
68
68
|
// we don't cache the index as it's small and may prevent plugins change to apply
|
|
69
|
-
ctx.body = await treatIndex(ctx, String(content)
|
|
69
|
+
ctx.body = await treatIndex(ctx, uri, String(content));
|
|
70
70
|
ctx.type = 'html';
|
|
71
71
|
ctx.set('Cache-Control', 'no-store, no-cache, must-revalidate');
|
|
72
72
|
};
|
|
@@ -75,17 +75,18 @@ function shouldServeApp(ctx) {
|
|
|
75
75
|
var _a;
|
|
76
76
|
return (_a = ctx.state).serveApp || (_a.serveApp = ctx.path.endsWith('/'));
|
|
77
77
|
}
|
|
78
|
-
function adjustBundlerLinks(
|
|
79
|
-
const ext = (0, path_1.extname)(path);
|
|
78
|
+
function adjustBundlerLinks(ctx, uri, data) {
|
|
79
|
+
const ext = (0, path_1.extname)(ctx.path);
|
|
80
80
|
return ext && !ext.match(/\.(css|html|js|ts|scss)/) ? data
|
|
81
|
-
: String(data).replace(/((?:import | from )['"])\//g, `$1${uri}`);
|
|
81
|
+
: String(data).replace(/((?:import | from )['"])\//g, `$1${ctx.state.revProxyPath}${uri}`);
|
|
82
82
|
}
|
|
83
|
-
async function treatIndex(ctx,
|
|
83
|
+
async function treatIndex(ctx, filesUri, body) {
|
|
84
84
|
const session = await (0, api_auth_1.refresh_session)({}, ctx);
|
|
85
85
|
ctx.set('etag', '');
|
|
86
86
|
const isFrontend = filesUri === const_1.FRONTEND_URI;
|
|
87
|
-
const
|
|
88
|
-
const
|
|
87
|
+
const pub = ctx.state.revProxyPath + const_1.PLUGINS_PUB_URI;
|
|
88
|
+
const css = (0, plugins_1.mapPlugins)((plug, k) => { var _a; return (_a = (isFrontend ? plug.frontend_css : null)) === null || _a === void 0 ? void 0 : _a.map(f => pub + k + '/' + f); }).flat().filter(Boolean);
|
|
89
|
+
const js = (0, plugins_1.mapPlugins)((plug, k) => { var _a; return (_a = (isFrontend ? plug.frontend_js : null)) === null || _a === void 0 ? void 0 : _a.map(f => pub + k + '/' + f); }).flat().filter(Boolean);
|
|
89
90
|
// expose plugins' configs that are declared with 'frontend' attribute
|
|
90
91
|
const plugins = Object.fromEntries((0, misc_1.onlyTruthy)((0, plugins_1.mapPlugins)((pl, name) => {
|
|
91
92
|
var _a, _b;
|
|
@@ -98,7 +99,7 @@ async function treatIndex(ctx, body, filesUri) {
|
|
|
98
99
|
return !lodash_1.default.isEmpty(configs) && [name, configs];
|
|
99
100
|
})));
|
|
100
101
|
let ret = body
|
|
101
|
-
.replace(/((?:src|href) *= *['"])\/?(?![a-z]+:\/\/)/g, '$1' + filesUri)
|
|
102
|
+
.replace(/((?:src|href) *= *['"])\/?(?![a-z]+:\/\/)/g, '$1' + ctx.state.revProxyPath + filesUri)
|
|
102
103
|
.replace('</head>', () => `
|
|
103
104
|
${!isFrontend ? '' : `
|
|
104
105
|
<title>${adminApis_1.title.get()}</title>
|
|
@@ -110,6 +111,7 @@ async function treatIndex(ctx, body, filesUri) {
|
|
|
110
111
|
API_VERSION: const_1.API_VERSION,
|
|
111
112
|
session: session instanceof apiMiddleware_1.ApiError ? null : session,
|
|
112
113
|
plugins,
|
|
114
|
+
prefixUrl: ctx.state.revProxyPath,
|
|
113
115
|
customHtml: lodash_1.default.omit(Object.fromEntries(customHtml_1.customHtmlState.sections), ['top', 'bottom']), // excluding sections we apply in this phase
|
|
114
116
|
}, null, 4)}
|
|
115
117
|
document.documentElement.setAttribute('ver', '${const_1.VERSION.split('-')[0] /*for style selectors*/}')
|
|
@@ -141,8 +143,8 @@ function serveProxied(port, uri) {
|
|
|
141
143
|
proxy = lib.default('127.0.0.1:' + port, {
|
|
142
144
|
proxyReqPathResolver: (ctx) => shouldServeApp(ctx) ? '/' : ctx.path,
|
|
143
145
|
userResDecorator(res, data, ctx) {
|
|
144
|
-
return shouldServeApp(ctx) ? treatIndex(ctx, String(data)
|
|
145
|
-
: adjustBundlerLinks(ctx
|
|
146
|
+
return shouldServeApp(ctx) ? treatIndex(ctx, uri, String(data))
|
|
147
|
+
: adjustBundlerLinks(ctx, uri, data);
|
|
146
148
|
}
|
|
147
149
|
}));
|
|
148
150
|
return function () {
|
package/src/throttler.js
CHANGED
|
@@ -65,6 +65,8 @@ const throttler = async (ctx, next) => {
|
|
|
65
65
|
ctx.body = ctx.body.pipe(ts);
|
|
66
66
|
if (bak)
|
|
67
67
|
ctx.response.length = bak;
|
|
68
|
+
ts.once('end', () => // in case of compressed response, we offer calculation of real size
|
|
69
|
+
ctx.state.length = ts.getBytesSent());
|
|
68
70
|
};
|
|
69
71
|
exports.throttler = throttler;
|
|
70
72
|
function roundSpeed(n) {
|
package/src/vfs.js
CHANGED
|
@@ -4,7 +4,7 @@ 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.cantReadStatusCode = exports.walkNode = exports.hasPermission = exports.nodeIsDirectory = exports.getNodeName = exports.saveVfs = exports.vfs = exports.urlToNode = exports.MIME_AUTO = exports.defaultPerms = void 0;
|
|
7
|
+
exports.cantReadStatusCode = exports.walkNode = exports.hasPermission = exports.nodeIsDirectory = exports.getNodeName = exports.saveVfs = exports.vfs = exports.urlToNode = exports.isSameFilenameAs = exports.MIME_AUTO = exports.defaultPerms = void 0;
|
|
8
8
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const micromatch_1 = require("micromatch");
|
|
@@ -14,7 +14,6 @@ const config_1 = require("./config");
|
|
|
14
14
|
const const_1 = require("./const");
|
|
15
15
|
const events_1 = __importDefault(require("./events"));
|
|
16
16
|
const perm_1 = require("./perm");
|
|
17
|
-
const misc_2 = require("./misc");
|
|
18
17
|
const WHO_ANYONE = true;
|
|
19
18
|
const WHO_NO_ONE = false;
|
|
20
19
|
const WHO_ANY_ACCOUNT = '*';
|
|
@@ -38,6 +37,11 @@ function inheritFromParent(parent, child) {
|
|
|
38
37
|
child.mime || (child.mime = parent.mime);
|
|
39
38
|
return child;
|
|
40
39
|
}
|
|
40
|
+
function isSameFilenameAs(name) {
|
|
41
|
+
const lc = name.toLowerCase();
|
|
42
|
+
return (other) => lc === (typeof other === 'string' ? other : getNodeName(other)).toLowerCase();
|
|
43
|
+
}
|
|
44
|
+
exports.isSameFilenameAs = isSameFilenameAs;
|
|
41
45
|
async function urlToNode(url, ctx, parent = exports.vfs, getRest) {
|
|
42
46
|
var _a;
|
|
43
47
|
let initialSlashes = 0;
|
|
@@ -54,9 +58,7 @@ async function urlToNode(url, ctx, parent = exports.vfs, getRest) {
|
|
|
54
58
|
return;
|
|
55
59
|
}
|
|
56
60
|
// does the tree node have a child that goes by this name?
|
|
57
|
-
const
|
|
58
|
-
: (0, misc_2.with_)(name.toLowerCase(), lc => (x) => x.toLowerCase() === lc);
|
|
59
|
-
const child = (_a = parent.children) === null || _a === void 0 ? void 0 : _a.find(x => sameName(getNodeName(x)));
|
|
61
|
+
const child = (_a = parent.children) === null || _a === void 0 ? void 0 : _a.find(isSameFilenameAs(name));
|
|
60
62
|
const ret = {
|
|
61
63
|
...child,
|
|
62
64
|
original: child,
|
|
@@ -124,8 +126,7 @@ exports.nodeIsDirectory = nodeIsDirectory;
|
|
|
124
126
|
function hasPermission(node, perm, ctx) {
|
|
125
127
|
var _a;
|
|
126
128
|
return (node.source || perm !== 'can_upload') // Upload possible only if we know where to store. First check node.source because is supposedly faster.
|
|
127
|
-
&& matchWho((_a = node[perm]) !== null && _a !== void 0 ? _a : exports.defaultPerms[perm], ctx)
|
|
128
|
-
&& (perm !== 'can_see' || hasPermission(node, 'can_read', ctx)); // can_see is used to hide something you nonetheless can_read, so you MUST also can_read
|
|
129
|
+
&& matchWho((_a = node[perm]) !== null && _a !== void 0 ? _a : exports.defaultPerms[perm], ctx);
|
|
129
130
|
}
|
|
130
131
|
exports.hasPermission = hasPermission;
|
|
131
132
|
async function* walkNode(parent, ctx, depth = 0, prefixPath = '') {
|