hfs 0.53.0-beta8 → 0.53.0-beta9
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-tmp9ryDR.js → index-CKQY3dM7.js} +112 -112
- package/admin/assets/{sha512-DvhxPRFX.js → sha512-CRQiqPhg.js} +1 -1
- package/admin/index.html +1 -1
- package/frontend/assets/{index-legacy-DygVvUke.js → index-legacy-D0PyKu9K.js} +7 -7
- package/frontend/assets/{sha512-legacy-BpgpVL8p.js → sha512-legacy-Sd8TlhD9.js} +1 -1
- package/frontend/index.html +1 -1
- package/package.json +1 -1
- package/src/api.get_file_list.js +2 -2
- package/src/api.log.js +3 -3
- package/src/api.plugins.js +0 -4
- package/src/commands.js +16 -5
- package/src/consoleLog.js +1 -1
- package/src/const.js +2 -2
- package/src/cross.js +5 -1
- package/src/customHtml.js +14 -3
- package/src/ddns.js +24 -13
- package/src/debounceAsync.js +5 -1
- package/src/events.js +16 -7
- package/src/fileAttr.js +35 -13
- package/src/frontEndApis.js +10 -19
- package/src/github.js +22 -6
- package/src/index.js +2 -2
- package/src/langs/hfs-lang-de.json +1 -1
- package/src/langs/hfs-lang-el.json +1 -1
- package/src/langs/hfs-lang-es.json +1 -1
- package/src/langs/hfs-lang-fi.json +8 -3
- package/src/langs/hfs-lang-fr.json +1 -1
- package/src/langs/hfs-lang-hu.json +1 -1
- package/src/langs/hfs-lang-it.json +7 -3
- package/src/langs/hfs-lang-ja.json +1 -1
- package/src/langs/hfs-lang-ko.json +1 -1
- package/src/langs/hfs-lang-nl.json +1 -1
- package/src/langs/hfs-lang-pt-br.json +1 -1
- package/src/langs/hfs-lang-ru.json +11 -8
- package/src/langs/hfs-lang-sr.json +1 -1
- package/src/langs/hfs-lang-vi.json +1 -1
- package/src/langs/hfs-lang-zh-tw.json +1 -1
- package/src/langs/hfs-lang-zh.json +1 -1
- package/src/misc.js +40 -1
- package/src/plugins.js +29 -4
- package/src/serveGuiAndSharedFiles.js +12 -0
- package/src/serveGuiFiles.js +1 -1
- package/src/update.js +3 -3
- package/src/upload.js +9 -11
- package/src/util-http.js +7 -3
- /package/src/{ip.js → ips.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
System.register(["./index-legacy-
|
|
1
|
+
System.register(["./index-legacy-D0PyKu9K.js"],(function(h,t){"use strict";var i,s;return{setters:[function(h){i=h.g,s=h.c}],execute:function(){function t(h,t){for(var i=function(){var i=t[s];if("string"!=typeof i&&!Array.isArray(i)){var r=function(t){if("default"!==t&&!(t in h)){var s=Object.getOwnPropertyDescriptor(i,t);s&&Object.defineProperty(h,t,s.get?s:{enumerable:!0,get:function(){return i[t]}})}};for(var e in i)r(e)}},s=0;s<t.length;s++)i();return Object.freeze(Object.defineProperty(h,Symbol.toStringTag,{value:"Module"}))}var r={exports:{}};
|
|
2
2
|
/*
|
|
3
3
|
* [js-sha512]{@link https://github.com/emn178/js-sha512}
|
|
4
4
|
*
|
package/frontend/index.html
CHANGED
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
<div id="root"></div>
|
|
12
12
|
<script nomodule>document.getElementById('root').innerText = "Please use a newer browser"</script>
|
|
13
13
|
<script crossorigin id="vite-legacy-polyfill" src="/assets/polyfills-legacy-DMrMt_pQ.js"></script>
|
|
14
|
-
<script crossorigin id="vite-legacy-entry" data-src="/assets/index-legacy-
|
|
14
|
+
<script crossorigin id="vite-legacy-entry" data-src="/assets/index-legacy-D0PyKu9K.js">System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'))</script>
|
|
15
15
|
</body>
|
|
16
16
|
</html>
|
package/package.json
CHANGED
package/src/api.get_file_list.js
CHANGED
|
@@ -20,12 +20,12 @@ const get_file_list = async ({ uri = '/', offset, limit, search, c, onlyFolders,
|
|
|
20
20
|
if (!node)
|
|
21
21
|
return fail(const_1.HTTP_NOT_FOUND);
|
|
22
22
|
admin && (admin = (0, adminApis_1.ctxAdminAccess)(ctx)); // validate 'admin' flag
|
|
23
|
-
if (!admin && (0, vfs_1.statusCodeForMissingPerm)(node, 'can_list', ctx))
|
|
24
|
-
return fail();
|
|
25
23
|
if ((0, misc_1.dirTraversal)(search))
|
|
26
24
|
return fail(const_1.HTTP_FOOL);
|
|
27
25
|
if (await hasDefaultFile(node) || !await (0, vfs_1.nodeIsDirectory)(node))
|
|
28
26
|
return fail(const_1.HTTP_METHOD_NOT_ALLOWED);
|
|
27
|
+
if (!admin && (0, vfs_1.statusCodeForMissingPerm)(node, 'can_list', ctx))
|
|
28
|
+
return fail();
|
|
29
29
|
offset = Number(offset);
|
|
30
30
|
limit = Number(limit);
|
|
31
31
|
const filter = (0, misc_1.pattern2filter)(String(search || ''));
|
package/src/api.log.js
CHANGED
|
@@ -10,7 +10,7 @@ const events_1 = __importDefault(require("./events"));
|
|
|
10
10
|
const log_1 = require("./log");
|
|
11
11
|
const SendList_1 = require("./SendList");
|
|
12
12
|
const serveFile_1 = require("./serveFile");
|
|
13
|
-
const
|
|
13
|
+
const ips_1 = require("./ips");
|
|
14
14
|
exports.default = {
|
|
15
15
|
async get_log_file({ file = 'log', range = '' }, ctx) {
|
|
16
16
|
const log = lodash_1.default.find(log_1.loggers, { name: file });
|
|
@@ -31,7 +31,7 @@ exports.default = {
|
|
|
31
31
|
bufferTime: 10,
|
|
32
32
|
async doAtStart(list) {
|
|
33
33
|
if (file === 'ips') {
|
|
34
|
-
for await (const [k, v] of
|
|
34
|
+
for await (const [k, v] of ips_1.ips.iterator())
|
|
35
35
|
list.add({ ip: k, ...v });
|
|
36
36
|
list.ready();
|
|
37
37
|
return;
|
|
@@ -55,6 +55,6 @@ exports.default = {
|
|
|
55
55
|
});
|
|
56
56
|
},
|
|
57
57
|
reset_ips() {
|
|
58
|
-
return
|
|
58
|
+
return ips_1.ips.clear();
|
|
59
59
|
},
|
|
60
60
|
};
|
package/src/api.plugins.js
CHANGED
|
@@ -141,11 +141,7 @@ const apis = {
|
|
|
141
141
|
if (!online)
|
|
142
142
|
return new apiMiddleware_1.ApiError(misc_1.HTTP_CONFLICT);
|
|
143
143
|
await checkDependencies(online);
|
|
144
|
-
const enabled = (0, plugins_1.isPluginEnabled)(id);
|
|
145
|
-
await (0, plugins_1.stopPlugin)(id);
|
|
146
144
|
await (0, github_1.downloadPlugin)(found.repo, { branch: online.branch, overwrite: true });
|
|
147
|
-
if (enabled)
|
|
148
|
-
void (0, plugins_1.startPlugin)(id); // don't wait, in case it fails to start
|
|
149
145
|
return {};
|
|
150
146
|
},
|
|
151
147
|
async uninstall_plugin({ id, deleteConfig }) {
|
package/src/commands.js
CHANGED
|
@@ -14,6 +14,7 @@ const const_1 = require("./const");
|
|
|
14
14
|
const readline_1 = require("readline");
|
|
15
15
|
const plugins_1 = require("./plugins");
|
|
16
16
|
const fileAttr_1 = require("./fileAttr");
|
|
17
|
+
const github_1 = require("./github");
|
|
17
18
|
if (!const_1.argv.updating)
|
|
18
19
|
try {
|
|
19
20
|
/*
|
|
@@ -37,10 +38,9 @@ function parseCommandLine(line) {
|
|
|
37
38
|
if (cmd.cb.length > params.length)
|
|
38
39
|
return console.error("insufficient parameters, expected: " + cmd.params);
|
|
39
40
|
Promise.resolve(cmd.cb(...params)).then(() => console.log("+++ command executed"), (err) => {
|
|
40
|
-
if (typeof err
|
|
41
|
-
console.error("command failed:", err);
|
|
42
|
-
else
|
|
41
|
+
if (typeof err !== 'string' && !(err === null || err === void 0 ? void 0 : err.message))
|
|
43
42
|
throw err;
|
|
43
|
+
console.error("command failed:", err.message || err);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
const commands = {
|
|
@@ -98,12 +98,12 @@ const commands = {
|
|
|
98
98
|
},
|
|
99
99
|
update: {
|
|
100
100
|
params: '[<version>=latest]',
|
|
101
|
-
cb: update_1.update
|
|
101
|
+
cb: update_1.update,
|
|
102
102
|
},
|
|
103
103
|
'check-update': {
|
|
104
104
|
params: '',
|
|
105
105
|
async cb() {
|
|
106
|
-
const update =
|
|
106
|
+
const update = (await (0, update_1.getUpdates)(true))[0];
|
|
107
107
|
if (!update)
|
|
108
108
|
throw "you already have the latest version: " + const_1.VERSION;
|
|
109
109
|
console.log("new version available", update.name);
|
|
@@ -124,6 +124,17 @@ const commands = {
|
|
|
124
124
|
params: '<name>',
|
|
125
125
|
cb: plugins_1.stopPlugin,
|
|
126
126
|
},
|
|
127
|
+
'download-plugin': {
|
|
128
|
+
params: '<githubUser/repo>',
|
|
129
|
+
cb: github_1.downloadPlugin,
|
|
130
|
+
},
|
|
131
|
+
'list-plugins': {
|
|
132
|
+
params: '',
|
|
133
|
+
cb() {
|
|
134
|
+
(0, plugins_1.mapPlugins)(p => console.log('ON:', p.id), false);
|
|
135
|
+
(0, plugins_1.getAvailablePlugins)().map(p => console.log('OFF:', p.id));
|
|
136
|
+
}
|
|
137
|
+
},
|
|
127
138
|
'purge-file-attr': {
|
|
128
139
|
params: '',
|
|
129
140
|
cb: fileAttr_1.purgeFileAttr,
|
package/src/consoleLog.js
CHANGED
|
@@ -15,6 +15,6 @@ for (const k of ['log', 'warn', 'error']) {
|
|
|
15
15
|
if (exports.consoleLog.length > 100000) // limit to avoid infinite space
|
|
16
16
|
exports.consoleLog.splice(0, 1000);
|
|
17
17
|
events_1.default.emit('console', rec);
|
|
18
|
-
return original(ts.toLocaleTimeString('
|
|
18
|
+
return original(ts.toLocaleTimeString(undefined, { hourCycle: 'h24' }), ...args); // bundled nodejs doesn't have locales (and apparently uses en-US)
|
|
19
19
|
};
|
|
20
20
|
}
|
package/src/const.js
CHANGED
|
@@ -37,7 +37,7 @@ const os_1 = require("os");
|
|
|
37
37
|
const fs_1 = require("fs");
|
|
38
38
|
const path_1 = require("path");
|
|
39
39
|
__exportStar(require("./cross-const"), exports);
|
|
40
|
-
exports.API_VERSION = 8.
|
|
40
|
+
exports.API_VERSION = 8.85;
|
|
41
41
|
exports.COMPATIBLE_API_VERSION = 1; // while changes in the api are not breaking, this number stays the same, otherwise it is made equal to API_VERSION
|
|
42
42
|
exports.HFS_REPO = 'rejetto/hfs';
|
|
43
43
|
exports.argv = (0, minimist_1.default)(process.argv.slice(2));
|
|
@@ -45,7 +45,7 @@ exports.DEV = process.env.DEV || exports.argv.dev ? 'DEV' : '';
|
|
|
45
45
|
exports.ORIGINAL_CWD = process.cwd();
|
|
46
46
|
exports.HFS_STARTED = new Date();
|
|
47
47
|
const PKG_PATH = (0, path_1.join)(__dirname, '..', 'package.json');
|
|
48
|
-
exports.BUILD_TIMESTAMP = "2024-
|
|
48
|
+
exports.BUILD_TIMESTAMP = "2024-06-07T10:19:15.753Z";
|
|
49
49
|
const pkg = JSON.parse(fs.readFileSync(PKG_PATH, 'utf8'));
|
|
50
50
|
exports.VERSION = pkg.version;
|
|
51
51
|
exports.RUNNING_BETA = exports.VERSION.includes('-');
|
package/src/cross.js
CHANGED
|
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.objRenameKey = exports.randomId = exports.getOrSet = exports.waitFor = exports.newObj = exports.findDefined = exports.isOrderedEqual = exports.swap = exports.tryJson = exports.dirname = exports.basename = exports.pendingPromise = exports._dbg = exports._log = exports.wantArray = exports.formatPerc = exports.with_ = exports.try_ = exports.setHidden = exports.onlyTruthy = exports.truthy = exports.splitAt = exports.strinsert = exports.removeStarting = exports.enforceStarting = exports.enforceFinal = exports.objSameKeys = exports.haveTimeout = exports.wait = exports.join = exports.prefix = exports.formatSpeed = exports.formatBytes = exports.isWhoObject = exports.PERM_KEYS = exports.defaultPerms = exports.WHO_ANY_ACCOUNT = exports.WHO_NO_ONE = exports.WHO_ANYONE = exports.LIST = exports.CFG = exports.THEME_OPTIONS = exports.SORT_BY_OPTIONS = exports.FRONTEND_OPTIONS = exports.MAX_TILE_SIZE = exports.DAY = exports.HOUR = exports.MINUTE = exports.WIKI_URL = exports.REPO_URL = void 0;
|
|
21
|
-
exports.shortenAgent = exports.mapFilter = exports.inCommon = exports.replace = exports.matches = exports.makeMatcher = exports.runAt = exports.pathEncode = exports.promiseBestEffort = exports.escapeHTML = exports.ipForUrl = exports.isIpLan = exports.isIpLocalHost = exports.xlate = exports.isEqualLax = exports.isTimestampString = exports.isWindowsDrive = exports.isIP = exports.isPrimitive = exports.formatTimestamp = exports.repeat = exports.asyncGeneratorToArray = exports.filterMapGenerator = exports.throw_ = exports.hasProp = exports.typedEntries = exports.typedKeys = void 0;
|
|
21
|
+
exports.shortenAgent = exports.callable = exports.mapFilter = exports.inCommon = exports.replace = exports.matches = exports.makeMatcher = exports.runAt = exports.pathEncode = exports.promiseBestEffort = exports.escapeHTML = exports.ipForUrl = exports.isIpLan = exports.isIpLocalHost = exports.xlate = exports.isEqualLax = exports.isTimestampString = exports.isWindowsDrive = exports.isIP = exports.isPrimitive = exports.formatTimestamp = exports.repeat = exports.asyncGeneratorToArray = exports.filterMapGenerator = exports.throw_ = exports.hasProp = exports.typedEntries = exports.typedKeys = void 0;
|
|
22
22
|
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
|
|
23
23
|
// all content here is shared between client and server
|
|
24
24
|
const lodash_1 = __importDefault(require("lodash"));
|
|
@@ -441,6 +441,10 @@ function mapFilter(arr, map, filter = (x) => x === undefined, invert = false) {
|
|
|
441
441
|
}, []);
|
|
442
442
|
}
|
|
443
443
|
exports.mapFilter = mapFilter;
|
|
444
|
+
function callable(x, ...args) {
|
|
445
|
+
return lodash_1.default.isFunction(x) ? x(...args) : x;
|
|
446
|
+
}
|
|
447
|
+
exports.callable = callable;
|
|
444
448
|
function shortenAgent(agent) {
|
|
445
449
|
var _a;
|
|
446
450
|
return lodash_1.default.findKey(BROWSERS, re => re.test(agent))
|
package/src/customHtml.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.saveCustomHtml = exports.getSection = exports.watchLoadCustomHtml = exports.customHtmlState = exports.customHtmlSections = void 0;
|
|
6
|
+
exports.saveCustomHtml = exports.getAllSections = exports.getSection = exports.watchLoadCustomHtml = exports.customHtmlState = exports.customHtmlSections = void 0;
|
|
4
7
|
const misc_1 = require("./misc");
|
|
5
8
|
const watchLoad_1 = require("./watchLoad");
|
|
6
9
|
const vanilla_1 = require("valtio/vanilla"); // without /vanilla we trigger react dependency
|
|
7
10
|
const promises_1 = require("fs/promises");
|
|
8
11
|
const plugins_1 = require("./plugins");
|
|
12
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
13
|
const FILE = 'custom.html';
|
|
10
14
|
exports.customHtmlSections = ['style', 'beforeHeader', 'afterHeader', 'afterMenuBar', 'afterList',
|
|
11
|
-
'top', 'bottom', 'afterEntryName', 'beforeLogin', 'unauthorized', 'htmlHead'];
|
|
15
|
+
'footer', 'top', 'bottom', 'afterEntryName', 'beforeLogin', 'unauthorized', 'htmlHead', 'userPanelAfterInfo'];
|
|
12
16
|
exports.customHtmlState = (0, vanilla_1.proxy)({
|
|
13
17
|
sections: watchLoadCustomHtml().state
|
|
14
18
|
});
|
|
@@ -35,9 +39,16 @@ function watchLoadCustomHtml(folder = '') {
|
|
|
35
39
|
exports.watchLoadCustomHtml = watchLoadCustomHtml;
|
|
36
40
|
function getSection(name) {
|
|
37
41
|
return (exports.customHtmlState.sections.get(name) || '')
|
|
38
|
-
+ (0, plugins_1.mapPlugins)(pl =>
|
|
42
|
+
+ (0, plugins_1.mapPlugins)(pl => pl.getData().getCustomHtml()[name]).join('\n');
|
|
39
43
|
}
|
|
40
44
|
exports.getSection = getSection;
|
|
45
|
+
function getAllSections() {
|
|
46
|
+
const keys = (0, plugins_1.mapPlugins)(pl => Object.keys(pl.getData().getCustomHtml()));
|
|
47
|
+
keys.push(Array.from(exports.customHtmlState.sections.keys()));
|
|
48
|
+
const all = lodash_1.default.uniq(keys.flat());
|
|
49
|
+
return Object.fromEntries(all.map(x => [x, getSection(x)]));
|
|
50
|
+
}
|
|
51
|
+
exports.getAllSections = getAllSections;
|
|
41
52
|
async function saveCustomHtml(sections) {
|
|
42
53
|
const text = Object.entries(sections).filter(([k, v]) => v === null || v === void 0 ? void 0 : v.trim()).map(([k, v]) => `[${k}]\n${v}\n\n`).join('');
|
|
43
54
|
await (0, promises_1.writeFile)(FILE, text);
|
package/src/ddns.js
CHANGED
|
@@ -15,24 +15,35 @@ const events_1 = __importDefault(require("./events"));
|
|
|
15
15
|
const nat_1 = require("./nat");
|
|
16
16
|
// optionally you can append '>' and a regular expression to determine what body is considered successful
|
|
17
17
|
const dynamicDnsUrl = (0, config_1.defineConfig)(cross_1.CFG.dynamic_dns_url, '');
|
|
18
|
-
|
|
18
|
+
// listening this event will trigger public-ips fetching
|
|
19
|
+
const EVENT = 'publicIpsChanged';
|
|
20
|
+
let stopFetching;
|
|
21
|
+
let lastIps;
|
|
22
|
+
events_1.default.onListeners(EVENT, cbs => {
|
|
23
|
+
stopFetching === null || stopFetching === void 0 ? void 0 : stopFetching();
|
|
24
|
+
if (!(cbs === null || cbs === void 0 ? void 0 : cbs.size))
|
|
25
|
+
return;
|
|
26
|
+
stopFetching = (0, cross_1.repeat)(cross_1.HOUR, async () => {
|
|
27
|
+
const IPs = await (0, nat_1.getPublicIps)();
|
|
28
|
+
if (lodash_1.default.isEqual(lastIps, IPs))
|
|
29
|
+
return;
|
|
30
|
+
events_1.default.emit(EVENT, {
|
|
31
|
+
IPs,
|
|
32
|
+
IPX: IPs[0] || '',
|
|
33
|
+
IP4: lodash_1.default.find(IPs, node_net_1.isIPv4) || '',
|
|
34
|
+
IP6: lodash_1.default.find(IPs, net_1.isIPv6) || '',
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
let stopEvent;
|
|
19
39
|
dynamicDnsUrl.sub(v => {
|
|
20
|
-
|
|
40
|
+
stopEvent === null || stopEvent === void 0 ? void 0 : stopEvent();
|
|
21
41
|
if (!v)
|
|
22
42
|
return;
|
|
23
|
-
|
|
24
|
-
stop = (0, cross_1.repeat)(cross_1.HOUR, async () => {
|
|
25
|
-
const ips = await (0, nat_1.getPublicIps)();
|
|
26
|
-
if (lodash_1.default.isEqual(lastIps, ips))
|
|
27
|
-
return;
|
|
28
|
-
lastIps = ips;
|
|
43
|
+
stopEvent = events_1.default.on(EVENT, async (map) => {
|
|
29
44
|
const all = await Promise.all(v.split('\n').map(async (line) => {
|
|
30
45
|
const [templateUrl, re] = (0, cross_1.splitAt)('>', line);
|
|
31
|
-
const url = (0, cross_1.replace)(templateUrl,
|
|
32
|
-
IPX: ips[0] || '',
|
|
33
|
-
IP4: lodash_1.default.find(ips, node_net_1.isIPv4) || '',
|
|
34
|
-
IP6: lodash_1.default.find(ips, net_1.isIPv6) || '',
|
|
35
|
-
}, '$');
|
|
46
|
+
const url = (0, cross_1.replace)(templateUrl, map, '$');
|
|
36
47
|
const error = await (0, util_http_1.httpWithBody)(url, { httpThrow: false, headers: { 'User-Agent': "HFS/" + const_1.VERSION } }) // UA specified as requested by no-ip guidelines
|
|
37
48
|
.then(async (res) => {
|
|
38
49
|
const str = String(res.body).trim();
|
package/src/debounceAsync.js
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.singleWorkerFromBatchWorker = exports.debounceAsync = void 0;
|
|
5
5
|
// like lodash.debounce, but also avoids async invocations to overlap
|
|
6
|
-
function debounceAsync(
|
|
6
|
+
function debounceAsync(
|
|
7
|
+
// the function you want to not call too often, too soon
|
|
8
|
+
callback,
|
|
9
|
+
// time to wait after invocation of the debounced function. If you call again while waiting, the timer starts again.
|
|
10
|
+
wait = 100, options = {}) {
|
|
7
11
|
const { leading = false, maxWait = Infinity, cancelable = false, retain = 0, retainFailure } = options;
|
|
8
12
|
let started = 0; // latest callback invocation
|
|
9
13
|
let runningCallback; // latest callback invocation result
|
package/src/events.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
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
4
|
exports.BetterEventEmitter = void 0;
|
|
5
|
+
const LISTENERS_SUFFIX = '\0listeners';
|
|
5
6
|
class BetterEventEmitter {
|
|
6
7
|
constructor() {
|
|
7
8
|
this.listeners = new Map();
|
|
9
|
+
this.stop = Symbol();
|
|
8
10
|
}
|
|
9
11
|
on(event, listener, { warnAfter = 10 } = {}) {
|
|
10
12
|
if (typeof event === 'string')
|
|
@@ -16,13 +18,22 @@ class BetterEventEmitter {
|
|
|
16
18
|
cbs.add(listener);
|
|
17
19
|
if (cbs.size > warnAfter)
|
|
18
20
|
console.warn("Warning: many events listeners for ", e);
|
|
21
|
+
this.emit(e + LISTENERS_SUFFIX, cbs);
|
|
19
22
|
}
|
|
20
23
|
return () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
for (const e of event) {
|
|
25
|
+
const cbs = this.listeners.get(e);
|
|
26
|
+
if (!cbs)
|
|
27
|
+
continue;
|
|
28
|
+
cbs.delete(listener);
|
|
29
|
+
this.emit(e + LISTENERS_SUFFIX, cbs);
|
|
30
|
+
}
|
|
24
31
|
};
|
|
25
32
|
}
|
|
33
|
+
// call me when listeners for event have changed
|
|
34
|
+
onListeners(event, listener) {
|
|
35
|
+
return this.on(event + LISTENERS_SUFFIX, listener);
|
|
36
|
+
}
|
|
26
37
|
once(event, listener) {
|
|
27
38
|
return new Promise(resolve => {
|
|
28
39
|
const off = this.on(event, function (...args) {
|
|
@@ -50,15 +61,13 @@ class BetterEventEmitter {
|
|
|
50
61
|
ret.push(res);
|
|
51
62
|
}
|
|
52
63
|
return Object.assign(ret, {
|
|
53
|
-
|
|
64
|
+
isDefaultPrevented: () => ret.some(r => r === this.stop),
|
|
54
65
|
});
|
|
55
66
|
}
|
|
56
67
|
emitAsync(event, ...args) {
|
|
57
68
|
const ret = Promise.all(this.emit(event, ...args) || []);
|
|
58
69
|
return Object.assign(ret, {
|
|
59
|
-
async
|
|
60
|
-
return (await ret).some((x) => x === false);
|
|
61
|
-
}
|
|
70
|
+
isDefaultPrevented: async () => (await ret).some((r) => r === this.stop)
|
|
62
71
|
});
|
|
63
72
|
}
|
|
64
73
|
}
|
package/src/fileAttr.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
4
24
|
};
|
|
5
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
26
|
exports.purgeFileAttr = exports.loadFileAttr = exports.storeFileAttr = void 0;
|
|
@@ -11,28 +31,30 @@ const promises_1 = require("fs/promises");
|
|
|
11
31
|
const cross_1 = require("./cross");
|
|
12
32
|
const first_1 = require("./first");
|
|
13
33
|
// @ts-ignore
|
|
14
|
-
const
|
|
15
|
-
|
|
34
|
+
const fsx = Promise.resolve().then(() => __importStar(require('fs-x-attributes'))).then(x => ({ set: (0, util_1.promisify)(x.set), get: (0, util_1.promisify)(x.get) }), () => console.log('fs-x-attributes not available'));
|
|
35
|
+
const fileAttrDb = new kvstorage_1.KvStorage({ defaultPutDelay: 1000, maxPutDelay: 5000 });
|
|
16
36
|
(0, first_1.onProcessExit)(() => fileAttrDb.flush());
|
|
17
37
|
const FN = 'file-attr.kv';
|
|
18
38
|
if ((0, fs_1.existsSync)(FN))
|
|
19
39
|
fileAttrDb.open(FN);
|
|
20
40
|
const FILE_ATTR_PREFIX = 'user.hfs.'; // user. prefix to be linux compatible
|
|
21
|
-
function storeFileAttr(path, k, v) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
async function storeFileAttr(path, k, v) {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
if (await fsx.then(x => x === null || x === void 0 ? void 0 : x.set(path, FILE_ATTR_PREFIX + k, JSON.stringify(v)).then(() => 1, () => 0)))
|
|
44
|
+
return true;
|
|
45
|
+
// fallback to our kv-storage
|
|
46
|
+
if (!fileAttrDb.isOpen())
|
|
47
|
+
await fileAttrDb.open(FN);
|
|
48
|
+
// pipe should be a safe separator
|
|
49
|
+
return (_b = await ((_a = fileAttrDb.put(`${path}|${k}`, v)) === null || _a === void 0 ? void 0 : _a.catch((e) => {
|
|
28
50
|
console.error("couldn't store metadata on", path, String(e.message || e));
|
|
29
51
|
return false;
|
|
30
|
-
});
|
|
52
|
+
}))) !== null && _b !== void 0 ? _b : true; // if put is undefined, the value was already there
|
|
31
53
|
}
|
|
32
54
|
exports.storeFileAttr = storeFileAttr;
|
|
33
55
|
async function loadFileAttr(path, k) {
|
|
34
56
|
var _a;
|
|
35
|
-
return (_a = await (0
|
|
57
|
+
return (_a = await fsx.then(x => x === null || x === void 0 ? void 0 : x.get(path, FILE_ATTR_PREFIX + k))
|
|
36
58
|
.then((x) => x && (0, cross_1.tryJson)(String(x)), () => { })
|
|
37
59
|
.then((x) => x !== null && x !== void 0 ? x : (fileAttrDb.isOpen() ? fileAttrDb.get(`${path}|${k}`) : null))) !== null && _a !== void 0 ? _a : undefined; // normalize, as we get null instead of undefined on windows
|
|
38
60
|
}
|
package/src/frontEndApis.js
CHANGED
|
@@ -90,24 +90,15 @@ exports.frontEndApis = {
|
|
|
90
90
|
},
|
|
91
91
|
async delete({ uri }, ctx) {
|
|
92
92
|
(0, misc_1.apiAssertTypes)({ string: { uri } });
|
|
93
|
-
ctx.logExtra(null, { target: decodeURI(uri) });
|
|
94
93
|
const node = await (0, vfs_1.urlToNode)(uri, ctx);
|
|
95
94
|
if (!node)
|
|
96
95
|
throw new apiMiddleware_1.ApiError(const_1.HTTP_NOT_FOUND);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return null; // stop
|
|
104
|
-
await (0, promises_1.rm)(node.source, { recursive: true });
|
|
105
|
-
void (0, comments_1.setCommentFor)(node.source, '');
|
|
106
|
-
return {};
|
|
107
|
-
}
|
|
108
|
-
catch (e) {
|
|
109
|
-
throw new apiMiddleware_1.ApiError(const_1.HTTP_SERVER_ERROR, e);
|
|
110
|
-
}
|
|
96
|
+
const res = await (0, misc_1.deleteNode)(ctx, node, uri);
|
|
97
|
+
if (typeof res === 'number')
|
|
98
|
+
throw new apiMiddleware_1.ApiError(res);
|
|
99
|
+
if (res instanceof Error)
|
|
100
|
+
throw new apiMiddleware_1.ApiError(const_1.HTTP_SERVER_ERROR, res);
|
|
101
|
+
return res && {};
|
|
111
102
|
},
|
|
112
103
|
async rename({ uri, dest }, ctx) {
|
|
113
104
|
(0, misc_1.apiAssertTypes)({ string: { uri, dest } });
|
|
@@ -180,10 +171,10 @@ exports.frontEndApis = {
|
|
|
180
171
|
return {};
|
|
181
172
|
},
|
|
182
173
|
};
|
|
183
|
-
function notifyClient(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
174
|
+
function notifyClient(channel, name, data) {
|
|
175
|
+
if (typeof channel !== 'string')
|
|
176
|
+
channel = String(channel.query.notificationChannel);
|
|
177
|
+
events_1.default.emit(NOTIFICATION_PREFIX + channel, name, data);
|
|
187
178
|
}
|
|
188
179
|
exports.notifyClient = notifyClient;
|
|
189
180
|
const NOTIFICATION_PREFIX = 'notificationChannel:';
|
package/src/github.js
CHANGED
|
@@ -64,6 +64,7 @@ async function downloadPlugin(repo, { branch = '', overwrite = false } = {}) {
|
|
|
64
64
|
return await go(`https://github.com/${repo}/archive/refs/heads/${branch}.zip`, folder, GITHUB_ZIP_ROOT + '/' + DIST_ROOT);
|
|
65
65
|
async function go(url, folder, zipRoot) {
|
|
66
66
|
const installPath = plugins_1.PATH + '/' + folder;
|
|
67
|
+
const tempInstallPath = installPath + '--' + plugins_1.DISABLING_SUFFIX;
|
|
67
68
|
const foldersToCopy = [
|
|
68
69
|
zipRoot + '-' + process.platform + '-' + process.arch,
|
|
69
70
|
zipRoot + '-' + process.platform,
|
|
@@ -71,20 +72,35 @@ async function downloadPlugin(repo, { branch = '', overwrite = false } = {}) {
|
|
|
71
72
|
].map(x => x + '/');
|
|
72
73
|
// github zip doesn't have content-length, so we cannot produce progress event
|
|
73
74
|
const stream = await (0, misc_1.httpStream)(url);
|
|
74
|
-
const MAIN = 'plugin.js';
|
|
75
75
|
await (0, misc_1.unzip)(stream, async (path) => {
|
|
76
76
|
const folder = foldersToCopy.find(x => path.startsWith(x));
|
|
77
77
|
if (!folder || path.endsWith('/'))
|
|
78
78
|
return false;
|
|
79
79
|
let dest = path.slice(folder.length);
|
|
80
|
-
|
|
81
|
-
dest += plugins_1.DISABLING_SUFFIX;
|
|
82
|
-
dest = (0, path_1.join)(installPath, dest);
|
|
80
|
+
dest = (0, path_1.join)(tempInstallPath, dest);
|
|
83
81
|
return (0, promises_1.rm)(dest, { force: true }).then(() => dest, () => false);
|
|
84
82
|
});
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
// ready to replace
|
|
84
|
+
const wasEnabled = (0, plugins_1.isPluginEnabled)(folder);
|
|
85
|
+
if (wasEnabled)
|
|
86
|
+
await (0, plugins_1.stopPlugin)(folder); // stop old
|
|
87
|
+
let retry = 3;
|
|
88
|
+
while (retry--) { // move data, and consider late release of the resource, up to a few seconds
|
|
89
|
+
const res = (0, promises_1.rename)((0, path_1.join)(installPath, plugins_1.STORAGE_FOLDER), (0, path_1.join)(tempInstallPath, plugins_1.STORAGE_FOLDER));
|
|
90
|
+
if (await res.then(() => true, e => e.code === 'ENOENT'))
|
|
91
|
+
break;
|
|
92
|
+
await (0, misc_1.wait)(1000);
|
|
93
|
+
}
|
|
94
|
+
// delete old
|
|
95
|
+
await (0, promises_1.rm)(installPath, { recursive: true }).catch(e => {
|
|
96
|
+
if (e.code !== 'ENOENT')
|
|
97
|
+
throw e;
|
|
98
|
+
});
|
|
99
|
+
// final replace
|
|
100
|
+
await (0, promises_1.rename)(tempInstallPath, installPath)
|
|
87
101
|
.catch(e => { throw e.code !== 'ENOENT' ? e : new apiMiddleware_1.ApiError(const_1.HTTP_NOT_ACCEPTABLE, "missing main file"); });
|
|
102
|
+
if (wasEnabled)
|
|
103
|
+
void (0, plugins_1.startPlugin)(folder); // don't wait, in case it fails to start
|
|
88
104
|
return folder;
|
|
89
105
|
}
|
|
90
106
|
}
|
package/src/index.js
CHANGED
|
@@ -31,7 +31,7 @@ require("./geo");
|
|
|
31
31
|
const geo_1 = require("./geo");
|
|
32
32
|
const roots_1 = require("./roots");
|
|
33
33
|
const events_1 = __importDefault(require("./events"));
|
|
34
|
-
const
|
|
34
|
+
const ips_1 = require("./ips");
|
|
35
35
|
const persistence_1 = require("./persistence");
|
|
36
36
|
(0, assert_1.ok)(lodash_1.default.intersection(Object.keys(frontEndApis_1.frontEndApis), Object.keys(adminApis_1.adminApis)).length === 0); // they share same endpoints, don't clash
|
|
37
37
|
process.title = 'HFS ' + const_1.VERSION;
|
|
@@ -44,7 +44,7 @@ exports.app.use(middlewares_1.sessionMiddleware)
|
|
|
44
44
|
.use(middlewares_1.someSecurity)
|
|
45
45
|
.use(middlewares_1.prepareState)
|
|
46
46
|
.use(geo_1.geoFilter)
|
|
47
|
-
.use(
|
|
47
|
+
.use(ips_1.trackIpsMw)
|
|
48
48
|
.use(middlewares_1.gzipper)
|
|
49
49
|
.use(middlewares_1.paramsDecoder) // must be done before plugins, so they can manipulate params
|
|
50
50
|
.use(middlewares_1.headRequests)
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"Full timestamp:": "Ganzer Zeitstempel:",
|
|
52
52
|
"Search was interrupted": "Suche wurde abgebrochen",
|
|
53
53
|
"Stop list": "Suche abbrechen",
|
|
54
|
-
"
|
|
54
|
+
"download_starting": "Ihr Download sollte jetzt starten",
|
|
55
55
|
"wrong_account": "Account {u} hat keinen Zugriff, versuchen Sie einen anderen",
|
|
56
56
|
"no_upload_here": "Keine Uploadberechtigung für den momentanen Ordner",
|
|
57
57
|
"Create folder": "Ordner erstellen",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"Full timestamp:": "Πλήρης χρονική σήμανση:",
|
|
52
52
|
"Search was interrupted": "Η αναζήτηση διακόπηκε",
|
|
53
53
|
"Stop list": "Λίστα διακοπής",
|
|
54
|
-
"
|
|
54
|
+
"download_starting": "Η λήψη σας ξεκίνησε",
|
|
55
55
|
"wrong_account": "Ο λογαριασμός {u} δεν έχει πρόσβαση, δοκιμάστε άλλον",
|
|
56
56
|
"no_upload_here": "Δεν υπάρχει άδεια μεταφόρτωσης για τον τρέχοντα φάκελο",
|
|
57
57
|
"Create folder": "Δημιουργία φακέλου",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"Full timestamp:": "Fecha - Hora completa",
|
|
52
52
|
"Search was interrupted": "La búsqueda fue interrumpida",
|
|
53
53
|
"Stop list": "Detener Lista",
|
|
54
|
-
"
|
|
54
|
+
"download_starting": "Su descarga debería iniciarse ahora",
|
|
55
55
|
"wrong_account": "La cuenta {u} no tiene acceso.",
|
|
56
56
|
"no_upload_here": "No tiene permisos para subir a la carpeta actual",
|
|
57
57
|
"Create folder": "Crear carpeta",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Pultsari & Win_7",
|
|
3
3
|
"version": 1.2,
|
|
4
|
-
"hfs_version": "0.
|
|
4
|
+
"hfs_version": "0.53.0b8",
|
|
5
5
|
"translate": {
|
|
6
6
|
"Select": "Valitse",
|
|
7
7
|
"n_files": "{n,plural,one{# tiedosto} other{# tiedostoa}}",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"Full timestamp:": "Täysi aikaleima:",
|
|
52
52
|
"Search was interrupted": "Haku keskeytetty",
|
|
53
53
|
"Stop list": "Pysäytä listaus",
|
|
54
|
-
"
|
|
54
|
+
"download_starting": "Aloitetaan lataaminen",
|
|
55
55
|
"wrong_account": "Tilillä {u} ei ole pääsyä, kokeile toista",
|
|
56
56
|
"no_upload_here": "Ei lähetysoikeutta tähän kansioon",
|
|
57
57
|
"Create folder": "Tee uusi kansio",
|
|
@@ -158,6 +158,11 @@
|
|
|
158
158
|
"Overwrite policy": "Ylikirjoitus käytäntö",
|
|
159
159
|
"Rename to avoid overwriting": "Uudelleen nimeä jotta ei ylikirjoiteta",
|
|
160
160
|
"Overwrite existing files": "Ylikirjoita olemassa olevat tiedostot",
|
|
161
|
-
"Menu": "Valikko"
|
|
161
|
+
"Menu": "Valikko",
|
|
162
|
+
"clipboard": "Leikepöytä ({content})",
|
|
163
|
+
"to_clipboard_source_tooltip": "Mene kansioon jossa leikepöydän kohteet sijaitsevat",
|
|
164
|
+
"more_items": "{n} lisää kohdetta",
|
|
165
|
+
"Show details": "Näytä yksityiskohdat",
|
|
166
|
+
"upload_conflict": "on jo olemassa"
|
|
162
167
|
}
|
|
163
168
|
}
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"Full timestamp:": "Horodatage complet:",
|
|
52
52
|
"Search was interrupted": "Recherche interrompue",
|
|
53
53
|
"Stop list": "Arrêter le chargement de la liste",
|
|
54
|
-
"
|
|
54
|
+
"download_starting": "Votre télé-chargement devrait commencer maintenant",
|
|
55
55
|
"wrong_account": "Aucun accès défini pour ce compte, essayez avec un autre compte",
|
|
56
56
|
"no_upload_here": "Pas de permission de télé-versement pour ce dossier",
|
|
57
57
|
"Create folder": "Créez un dossier",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"Full timestamp:": "Teljes időbélyeg:",
|
|
52
52
|
"Search was interrupted": "A keresés megszakadt",
|
|
53
53
|
"Stop list": "Stop lista",
|
|
54
|
-
"
|
|
54
|
+
"download_starting": "A letöltésnek hamarosan elkezdődik",
|
|
55
55
|
"wrong_account": "A(z) {u} fióknak nincs hozzáférése, próbálkozzon egy másikkal",
|
|
56
56
|
"no_upload_here": "Nincs feltöltési engedély az aktuális mappához",
|
|
57
57
|
"Create folder": "Mappa létrehozása",
|