hfs 0.49.0-alpha1 → 0.49.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.
- package/README.md +1 -1
- package/admin/assets/index-6afd4b06.js +542 -0
- package/{frontend/assets/sha512-82ed8772.js → admin/assets/sha512-f5f12dc1.js} +1 -1
- package/admin/index.html +1 -1
- package/central.json +30 -8
- package/frontend/assets/index-3a379840.js +94 -0
- package/frontend/assets/index-db5f0e4b.css +1 -0
- package/{admin/assets/sha512-ae917116.js → frontend/assets/sha512-3392c31f.js} +1 -1
- package/frontend/index.html +2 -2
- package/package.json +1 -2
- package/src/api.auth.js +6 -6
- package/src/api.file_list.js +10 -27
- package/src/api.net.js +59 -58
- package/src/api.plugins.js +14 -25
- package/src/api.vfs.js +9 -12
- package/src/block.js +14 -1
- package/src/comments.js +49 -0
- package/src/const.js +3 -2
- package/src/cross.js +29 -1
- package/src/debounceAsync.js +17 -1
- package/src/frontEndApis.js +28 -6
- package/src/github.js +24 -30
- package/src/langs/hfs-lang-it.json +5 -3
- package/src/langs/hfs-lang-ru.json +6 -4
- package/src/listen.js +3 -2
- package/src/middlewares.js +3 -1
- package/src/misc.js +4 -4
- package/src/perm.js +19 -12
- package/src/plugins.js +33 -12
- package/src/serveFile.js +2 -3
- package/src/upload.js +5 -1
- package/src/util-http.js +8 -6
- package/src/vfs.js +24 -32
- package/src/watchLoad.js +5 -12
- package/src/zip.js +4 -4
- package/admin/assets/index-b34ac7b4.js +0 -536
- package/frontend/assets/index-4cbc2ffc.js +0 -94
- package/frontend/assets/index-cbe043ee.css +0 -1
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.parentMaskApplier = exports.masksCouldGivePermission = exports.walkNode = exports.statusCodeForMissingPerm = exports.hasPermission = exports.nodeIsDirectory = exports.getNodeName = exports.saveVfs = exports.vfs = exports.urlToNode = exports.applyParentToChild = exports.isSameFilenameAs = exports.
|
|
7
|
+
exports.parentMaskApplier = exports.masksCouldGivePermission = exports.walkNode = exports.statusCodeForMissingPerm = exports.hasPermission = exports.nodeIsDirectory = exports.getNodeName = exports.saveVfs = exports.vfs = exports.urlToNode = exports.applyParentToChild = exports.isSameFilenameAs = exports.permsFromParent = exports.MIME_AUTO = void 0;
|
|
8
8
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const misc_1 = require("./misc");
|
|
@@ -13,46 +13,38 @@ const config_1 = require("./config");
|
|
|
13
13
|
const const_1 = require("./const");
|
|
14
14
|
const events_1 = __importDefault(require("./events"));
|
|
15
15
|
const perm_1 = require("./perm");
|
|
16
|
-
exports.WHO_ANYONE = true;
|
|
17
|
-
exports.WHO_NO_ONE = false;
|
|
18
|
-
exports.WHO_ANY_ACCOUNT = '*';
|
|
19
|
-
exports.defaultPerms = {
|
|
20
|
-
can_see: 'can_read',
|
|
21
|
-
can_read: exports.WHO_ANYONE,
|
|
22
|
-
can_list: 'can_read',
|
|
23
|
-
can_upload: exports.WHO_NO_ONE,
|
|
24
|
-
can_delete: exports.WHO_NO_ONE,
|
|
25
|
-
};
|
|
26
|
-
exports.PERM_KEYS = (0, misc_1.typedKeys)(exports.defaultPerms);
|
|
27
16
|
exports.MIME_AUTO = 'auto';
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
for (const k of
|
|
17
|
+
function permsFromParent(parent, child) {
|
|
18
|
+
const ret = {};
|
|
19
|
+
for (const k of misc_1.PERM_KEYS) {
|
|
31
20
|
let p = parent;
|
|
32
21
|
let inheritedPerm;
|
|
33
22
|
while (p) {
|
|
34
23
|
inheritedPerm = p[k];
|
|
35
|
-
//
|
|
36
|
-
if (!isWhoObject(inheritedPerm))
|
|
24
|
+
// in case of object without children, parent is skipped in favor of the parent's parent
|
|
25
|
+
if (!(0, misc_1.isWhoObject)(inheritedPerm))
|
|
37
26
|
break;
|
|
38
27
|
inheritedPerm = inheritedPerm.children;
|
|
39
28
|
if (inheritedPerm !== undefined)
|
|
40
29
|
break;
|
|
41
30
|
p = p.parent;
|
|
42
31
|
}
|
|
43
|
-
if (inheritedPerm !== undefined) // small optimization: don't expand the object
|
|
44
|
-
|
|
32
|
+
if (inheritedPerm !== undefined && child[k] === undefined) // small optimization: don't expand the object
|
|
33
|
+
ret[k] = inheritedPerm;
|
|
45
34
|
}
|
|
35
|
+
return lodash_1.default.isEmpty(ret) ? undefined : ret;
|
|
36
|
+
}
|
|
37
|
+
exports.permsFromParent = permsFromParent;
|
|
38
|
+
function inheritFromParent(parent, child) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
Object.assign(child, permsFromParent(parent, child));
|
|
46
41
|
if (typeof parent.mime === 'object' && typeof child.mime === 'object')
|
|
47
42
|
lodash_1.default.defaults(child.mime, parent.mime);
|
|
48
43
|
else
|
|
49
|
-
(
|
|
50
|
-
(
|
|
44
|
+
(_a = child.mime) !== null && _a !== void 0 ? _a : (child.mime = parent.mime);
|
|
45
|
+
(_b = child.accept) !== null && _b !== void 0 ? _b : (child.accept = parent.accept);
|
|
51
46
|
return child;
|
|
52
47
|
}
|
|
53
|
-
function isWhoObject(v) {
|
|
54
|
-
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
55
|
-
}
|
|
56
48
|
function isSameFilenameAs(name) {
|
|
57
49
|
const lc = name.toLowerCase();
|
|
58
50
|
return (other) => lc === (typeof other === 'string' ? other : getNodeName(other)).toLowerCase();
|
|
@@ -183,25 +175,25 @@ function statusCodeForMissingPerm(node, perm, ctx, assign = true) {
|
|
|
183
175
|
return const_1.HTTP_FORBIDDEN;
|
|
184
176
|
// calculate value of permission resolving references to other permissions, avoiding infinite loop
|
|
185
177
|
let who;
|
|
186
|
-
let max =
|
|
178
|
+
let max = misc_1.PERM_KEYS.length;
|
|
187
179
|
do {
|
|
188
180
|
who = node[perm];
|
|
189
|
-
if (isWhoObject(who))
|
|
181
|
+
if ((0, misc_1.isWhoObject)(who))
|
|
190
182
|
who = who.this;
|
|
191
|
-
who !== null && who !== void 0 ? who : (who =
|
|
192
|
-
if (!max-- || typeof who !== 'string' || who ===
|
|
183
|
+
who !== null && who !== void 0 ? who : (who = misc_1.defaultPerms[perm]);
|
|
184
|
+
if (!max-- || typeof who !== 'string' || who === misc_1.WHO_ANY_ACCOUNT)
|
|
193
185
|
break;
|
|
194
186
|
perm = who;
|
|
195
187
|
} while (1);
|
|
196
188
|
if (Array.isArray(who)) {
|
|
197
189
|
const arr = who; // shut up ts
|
|
198
190
|
// check if I or any ancestor match `who`, but cache ancestors' usernames inside context state
|
|
199
|
-
const some = (0, misc_1.getOrSet)(ctx.state, 'usernames', () => (0, perm_1.
|
|
191
|
+
const some = (0, misc_1.getOrSet)(ctx.state, 'usernames', () => (0, perm_1.expandUsername)((0, perm_1.getCurrentUsername)(ctx)))
|
|
200
192
|
.some((u) => arr.includes(u));
|
|
201
193
|
return some ? 0 : const_1.HTTP_UNAUTHORIZED;
|
|
202
194
|
}
|
|
203
195
|
return typeof who === 'boolean' ? (who ? 0 : const_1.HTTP_FORBIDDEN)
|
|
204
|
-
: who ===
|
|
196
|
+
: who === misc_1.WHO_ANY_ACCOUNT ? (ctx.state.account ? 0 : const_1.HTTP_UNAUTHORIZED)
|
|
205
197
|
: (0, misc_1.throw_)(Error('invalid permission: ' + JSON.stringify(who)));
|
|
206
198
|
}
|
|
207
199
|
}
|
|
@@ -235,7 +227,7 @@ async function* walkNode(parent, ctx, depth = 0, prefixPath = '', requiredPerm)
|
|
|
235
227
|
parentsCache.set(name, item);
|
|
236
228
|
inheritMasks(item, parent, nodeName);
|
|
237
229
|
if (!ctx || hasPermission(item, 'can_list', ctx)) // check perm before recursion
|
|
238
|
-
yield* walkNode(item, ctx, depth - 1, name + '/');
|
|
230
|
+
yield* walkNode(item, ctx, depth - 1, name + '/', requiredPerm);
|
|
239
231
|
}
|
|
240
232
|
if (!source)
|
|
241
233
|
return;
|
|
@@ -338,7 +330,7 @@ events_1.default.on('accountRenamed', (from, to) => {
|
|
|
338
330
|
;
|
|
339
331
|
(function renameInNode(n) {
|
|
340
332
|
var _a;
|
|
341
|
-
for (const k of
|
|
333
|
+
for (const k of misc_1.PERM_KEYS)
|
|
342
334
|
renameInPerm(n[k]);
|
|
343
335
|
if (n.masks)
|
|
344
336
|
Object.values(n.masks).forEach(renameInNode);
|
package/src/watchLoad.js
CHANGED
|
@@ -13,21 +13,14 @@ function watchLoad(path, parser, { failedOnFirstAttempt, immediateFirst } = {})
|
|
|
13
13
|
let watcher;
|
|
14
14
|
const debounced = (0, misc_1.debounceAsync)(load, 500, { maxWait: 1000 });
|
|
15
15
|
let retry;
|
|
16
|
-
let saving;
|
|
17
16
|
let last;
|
|
18
17
|
install(true);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
save: (data) => Promise.resolve(saving).catch(() => { }).then(() => {
|
|
22
|
-
console.debug('writing', path);
|
|
23
|
-
return saving = promises_1.default.writeFile(path, data, 'utf8').finally(() => // save but also keep track of the current operation
|
|
24
|
-
saving = undefined);
|
|
25
|
-
}) // clear
|
|
26
|
-
};
|
|
18
|
+
const save = (0, misc_1.debounceAsync)((data) => promises_1.default.writeFile(path, data, 'utf8'));
|
|
19
|
+
return { unwatch, save };
|
|
27
20
|
function install(first = false) {
|
|
28
21
|
try {
|
|
29
22
|
watcher = (0, fs_1.watch)(path, () => {
|
|
30
|
-
if (!
|
|
23
|
+
if (!save.isWorking())
|
|
31
24
|
debounced().then();
|
|
32
25
|
});
|
|
33
26
|
debounced().catch(x => x);
|
|
@@ -40,7 +33,7 @@ function watchLoad(path, parser, { failedOnFirstAttempt, immediateFirst } = {})
|
|
|
40
33
|
failedOnFirstAttempt === null || failedOnFirstAttempt === void 0 ? void 0 : failedOnFirstAttempt();
|
|
41
34
|
}
|
|
42
35
|
}
|
|
43
|
-
function
|
|
36
|
+
function unwatch() {
|
|
44
37
|
watcher === null || watcher === void 0 ? void 0 : watcher.close();
|
|
45
38
|
clearTimeout(retry);
|
|
46
39
|
watcher = undefined;
|
|
@@ -59,7 +52,7 @@ function watchLoad(path, parser, { failedOnFirstAttempt, immediateFirst } = {})
|
|
|
59
52
|
return;
|
|
60
53
|
last = text;
|
|
61
54
|
console.debug('loaded', path);
|
|
62
|
-
|
|
55
|
+
unwatch();
|
|
63
56
|
install(); // reinstall, as the original file could have been renamed. We watch by the name.
|
|
64
57
|
await parser(text);
|
|
65
58
|
}
|
package/src/zip.js
CHANGED
|
@@ -24,7 +24,7 @@ async function zipStreamFromFolder(node, ctx) {
|
|
|
24
24
|
const name = (list === null || list === void 0 ? void 0 : list.length) === 1 ? decodeURIComponent((0, path_1.basename)(list[0])) : (0, vfs_1.getNodeName)(node);
|
|
25
25
|
ctx.attachment(((0, misc_1.isWindowsDrive)(name) ? name[0] : (name || 'archive')) + '.zip');
|
|
26
26
|
const filter = (0, misc_1.pattern2filter)(String(ctx.query.search || ''));
|
|
27
|
-
const walker = !list ? (0, vfs_1.walkNode)(node, ctx, Infinity, '', '
|
|
27
|
+
const walker = !list ? (0, vfs_1.walkNode)(node, ctx, Infinity, '', 'can_archive')
|
|
28
28
|
: (async function* () {
|
|
29
29
|
for await (const uri of list) {
|
|
30
30
|
const subNode = await (0, vfs_1.urlToNode)(uri, ctx, node);
|
|
@@ -33,7 +33,7 @@ async function zipStreamFromFolder(node, ctx) {
|
|
|
33
33
|
if (await (0, vfs_1.nodeIsDirectory)(subNode)) { // a directory needs to walked
|
|
34
34
|
if ((0, vfs_1.hasPermission)(subNode, 'can_list', ctx)) {
|
|
35
35
|
yield subNode; // it could be empty
|
|
36
|
-
yield* (0, vfs_1.walkNode)(subNode, ctx, Infinity, decodeURI(uri) + '/', '
|
|
36
|
+
yield* (0, vfs_1.walkNode)(subNode, ctx, Infinity, decodeURI(uri) + '/', 'can_archive');
|
|
37
37
|
}
|
|
38
38
|
continue;
|
|
39
39
|
}
|
|
@@ -43,8 +43,8 @@ async function zipStreamFromFolder(node, ctx) {
|
|
|
43
43
|
}
|
|
44
44
|
})();
|
|
45
45
|
const mappedWalker = (0, misc_1.filterMapGenerator)(walker, async (el) => {
|
|
46
|
-
if (!(0, vfs_1.hasPermission)(el, '
|
|
47
|
-
return; // the fact you see it doesn't mean you can
|
|
46
|
+
if (!(0, vfs_1.hasPermission)(el, 'can_archive', ctx))
|
|
47
|
+
return; // the fact you see it doesn't mean you can get it
|
|
48
48
|
const { source } = el;
|
|
49
49
|
const name = (0, vfs_1.getNodeName)(el);
|
|
50
50
|
if (ctx.req.aborted || !filter(name))
|