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/cross.js
CHANGED
|
@@ -3,7 +3,8 @@ 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.
|
|
6
|
+
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._dbg = 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.isWhoObject = exports.PERM_KEYS = exports.defaultPerms = exports.WHO_ANY_ACCOUNT = exports.WHO_NO_ONE = exports.WHO_ANYONE = exports.MAX_TILES_SIZE = exports.DAY = exports.HOUR = exports.MINUTE = exports.WIKI_URL = exports.REPO_URL = void 0;
|
|
7
|
+
exports.promiseBestEffort = exports.escapeHTML = exports.ipForUrl = exports.ipLocalHost = exports.xlate = exports.isEqualLax = void 0;
|
|
7
8
|
// 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
9
|
// all content here is shared between client and server
|
|
9
10
|
const lodash_1 = __importDefault(require("lodash"));
|
|
@@ -13,6 +14,22 @@ exports.MINUTE = 60000;
|
|
|
13
14
|
exports.HOUR = 60 * exports.MINUTE;
|
|
14
15
|
exports.DAY = 24 * exports.HOUR;
|
|
15
16
|
exports.MAX_TILES_SIZE = 10;
|
|
17
|
+
exports.WHO_ANYONE = true;
|
|
18
|
+
exports.WHO_NO_ONE = false;
|
|
19
|
+
exports.WHO_ANY_ACCOUNT = '*';
|
|
20
|
+
exports.defaultPerms = {
|
|
21
|
+
can_see: 'can_read',
|
|
22
|
+
can_read: exports.WHO_ANYONE,
|
|
23
|
+
can_list: 'can_read',
|
|
24
|
+
can_upload: exports.WHO_NO_ONE,
|
|
25
|
+
can_delete: exports.WHO_NO_ONE,
|
|
26
|
+
can_archive: 'can_read'
|
|
27
|
+
};
|
|
28
|
+
exports.PERM_KEYS = typedKeys(exports.defaultPerms);
|
|
29
|
+
function isWhoObject(v) {
|
|
30
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
31
|
+
}
|
|
32
|
+
exports.isWhoObject = isWhoObject;
|
|
16
33
|
const MULTIPLIERS = ['', 'K', 'M', 'G', 'T'];
|
|
17
34
|
function formatBytes(n, { post = 'B', k = 1024, digits = NaN } = {}) {
|
|
18
35
|
if (isNaN(Number(n)) || n < 0)
|
|
@@ -163,6 +180,7 @@ function newObj(src, returnNewValue, recur = false) {
|
|
|
163
180
|
return Object.fromEntries(onlyTruthy(pairs));
|
|
164
181
|
}
|
|
165
182
|
exports.newObj = newObj;
|
|
183
|
+
// returns undefined if timeout is reached
|
|
166
184
|
async function waitFor(cb, { interval = 200, timeout = Infinity } = {}) {
|
|
167
185
|
const started = Date.now();
|
|
168
186
|
while (1) {
|
|
@@ -268,3 +286,13 @@ function ipForUrl(ip) {
|
|
|
268
286
|
return ip.includes(':') ? '[' + ip + ']' : ip;
|
|
269
287
|
}
|
|
270
288
|
exports.ipForUrl = ipForUrl;
|
|
289
|
+
function escapeHTML(text) {
|
|
290
|
+
return text.replace(/[\u0000-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u00FF]/g, c => '&#' + ('000' + c.charCodeAt(0)).slice(-4) + ';');
|
|
291
|
+
}
|
|
292
|
+
exports.escapeHTML = escapeHTML;
|
|
293
|
+
// wait for all, but returns only those that resolved
|
|
294
|
+
async function promiseBestEffort(promises) {
|
|
295
|
+
const res = await Promise.allSettled(promises);
|
|
296
|
+
return res.filter(x => x.status === 'fulfilled').map((x) => x.value);
|
|
297
|
+
}
|
|
298
|
+
exports.promiseBestEffort = promiseBestEffort;
|
package/src/debounceAsync.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.singleFromBatch = exports.debounceAsync = void 0;
|
|
4
5
|
// like lodash.debounce, but also avoids async invocations to overlap
|
|
5
6
|
function debounceAsync(callback, wait = 100, options = {}) {
|
|
6
7
|
const { leading = false, maxWait = Infinity, cancelable = false, retain = 0, retainFailure } = options;
|
|
@@ -16,6 +17,7 @@ function debounceAsync(callback, wait = 100, options = {}) {
|
|
|
16
17
|
return Object.assign(interceptingWrapper, {
|
|
17
18
|
clearRetain: () => last = undefined,
|
|
18
19
|
flush: () => runningCallback !== null && runningCallback !== void 0 ? runningCallback : exec(),
|
|
20
|
+
isWorking: () => runningCallback,
|
|
19
21
|
...cancelable && {
|
|
20
22
|
cancel() {
|
|
21
23
|
waitingSince = 0;
|
|
@@ -59,4 +61,18 @@ function debounceAsync(callback, wait = 100, options = {}) {
|
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
|
-
exports.
|
|
64
|
+
exports.debounceAsync = debounceAsync;
|
|
65
|
+
// given a function that works on a batch of requests, returns the function that works on a single request
|
|
66
|
+
function singleFromBatch(batchWorker) {
|
|
67
|
+
let batch = [];
|
|
68
|
+
const debounced = debounceAsync(async () => {
|
|
69
|
+
const ret = batchWorker(batch);
|
|
70
|
+
batch = [];
|
|
71
|
+
return ret;
|
|
72
|
+
});
|
|
73
|
+
return (...args) => {
|
|
74
|
+
batch.push(args);
|
|
75
|
+
return debounced();
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.singleFromBatch = singleFromBatch;
|
package/src/frontEndApis.js
CHANGED
|
@@ -39,6 +39,7 @@ const promises_1 = require("fs/promises");
|
|
|
39
39
|
const path_1 = require("path");
|
|
40
40
|
const upload_1 = require("./upload");
|
|
41
41
|
const misc_1 = require("./misc");
|
|
42
|
+
const comments_1 = require("./comments");
|
|
42
43
|
exports.frontEndApis = {
|
|
43
44
|
get_file_list: api_file_list_1.get_file_list,
|
|
44
45
|
...api_auth,
|
|
@@ -95,6 +96,7 @@ exports.frontEndApis = {
|
|
|
95
96
|
throw new apiMiddleware_1.ApiError(const_1.HTTP_UNAUTHORIZED);
|
|
96
97
|
try {
|
|
97
98
|
await (0, promises_1.rm)(node.source, { recursive: true });
|
|
99
|
+
(0, comments_1.setCommentFor)(node.source, '').then();
|
|
98
100
|
return {};
|
|
99
101
|
}
|
|
100
102
|
catch (e) {
|
|
@@ -111,18 +113,38 @@ exports.frontEndApis = {
|
|
|
111
113
|
if (!(0, vfs_1.hasPermission)(node, 'can_delete', ctx))
|
|
112
114
|
throw new apiMiddleware_1.ApiError(const_1.HTTP_UNAUTHORIZED);
|
|
113
115
|
try {
|
|
114
|
-
if (node.name)
|
|
116
|
+
if (node.name) // virtual name = virtual rename
|
|
115
117
|
node.name = dest;
|
|
116
|
-
else
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
else {
|
|
119
|
+
if (!node.source)
|
|
120
|
+
throw new apiMiddleware_1.ApiError(const_1.HTTP_FAILED_DEPENDENCY);
|
|
121
|
+
const destSource = (0, path_1.join)((0, path_1.dirname)(node.source), dest);
|
|
122
|
+
await (0, promises_1.rename)(node.source, destSource);
|
|
123
|
+
(0, comments_1.getCommentFor)(node.source).then(c => {
|
|
124
|
+
if (!c)
|
|
125
|
+
return;
|
|
126
|
+
(0, comments_1.setCommentFor)(node.source, '').then();
|
|
127
|
+
(0, comments_1.setCommentFor)(destSource, c).then();
|
|
128
|
+
});
|
|
129
|
+
}
|
|
120
130
|
return {};
|
|
121
131
|
}
|
|
122
132
|
catch (e) {
|
|
123
133
|
throw new apiMiddleware_1.ApiError(const_1.HTTP_SERVER_ERROR, e);
|
|
124
134
|
}
|
|
125
|
-
}
|
|
135
|
+
},
|
|
136
|
+
async comment({ uri, comment }, ctx) {
|
|
137
|
+
(0, misc_1.apiAssertTypes)({ string: { uri, comment } });
|
|
138
|
+
const node = await (0, vfs_1.urlToNode)(uri, ctx);
|
|
139
|
+
if (!node)
|
|
140
|
+
throw new apiMiddleware_1.ApiError(const_1.HTTP_NOT_FOUND);
|
|
141
|
+
if (!(0, vfs_1.hasPermission)(node, 'can_upload', ctx))
|
|
142
|
+
throw new apiMiddleware_1.ApiError(const_1.HTTP_UNAUTHORIZED);
|
|
143
|
+
if (!node.source)
|
|
144
|
+
throw new apiMiddleware_1.ApiError(const_1.HTTP_FAILED_DEPENDENCY);
|
|
145
|
+
await (0, comments_1.setCommentFor)(node.source, comment);
|
|
146
|
+
return {};
|
|
147
|
+
},
|
|
126
148
|
};
|
|
127
149
|
function notifyClient(ctx, name, data) {
|
|
128
150
|
const { notificationChannel } = ctx.query;
|
package/src/github.js
CHANGED
|
@@ -26,35 +26,37 @@ function downloadProgress(id, status) {
|
|
|
26
26
|
// determine default branch, possibly without consuming api quota
|
|
27
27
|
async function getGithubDefaultBranch(repo) {
|
|
28
28
|
var _a;
|
|
29
|
-
const
|
|
30
|
-
return
|
|
31
|
-
: (_a = (await getRepoInfo(repo))) === null || _a === void 0 ? void 0 : _a.default_branch;
|
|
29
|
+
const test = await (0, misc_1.httpString)(`https://github.com/${repo}/archive/refs/heads/main.zip`, { method: 'HEAD' }).then(() => 1, () => 0);
|
|
30
|
+
return test ? 'main' : (_a = (await getRepoInfo(repo))) === null || _a === void 0 ? void 0 : _a.default_branch;
|
|
32
31
|
}
|
|
33
32
|
async function downloadPlugin(repo, { branch = '', overwrite = false } = {}) {
|
|
34
|
-
var _a, _b, _c;
|
|
33
|
+
var _a, _b, _c, _d;
|
|
35
34
|
if (typeof repo !== 'string')
|
|
36
35
|
repo = repo.main;
|
|
37
36
|
if (downloading[repo])
|
|
38
|
-
|
|
37
|
+
throw new apiMiddleware_1.ApiError(const_1.HTTP_CONFLICT, "already downloading");
|
|
38
|
+
const projectInfo = await (0, exports.getProjectInfo)();
|
|
39
|
+
if ((_a = projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.plugins_blacklist) === null || _a === void 0 ? void 0 : _a.includes(repo))
|
|
40
|
+
throw new apiMiddleware_1.ApiError(const_1.HTTP_FORBIDDEN, "blacklisted");
|
|
39
41
|
console.log('downloading plugin', repo);
|
|
40
42
|
downloadProgress(repo, true);
|
|
41
43
|
try {
|
|
42
44
|
if (repo.includes('//')) { // custom repo
|
|
43
45
|
const pl = (0, plugins_1.findPluginByRepo)(repo);
|
|
44
46
|
if (!pl)
|
|
45
|
-
|
|
46
|
-
const customRepo = (((
|
|
47
|
+
throw new apiMiddleware_1.ApiError(const_1.HTTP_BAD_REQUEST, "bad repo");
|
|
48
|
+
const customRepo = (((_c = (_b = pl).getData) === null || _c === void 0 ? void 0 : _c.call(_b)) || pl).repo;
|
|
47
49
|
let url = customRepo === null || customRepo === void 0 ? void 0 : customRepo.zip;
|
|
48
50
|
if (!url)
|
|
49
|
-
|
|
51
|
+
throw new apiMiddleware_1.ApiError(const_1.HTTP_SERVER_ERROR, "bad plugin");
|
|
50
52
|
if (!url.includes('//'))
|
|
51
53
|
url = customRepo.web + url;
|
|
52
|
-
return await go(url, pl === null || pl === void 0 ? void 0 : pl.id, (
|
|
54
|
+
return await go(url, pl === null || pl === void 0 ? void 0 : pl.id, (_d = customRepo.zipRoot) !== null && _d !== void 0 ? _d : DIST_ROOT);
|
|
53
55
|
}
|
|
54
56
|
branch || (branch = await getGithubDefaultBranch(repo));
|
|
55
57
|
const short = repo.split('/')[1]; // second part, repo without the owner
|
|
56
58
|
if (!short)
|
|
57
|
-
|
|
59
|
+
throw new apiMiddleware_1.ApiError(const_1.HTTP_BAD_REQUEST, "bad repo");
|
|
58
60
|
const folder = overwrite ? lodash_1.default.findKey(getFolder2repo(), x => x === repo) // use existing folder
|
|
59
61
|
: getFolder2repo().hasOwnProperty(short) ? repo.replace('/', '-') // longer form only if another plugin is using short form, to avoid overwriting
|
|
60
62
|
: short;
|
|
@@ -96,8 +98,7 @@ function getRepoInfo(id) {
|
|
|
96
98
|
}
|
|
97
99
|
exports.getRepoInfo = getRepoInfo;
|
|
98
100
|
function readGithubFile(uri) {
|
|
99
|
-
return (0, misc_1.httpString)('https://raw.githubusercontent.com/' + uri)
|
|
100
|
-
.then(res => res.body);
|
|
101
|
+
return (0, misc_1.httpString)('https://raw.githubusercontent.com/' + uri);
|
|
101
102
|
}
|
|
102
103
|
exports.readGithubFile = readGithubFile;
|
|
103
104
|
async function readOnlinePlugin(repo, branch = '') {
|
|
@@ -111,10 +112,7 @@ async function readOnlinePlugin(repo, branch = '') {
|
|
|
111
112
|
throw Error("missing repo.main");
|
|
112
113
|
if (!main.includes('//'))
|
|
113
114
|
main = pl.repo.web + main;
|
|
114
|
-
|
|
115
|
-
if (!res.ok)
|
|
116
|
-
throw Error("bad repo.main");
|
|
117
|
-
return (0, plugins_1.parsePluginSource)(main, res.body); // use 'repo' as 'id' client-side
|
|
115
|
+
return (0, plugins_1.parsePluginSource)(main, await (0, misc_1.httpString)(main)); // use 'repo' as 'id' client-side
|
|
118
116
|
}
|
|
119
117
|
branch || (branch = await getGithubDefaultBranch(repo));
|
|
120
118
|
const res = await readGithubFile(`${repo}/${branch}/${DIST_ROOT}/plugin.js`);
|
|
@@ -132,22 +130,16 @@ function getFolder2repo() {
|
|
|
132
130
|
}
|
|
133
131
|
exports.getFolder2repo = getFolder2repo;
|
|
134
132
|
async function apiGithub(uri) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
});
|
|
142
|
-
if (!res.ok)
|
|
143
|
-
throw res.statusCode;
|
|
144
|
-
return JSON.parse(res.body);
|
|
145
|
-
}
|
|
146
|
-
catch (e) {
|
|
133
|
+
return (0, misc_1.httpString)('https://api.github.com/' + uri, {
|
|
134
|
+
headers: {
|
|
135
|
+
'User-Agent': 'HFS',
|
|
136
|
+
Accept: 'application/vnd.github.v3+json',
|
|
137
|
+
}
|
|
138
|
+
}).then(JSON.parse, e => {
|
|
147
139
|
// https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting
|
|
148
140
|
throw e.message === '403' ? Error('github_quota')
|
|
149
141
|
: e;
|
|
150
|
-
}
|
|
142
|
+
});
|
|
151
143
|
}
|
|
152
144
|
async function searchPlugins(text = '') {
|
|
153
145
|
const projectInfo = await (0, exports.getProjectInfo)();
|
|
@@ -188,5 +180,7 @@ exports.searchPlugins = searchPlugins;
|
|
|
188
180
|
// centralized hosted information, to be used as little as possible
|
|
189
181
|
const FN = 'central.json';
|
|
190
182
|
let builtIn = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '..', FN), 'utf8'));
|
|
191
|
-
exports.getProjectInfo = (0, misc_1.debounceAsync)(() => readGithubFile(`${const_1.HFS_REPO}/${const_1.HFS_REPO_BRANCH}/${FN}`)
|
|
183
|
+
exports.getProjectInfo = (0, misc_1.debounceAsync)(() => readGithubFile(`${const_1.HFS_REPO}/${const_1.HFS_REPO_BRANCH}/${FN}`)
|
|
184
|
+
.then(JSON.parse, () => null)
|
|
185
|
+
.then(x => Object.assign(Object.create(builtIn), const_1.DEV ? null : x)), // fall back to built-in
|
|
192
186
|
0, { retain: misc_1.DAY, retainFailure: 60000 });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Massimo Melina",
|
|
3
3
|
"version": 1.8,
|
|
4
|
-
"hfs_version": "0.
|
|
4
|
+
"hfs_version": "0.49.0",
|
|
5
5
|
"translate": {
|
|
6
6
|
"Select": "Seleziona",
|
|
7
7
|
"n_files": "{n} file",
|
|
@@ -121,8 +121,10 @@
|
|
|
121
121
|
"showHelp_F_body": "pieno schermo",
|
|
122
122
|
"Destination": "Destinazione",
|
|
123
123
|
"in_queue": "{n} in coda",
|
|
124
|
-
"": "
|
|
125
|
-
"": "
|
|
124
|
+
"enter_comment": "Comment for this file",
|
|
125
|
+
"Comment": "Comment",
|
|
126
|
+
"_PLUGINS SECTION": "",
|
|
127
|
+
"_PLUGIN thumbnails": "",
|
|
126
128
|
"Enable tiles mode": "Modalità griglia",
|
|
127
129
|
"thumbnails_switchBack": "Puoi tornare alla lista com'era prima entrando in Opzioni"
|
|
128
130
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Mefistofell, SanokKule",
|
|
3
|
-
"version": 2.
|
|
4
|
-
"hfs_version": "0.
|
|
3
|
+
"version": 2.2,
|
|
4
|
+
"hfs_version": "0.49.0",
|
|
5
5
|
"translate": {
|
|
6
6
|
"Select": "Выбор",
|
|
7
7
|
"n_files": "{n,plural, one{1 файл} few{# файла} other{# файлов}}",
|
|
@@ -129,8 +129,10 @@
|
|
|
129
129
|
"showHelp_F_body": "полноэкранный режим",
|
|
130
130
|
"Destination": "Назначение",
|
|
131
131
|
"in_queue": "{n} в очереди",
|
|
132
|
-
"": "
|
|
133
|
-
"": "
|
|
132
|
+
"enter_comment": "Комментарий для файла",
|
|
133
|
+
"Comment": "Комментировать",
|
|
134
|
+
"_PLUGINS SECTION": "",
|
|
135
|
+
"_PLUGIN thumbnails": "",
|
|
134
136
|
"Enable tiles mode": "Просмотр в режиме плиток",
|
|
135
137
|
"thumbnails_switchBack": "Изменить вид можно в настройках"
|
|
136
138
|
}
|
package/src/listen.js
CHANGED
|
@@ -44,6 +44,7 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
44
44
|
const crypto_1 = require("crypto");
|
|
45
45
|
const api_net_1 = require("./api.net");
|
|
46
46
|
const events_1 = __importDefault(require("./events"));
|
|
47
|
+
const net_1 = require("net");
|
|
47
48
|
let httpSrv;
|
|
48
49
|
let httpsSrv;
|
|
49
50
|
const openBrowserAtStart = (0, config_1.defineConfig)('open_browser_at_start', !const_1.DEV);
|
|
@@ -257,13 +258,13 @@ async function getIps(external = true) {
|
|
|
257
258
|
const ips = (0, misc_1.onlyTruthy)(Object.entries((0, os_1.networkInterfaces)()).map(([name, nets]) => nets && !ignore.test(name)
|
|
258
259
|
&& v4first((0, misc_1.onlyTruthy)(nets.map(net => !net.internal && net.address)))[0] // for each interface we consider only 1 address
|
|
259
260
|
)).flat();
|
|
260
|
-
const e = external &&
|
|
261
|
+
const e = external && api_net_1.externalIp;
|
|
261
262
|
if (e && !ips.includes(e))
|
|
262
263
|
ips.unshift(e);
|
|
263
264
|
return v4first(ips)
|
|
264
265
|
.filter((x, i, a) => a.length > 1 || !x.startsWith('169.254')); // 169.254 = dhcp failure on the interface, but keep it if it's our only one
|
|
265
266
|
function v4first(a) {
|
|
266
|
-
return lodash_1.default.sortBy(a,
|
|
267
|
+
return lodash_1.default.sortBy(a, net_1.isIPv6); // works because `false` comes first
|
|
267
268
|
}
|
|
268
269
|
}
|
|
269
270
|
exports.getIps = getIps;
|
package/src/middlewares.js
CHANGED
|
@@ -224,7 +224,9 @@ const prepareState = async (ctx, next) => {
|
|
|
224
224
|
if (ctx.session)
|
|
225
225
|
ctx.session.maxAge = exports.sessionDuration.compiled();
|
|
226
226
|
// calculate these once and for all
|
|
227
|
-
ctx.state.account = (_a = await getHttpAccount(ctx)) !== null && _a !== void 0 ? _a : (0, perm_1.getAccount)((_b = ctx.session) === null || _b === void 0 ? void 0 : _b.username, false);
|
|
227
|
+
const a = ctx.state.account = (_a = await getHttpAccount(ctx)) !== null && _a !== void 0 ? _a : (0, perm_1.getAccount)((_b = ctx.session) === null || _b === void 0 ? void 0 : _b.username, false);
|
|
228
|
+
if (a && !(0, perm_1.accountCanLogin)(a))
|
|
229
|
+
ctx.state.account = undefined;
|
|
228
230
|
const conn = ctx.state.connection = (0, connections_1.socket2connection)(ctx.socket);
|
|
229
231
|
ctx.state.revProxyPath = ctx.get('x-forwarded-prefix');
|
|
230
232
|
if (conn)
|
package/src/misc.js
CHANGED
|
@@ -18,21 +18,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.apiAssertTypes = exports.AsapStream = exports.asyncGeneratorToReadable = exports.stream2string = exports.same = exports.matches = exports.makeMatcher = exports.makeNetMatcher = exports.isLocalHost = exports.onOff = exports.pattern2filter = exports.onFirstEvent = exports.onProcessExit =
|
|
21
|
+
exports.apiAssertTypes = exports.AsapStream = exports.asyncGeneratorToReadable = exports.stream2string = exports.same = exports.matches = exports.makeMatcher = exports.makeNetMatcher = exports.isLocalHost = exports.onOff = exports.pattern2filter = exports.onFirstEvent = exports.onProcessExit = void 0;
|
|
22
22
|
const path_1 = require("path");
|
|
23
23
|
const lodash_1 = __importDefault(require("lodash"));
|
|
24
24
|
const assert_1 = __importDefault(require("assert"));
|
|
25
25
|
__exportStar(require("./util-http"), exports);
|
|
26
26
|
__exportStar(require("./util-files"), exports);
|
|
27
27
|
__exportStar(require("./cross"), exports);
|
|
28
|
+
__exportStar(require("./debounceAsync"), exports);
|
|
28
29
|
const stream_1 = require("stream");
|
|
29
30
|
const micromatch_1 = require("micromatch");
|
|
30
31
|
const node_net_1 = require("node:net");
|
|
31
|
-
const debounceAsync_1 = __importDefault(require("./debounceAsync"));
|
|
32
|
-
exports.debounceAsync = debounceAsync_1.default;
|
|
33
32
|
const apiMiddleware_1 = require("./apiMiddleware");
|
|
34
33
|
const const_1 = require("./const");
|
|
35
34
|
const cross_1 = require("./cross");
|
|
35
|
+
const net_1 = require("net");
|
|
36
36
|
const cbs = new Set();
|
|
37
37
|
function onProcessExit(cb) {
|
|
38
38
|
cbs.add(cb);
|
|
@@ -103,7 +103,7 @@ function makeNetMatcher(mask, emptyMaskReturns = false) {
|
|
|
103
103
|
}
|
|
104
104
|
exports.makeNetMatcher = makeNetMatcher;
|
|
105
105
|
function parseAddress(s) {
|
|
106
|
-
return new node_net_1.SocketAddress({ address: s, family:
|
|
106
|
+
return new node_net_1.SocketAddress({ address: s, family: (0, net_1.isIPv6)(s) ? 'ipv6' : 'ipv4' });
|
|
107
107
|
}
|
|
108
108
|
function makeMatcher(mask, emptyMaskReturns = false) {
|
|
109
109
|
return mask ? (0, micromatch_1.matcher)(mask.replace(/^(!)?/, '$1(') + ')') // adding () will allow us to use the pipe at root level
|
package/src/perm.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.accountCanLoginAdmin = exports.accountCanLogin = exports.accountHasPassword = exports.getFromAccount = exports.delAccount = exports.setAccount = exports.addAccount = exports.renameAccount = exports.normalizeUsername = exports.accountsConfig = exports.updateAccount = exports.allowClearTextLogin = exports.saveSrpInfo = exports.getAccount = exports.
|
|
7
|
+
exports.accountCanLoginAdmin = exports.accountCanLogin = exports.accountHasPassword = exports.getFromAccount = exports.delAccount = exports.setAccount = exports.addAccount = exports.renameAccount = exports.normalizeUsername = exports.accountsConfig = exports.updateAccount = exports.allowClearTextLogin = exports.saveSrpInfo = exports.getAccount = exports.expandUsername = exports.getCurrentUsername = void 0;
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
9
|
const crypt_1 = require("./crypt");
|
|
10
10
|
const misc_1 = require("./misc");
|
|
@@ -18,19 +18,20 @@ function getCurrentUsername(ctx) {
|
|
|
18
18
|
}
|
|
19
19
|
exports.getCurrentUsername = getCurrentUsername;
|
|
20
20
|
// provides the username and all other usernames it inherits based on the 'belongs' attribute. Useful to check permissions
|
|
21
|
-
function
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const ret = [who];
|
|
26
|
-
for (const u of ret) {
|
|
21
|
+
function expandUsername(who) {
|
|
22
|
+
const ret = [];
|
|
23
|
+
const q = [who];
|
|
24
|
+
for (const u of q) {
|
|
27
25
|
const a = getAccount(u);
|
|
28
|
-
if (a
|
|
29
|
-
|
|
26
|
+
if (!a || a.disabled)
|
|
27
|
+
continue;
|
|
28
|
+
ret.push(u);
|
|
29
|
+
if (a.belongs)
|
|
30
|
+
q.push(...a.belongs);
|
|
30
31
|
}
|
|
31
32
|
return ret;
|
|
32
33
|
}
|
|
33
|
-
exports.
|
|
34
|
+
exports.expandUsername = expandUsername;
|
|
34
35
|
function getAccount(username, normalize = true) {
|
|
35
36
|
if (normalize)
|
|
36
37
|
username = normalizeUsername(username);
|
|
@@ -116,7 +117,7 @@ function renameAccount(from, to) {
|
|
|
116
117
|
}
|
|
117
118
|
exports.renameAccount = renameAccount;
|
|
118
119
|
// we consider all the following fields, when falsy, as equivalent to be missing. If this changes in the future, please adjust addAccount and setAccount
|
|
119
|
-
const assignableProps = ['redirect', 'ignore_limits', 'belongs', 'admin'];
|
|
120
|
+
const assignableProps = ['redirect', 'ignore_limits', 'belongs', 'admin', 'disabled'];
|
|
120
121
|
function addAccount(username, props) {
|
|
121
122
|
username = normalizeUsername(username);
|
|
122
123
|
if (!username || getAccount(username, false))
|
|
@@ -133,6 +134,8 @@ function setAccount(acc, changes) {
|
|
|
133
134
|
if (!v)
|
|
134
135
|
rest[k] = undefined;
|
|
135
136
|
Object.assign(acc, rest);
|
|
137
|
+
if (!acc.disabled)
|
|
138
|
+
delete acc.disabled;
|
|
136
139
|
if (changes.username)
|
|
137
140
|
renameAccount(acc.username, changes.username);
|
|
138
141
|
saveAccountsAsap();
|
|
@@ -167,9 +170,13 @@ function accountHasPassword(account) {
|
|
|
167
170
|
}
|
|
168
171
|
exports.accountHasPassword = accountHasPassword;
|
|
169
172
|
function accountCanLogin(account) {
|
|
170
|
-
return accountHasPassword(account);
|
|
173
|
+
return accountHasPassword(account) && !allDisabled(account);
|
|
171
174
|
}
|
|
172
175
|
exports.accountCanLogin = accountCanLogin;
|
|
176
|
+
function allDisabled(account) {
|
|
177
|
+
var _a;
|
|
178
|
+
return Boolean(account.disabled || ((_a = account.belongs) === null || _a === void 0 ? void 0 : _a.map(u => getAccount(u, false)).every(a => a && allDisabled(a))));
|
|
179
|
+
}
|
|
173
180
|
function accountCanLoginAdmin(account) {
|
|
174
181
|
return accountCanLogin(account) && Boolean(getFromAccount(account, a => a.admin));
|
|
175
182
|
}
|
package/src/plugins.js
CHANGED
|
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.parsePluginSource = exports.rescan = exports.pluginsConfig = exports.enablePlugins = exports.pluginsWatcher = exports.getAvailablePlugins = exports.mapPlugins = exports.Plugin = exports.pluginsMiddleware = exports.getPluginConfigFields = exports.findPluginByRepo = exports.getPluginInfo = exports.setPluginConfig = exports.startPlugin = exports.stopPlugin = exports.enablePlugin = exports.isPluginEnabled = exports.isPluginRunning = exports.STORAGE_FOLDER = exports.DISABLING_POSTFIX = exports.PATH = void 0;
|
|
30
|
+
exports.getMissingDependencies = exports.parsePluginSource = exports.rescan = exports.pluginsConfig = exports.enablePlugins = exports.pluginsWatcher = exports.getAvailablePlugins = exports.mapPlugins = exports.Plugin = exports.pluginsMiddleware = exports.getPluginConfigFields = exports.findPluginByRepo = exports.getPluginInfo = exports.setPluginConfig = exports.startPlugin = exports.stopPlugin = exports.enablePlugin = exports.isPluginEnabled = exports.isPluginRunning = exports.STORAGE_FOLDER = exports.DISABLING_POSTFIX = exports.PATH = void 0;
|
|
31
31
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
32
32
|
const watchLoad_1 = require("./watchLoad");
|
|
33
33
|
const lodash_1 = __importDefault(require("lodash"));
|
|
@@ -193,10 +193,11 @@ class Plugin {
|
|
|
193
193
|
}
|
|
194
194
|
plugins[id] = this;
|
|
195
195
|
}
|
|
196
|
-
get version() {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
196
|
+
get version() { var _a; return (_a = this.data) === null || _a === void 0 ? void 0 : _a.version; }
|
|
197
|
+
get description() { var _a; return (_a = this.data) === null || _a === void 0 ? void 0 : _a.description; }
|
|
198
|
+
get apiRequired() { var _a; return (_a = this.data) === null || _a === void 0 ? void 0 : _a.apiRequired; }
|
|
199
|
+
get repo() { var _a; return (_a = this.data) === null || _a === void 0 ? void 0 : _a.repo; }
|
|
200
|
+
get depend() { var _a; return (_a = this.data) === null || _a === void 0 ? void 0 : _a.depend; }
|
|
200
201
|
get middleware() {
|
|
201
202
|
var _a;
|
|
202
203
|
return (_a = this.data) === null || _a === void 0 ? void 0 : _a.middleware;
|
|
@@ -236,11 +237,12 @@ class Plugin {
|
|
|
236
237
|
}
|
|
237
238
|
}
|
|
238
239
|
exports.Plugin = Plugin;
|
|
240
|
+
const SERVER_CODE_ID = '.';
|
|
239
241
|
const serverCode = (0, config_1.defineConfig)('server_code', '', async (script, { k }) => {
|
|
240
242
|
const res = {};
|
|
241
243
|
try {
|
|
242
244
|
new Function('exports', script)(res); // parse
|
|
243
|
-
return new Plugin(
|
|
245
|
+
return new Plugin(SERVER_CODE_ID, '', await initPlugin(res), lodash_1.default.noop); // '.' is a name that will surely be not found among plugin folders
|
|
244
246
|
}
|
|
245
247
|
catch (e) {
|
|
246
248
|
return console.error(k + ':', e.message || String(e));
|
|
@@ -250,9 +252,9 @@ let serverCodePlugin;
|
|
|
250
252
|
serverCode.sub(() => serverCode.compiled().then(x => serverCodePlugin = x));
|
|
251
253
|
function mapPlugins(cb, includeServerCode = true) {
|
|
252
254
|
const entries = Object.entries(plugins);
|
|
253
|
-
if (includeServerCode && serverCodePlugin)
|
|
254
|
-
entries.push([serverCodePlugin.id, serverCodePlugin]);
|
|
255
255
|
return entries.map(([plName, pl]) => {
|
|
256
|
+
if (!includeServerCode && plName === SERVER_CODE_ID)
|
|
257
|
+
return;
|
|
256
258
|
try {
|
|
257
259
|
return cb(pl, plName);
|
|
258
260
|
}
|
|
@@ -337,8 +339,10 @@ function watchPlugin(id, path) {
|
|
|
337
339
|
}
|
|
338
340
|
async function markItAvailable() {
|
|
339
341
|
delete plugins[id];
|
|
340
|
-
|
|
341
|
-
|
|
342
|
+
availablePlugins[id] = await parsePlugin();
|
|
343
|
+
}
|
|
344
|
+
async function parsePlugin() {
|
|
345
|
+
return parsePluginSource(id, await (0, promises_1.readFile)(module, 'utf8'));
|
|
342
346
|
}
|
|
343
347
|
async function stop() {
|
|
344
348
|
await starting;
|
|
@@ -355,6 +359,10 @@ function watchPlugin(id, path) {
|
|
|
355
359
|
return;
|
|
356
360
|
try {
|
|
357
361
|
starting = (0, misc_1.pendingPromise)();
|
|
362
|
+
// if dependencies are not ready right now, we give some time. Not super-solid but good enough for now.
|
|
363
|
+
const info = await parsePlugin();
|
|
364
|
+
if (!await (0, misc_1.waitFor)(async () => lodash_1.default.isEmpty(await getMissingDependencies(info)), { timeout: 5000 }))
|
|
365
|
+
return console.debug("plugin missing dependencies", id);
|
|
358
366
|
if (getPluginInfo(id))
|
|
359
367
|
setError(id, '');
|
|
360
368
|
const alreadyRunning = plugins[id];
|
|
@@ -404,6 +412,7 @@ function watchPlugin(id, path) {
|
|
|
404
412
|
delete availablePlugins[id];
|
|
405
413
|
events_1.default.emit(wasInstalled ? 'pluginStarted' : 'pluginInstalled', plugin);
|
|
406
414
|
}
|
|
415
|
+
events_1.default.emit('pluginStarted:' + id);
|
|
407
416
|
}
|
|
408
417
|
catch (e) {
|
|
409
418
|
await markItAvailable();
|
|
@@ -417,8 +426,8 @@ function watchPlugin(id, path) {
|
|
|
417
426
|
}
|
|
418
427
|
}
|
|
419
428
|
}
|
|
420
|
-
function customApiCall(method, params) {
|
|
421
|
-
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); });
|
|
429
|
+
function customApiCall(method, ...params) {
|
|
430
|
+
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); });
|
|
422
431
|
}
|
|
423
432
|
function getError(id) {
|
|
424
433
|
return getPluginInfo(id).error;
|
|
@@ -473,3 +482,15 @@ function calculateBadApi(data) {
|
|
|
473
482
|
: max < const_1.COMPATIBLE_API_VERSION ? "may not work correctly as it is designed for an older version of HFS - check for updates"
|
|
474
483
|
: undefined;
|
|
475
484
|
}
|
|
485
|
+
async function getMissingDependencies(plugin) {
|
|
486
|
+
return (0, misc_1.onlyTruthy)(((plugin === null || plugin === void 0 ? void 0 : plugin.depend) || []).map((dep) => {
|
|
487
|
+
const res = findPluginByRepo(dep.repo);
|
|
488
|
+
const error = !res ? 'missing'
|
|
489
|
+
: (res.version || 0) < dep.version ? 'version'
|
|
490
|
+
: !isPluginEnabled(res.id) ? 'disabled'
|
|
491
|
+
: !isPluginRunning(res.id) ? 'stopped'
|
|
492
|
+
: '';
|
|
493
|
+
return error && { repo: dep.repo, error, id: res === null || res === void 0 ? void 0 : res.id };
|
|
494
|
+
}));
|
|
495
|
+
}
|
|
496
|
+
exports.getMissingDependencies = getMissingDependencies;
|
package/src/serveFile.js
CHANGED
|
@@ -22,11 +22,10 @@ function serveFileNode(ctx, node) {
|
|
|
22
22
|
const name = (0, vfs_1.getNodeName)(node);
|
|
23
23
|
const mimeString = typeof mime === 'string' ? mime
|
|
24
24
|
: lodash_1.default.find(mime, (val, mask) => (0, misc_1.matches)(name, mask));
|
|
25
|
-
|
|
26
|
-
if (allowed) {
|
|
25
|
+
if (allowedReferer.get()) {
|
|
27
26
|
const ref = (_a = /\/\/([^:/]+)/.exec(ctx.get('referer'))) === null || _a === void 0 ? void 0 : _a[1]; // extract host from url
|
|
28
27
|
if (ref && ref !== host() // automatic accept if referer is basically the hosting domain
|
|
29
|
-
&& !(0, misc_1.matches)(ref,
|
|
28
|
+
&& !(0, misc_1.matches)(ref, allowedReferer.get()))
|
|
30
29
|
return ctx.status = const_1.HTTP_FORBIDDEN;
|
|
31
30
|
}
|
|
32
31
|
ctx.vfsNode = node; // useful to tell service files from files shared by the user
|
package/src/upload.js
CHANGED
|
@@ -15,6 +15,7 @@ const util_os_1 = require("./util-os");
|
|
|
15
15
|
const connections_1 = require("./connections");
|
|
16
16
|
const throttler_1 = require("./throttler");
|
|
17
17
|
const perm_1 = require("./perm");
|
|
18
|
+
const comments_1 = require("./comments");
|
|
18
19
|
exports.deleteUnfinishedUploadsAfter = (0, config_1.defineConfig)('delete_unfinished_uploads_after', 86400);
|
|
19
20
|
exports.minAvailableMb = (0, config_1.defineConfig)('min_available_mb', 100);
|
|
20
21
|
const dontOverwriteUploading = (0, config_1.defineConfig)('dont_overwrite_uploading', false);
|
|
@@ -98,7 +99,10 @@ function uploadWriter(base, path, ctx) {
|
|
|
98
99
|
while (fs_1.default.existsSync(dest));
|
|
99
100
|
}
|
|
100
101
|
return fs_1.default.rename(tempName, dest, err => {
|
|
101
|
-
|
|
102
|
+
if (err)
|
|
103
|
+
console.error("couldn't rename temp to", dest, String(err));
|
|
104
|
+
else if (ctx.query.comment)
|
|
105
|
+
(0, comments_1.setCommentFor)(dest, (0, misc_1.escapeHTML)(String(ctx.query.comment)));
|
|
102
106
|
if (resumable)
|
|
103
107
|
delayedDelete(resumable, 0);
|
|
104
108
|
});
|
package/src/util-http.js
CHANGED
|
@@ -7,15 +7,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.httpStream = exports.httpString = void 0;
|
|
8
8
|
const node_http_1 = __importDefault(require("node:http"));
|
|
9
9
|
const node_https_1 = __importDefault(require("node:https"));
|
|
10
|
-
const
|
|
10
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
11
|
+
// in case the response is not 2xx, it will throw and the error object is the Response object
|
|
11
12
|
function httpString(url, options) {
|
|
12
13
|
return httpStream(url, options).then(res => new Promise(resolve => {
|
|
13
14
|
let buf = '';
|
|
14
15
|
res.on('data', chunk => buf += chunk.toString());
|
|
15
|
-
res.on('end', () =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
res.on('end', () => {
|
|
17
|
+
if (!lodash_1.default.inRange(res.statusCode, 200, 299))
|
|
18
|
+
throw res;
|
|
19
|
+
resolve(buf);
|
|
20
|
+
});
|
|
19
21
|
}));
|
|
20
22
|
}
|
|
21
23
|
exports.httpString = httpString;
|
|
@@ -28,7 +30,7 @@ function httpStream(url, { body, ...options } = {}) {
|
|
|
28
30
|
console.debug("http responded", res.statusCode, "to", url);
|
|
29
31
|
if (!res.statusCode || res.statusCode >= 400)
|
|
30
32
|
return reject(new Error(String(res.statusCode), { cause: res }));
|
|
31
|
-
if (res.
|
|
33
|
+
if (res.headers.location)
|
|
32
34
|
return resolve(httpStream(res.headers.location, options));
|
|
33
35
|
resolve(res);
|
|
34
36
|
}).on('error', e => {
|