hfs 0.26.7 → 0.26.8
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/.DS_Store +0 -0
- package/admin/.eslintrc +8 -0
- package/admin/.gitignore +23 -0
- package/admin/index.html +1 -3
- package/admin/package.json +67 -0
- package/admin/{logo.svg → public/logo.svg} +0 -0
- package/admin/src/AccountForm.ts +92 -0
- package/admin/src/AccountsPage.ts +143 -0
- package/admin/src/App.ts +83 -0
- package/admin/src/ArrayField.ts +84 -0
- package/admin/src/ConfigPage.ts +279 -0
- package/admin/src/FileField.ts +52 -0
- package/admin/src/FileForm.ts +148 -0
- package/admin/src/FilePicker.ts +166 -0
- package/admin/src/HomePage.ts +96 -0
- package/admin/src/InstalledPlugins.ts +158 -0
- package/admin/src/LoginRequired.ts +75 -0
- package/admin/src/LogoutPage.ts +27 -0
- package/admin/src/LogsPage.ts +75 -0
- package/admin/src/MainMenu.ts +74 -0
- package/admin/src/MenuButton.ts +38 -0
- package/admin/src/MonitorPage.ts +200 -0
- package/admin/src/OnlinePlugins.ts +101 -0
- package/admin/src/PermField.ts +80 -0
- package/admin/src/PluginsPage.ts +27 -0
- package/admin/src/VfsMenuBar.ts +58 -0
- package/admin/src/VfsPage.ts +124 -0
- package/admin/src/VfsTree.ts +95 -0
- package/admin/src/addFiles.ts +59 -0
- package/admin/src/api.ts +246 -0
- package/admin/src/dialog.ts +203 -0
- package/admin/src/index.css +21 -0
- package/admin/src/index.ts +10 -0
- package/admin/src/md.ts +31 -0
- package/admin/src/misc.ts +141 -0
- package/admin/src/react-app-env.d.ts +1 -0
- package/admin/src/reportWebVitals.ts +15 -0
- package/admin/src/setupTests.ts +5 -0
- package/admin/src/state.ts +40 -0
- package/admin/src/theme.ts +37 -0
- package/admin/tsconfig.json +26 -0
- package/admin/vite.config.ts +32 -0
- package/frontend/.DS_Store +0 -0
- package/frontend/.eslintrc +8 -0
- package/frontend/.gitignore +23 -0
- package/frontend/index.html +1 -3
- package/frontend/package.json +51 -0
- package/frontend/{fontello.css → public/fontello.css} +0 -0
- package/frontend/{fontello.woff2 → public/fontello.woff2} +0 -0
- package/frontend/src/App.ts +25 -0
- package/frontend/src/Breadcrumbs.ts +43 -0
- package/frontend/src/BrowseFiles.ts +141 -0
- package/frontend/src/Head.ts +45 -0
- package/frontend/src/UserPanel.ts +52 -0
- package/frontend/src/api.ts +78 -0
- package/frontend/src/components.ts +54 -0
- package/frontend/src/dialog.css +76 -0
- package/frontend/src/dialog.ts +105 -0
- package/frontend/src/icons.ts +46 -0
- package/frontend/src/index.scss +307 -0
- package/frontend/src/index.ts +10 -0
- package/frontend/src/login.ts +50 -0
- package/frontend/src/menu.ts +188 -0
- package/frontend/src/misc.ts +54 -0
- package/frontend/src/options.ts +52 -0
- package/frontend/src/react-app-env.d.ts +1 -0
- package/frontend/src/reportWebVitals.ts +15 -0
- package/frontend/src/setupTests.ts +5 -0
- package/frontend/src/state.ts +82 -0
- package/frontend/src/useAuthorized.ts +17 -0
- package/frontend/src/useFetchList.ts +144 -0
- package/frontend/src/useTheme.ts +23 -0
- package/frontend/tsconfig.json +26 -0
- package/frontend/vite.config.ts +21 -0
- package/package.json +2 -1
- package/plugins/vhosting/plugin.js +1 -1
- package/src/QuickZipStream.ts +279 -0
- package/src/ThrottledStream.ts +98 -0
- package/src/adminApis.ts +161 -0
- package/src/api.accounts.ts +78 -0
- package/src/api.auth.ts +131 -0
- package/src/api.file_list.ts +102 -0
- package/src/api.helpers.ts +30 -0
- package/src/api.monitor.ts +106 -0
- package/src/api.plugins.ts +139 -0
- package/src/api.vfs.ts +182 -0
- package/src/apiMiddleware.ts +124 -0
- package/src/block.ts +35 -0
- package/src/commands.ts +122 -0
- package/src/config.ts +166 -0
- package/src/connections.ts +60 -0
- package/src/const.ts +57 -0
- package/src/crypt.ts +16 -0
- package/src/debounceAsync.ts +51 -0
- package/src/events.ts +6 -0
- package/src/frontEndApis.ts +17 -0
- package/src/github.ts +102 -0
- package/src/index.ts +53 -0
- package/src/listen.ts +220 -0
- package/src/log.ts +128 -0
- package/src/middlewares.ts +176 -0
- package/src/misc.ts +149 -0
- package/src/pbkdf2.ts +83 -0
- package/src/perm.ts +194 -0
- package/src/plugins.ts +342 -0
- package/src/serveFile.ts +104 -0
- package/src/serveGuiFiles.ts +95 -0
- package/src/sse.ts +29 -0
- package/src/throttler.ts +106 -0
- package/src/update.ts +67 -0
- package/src/util-files.ts +137 -0
- package/src/util-generators.ts +29 -0
- package/src/util-http.ts +29 -0
- package/src/vfs.ts +258 -0
- package/src/watchLoad.ts +75 -0
- package/src/zip.ts +69 -0
- package/admin/assets/index.0f549e00.js +0 -281
- package/admin/assets/index.dcc78777.css +0 -1
- package/admin/assets/sha512.ea1121b3.js +0 -8
- package/frontend/assets/index.1151988f.js +0 -85
- package/frontend/assets/index.93366732.css +0 -1
- package/frontend/assets/sha512.bb881250.js +0 -8
- package/src/QuickZipStream.js +0 -285
- package/src/ThrottledStream.js +0 -93
- package/src/adminApis.js +0 -169
- package/src/api.accounts.js +0 -59
- package/src/api.auth.js +0 -130
- package/src/api.file_list.js +0 -103
- package/src/api.helpers.js +0 -32
- package/src/api.monitor.js +0 -102
- package/src/api.plugins.js +0 -127
- package/src/api.vfs.js +0 -164
- package/src/apiMiddleware.js +0 -136
- package/src/block.js +0 -33
- package/src/commands.js +0 -124
- package/src/config.js +0 -168
- package/src/connections.js +0 -57
- package/src/const.js +0 -83
- package/src/crypt.js +0 -21
- package/src/debounceAsync.js +0 -48
- package/src/events.js +0 -9
- package/src/frontEndApis.js +0 -38
- package/src/github.js +0 -102
- package/src/index.js +0 -55
- package/src/listen.js +0 -235
- package/src/log.js +0 -137
- package/src/middlewares.js +0 -154
- package/src/misc.js +0 -160
- package/src/pbkdf2.js +0 -74
- package/src/perm.js +0 -176
- package/src/plugins.js +0 -343
- package/src/serveFile.js +0 -104
- package/src/serveGuiFiles.js +0 -113
- package/src/sse.js +0 -29
- package/src/throttler.js +0 -91
- package/src/update.js +0 -69
- package/src/util-files.js +0 -148
- package/src/util-generators.js +0 -30
- package/src/util-http.js +0 -30
- package/src/vfs.js +0 -227
- package/src/watchLoad.js +0 -73
- package/src/zip.js +0 -69
package/src/const.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is part of HFS - Copyright 2021-2022, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.APP_PATH = exports.IS_WINDOWS = exports.UNAUTHORIZED = exports.FORBIDDEN = exports.NO_CONTENT = exports.METHOD_NOT_ALLOWED = exports.PLUGINS_PUB_URI = exports.API_URI = exports.ADMIN_URI = exports.FRONTEND_URI = exports.SPECIAL_URI = exports.COMPATIBLE_API_VERSION = exports.API_VERSION = exports.SESSION_DURATION = exports.DAY = exports.VERSION = exports.BUILD_TIMESTAMP = exports.HFS_STARTED = exports.ORIGINAL_CWD = exports.DEV = exports.argv = void 0;
|
|
31
|
-
const minimist_1 = __importDefault(require("minimist"));
|
|
32
|
-
const fs = __importStar(require("fs"));
|
|
33
|
-
const os_1 = require("os");
|
|
34
|
-
const fs_1 = require("fs");
|
|
35
|
-
const path_1 = require("path");
|
|
36
|
-
exports.argv = (0, minimist_1.default)(process.argv.slice(2));
|
|
37
|
-
exports.DEV = process.env.DEV || exports.argv.dev ? 'DEV' : '';
|
|
38
|
-
exports.ORIGINAL_CWD = process.cwd();
|
|
39
|
-
exports.HFS_STARTED = new Date();
|
|
40
|
-
const PKG_PATH = (0, path_1.join)(__dirname, '..', 'package.json');
|
|
41
|
-
exports.BUILD_TIMESTAMP = fs.statSync(PKG_PATH).mtime.toISOString();
|
|
42
|
-
const pkg = JSON.parse(fs.readFileSync(PKG_PATH, 'utf8'));
|
|
43
|
-
exports.VERSION = pkg.version;
|
|
44
|
-
exports.DAY = 86400000;
|
|
45
|
-
exports.SESSION_DURATION = exports.DAY;
|
|
46
|
-
exports.API_VERSION = 4.1; // array.$width
|
|
47
|
-
exports.COMPATIBLE_API_VERSION = 1; // while changes in the api are not breaking, this number stays the same, otherwise is made equal to API_VERSION
|
|
48
|
-
exports.SPECIAL_URI = '/~/';
|
|
49
|
-
exports.FRONTEND_URI = exports.SPECIAL_URI + 'frontend/';
|
|
50
|
-
exports.ADMIN_URI = exports.SPECIAL_URI + 'admin/';
|
|
51
|
-
exports.API_URI = exports.SPECIAL_URI + 'api/';
|
|
52
|
-
exports.PLUGINS_PUB_URI = exports.SPECIAL_URI + 'plugins/';
|
|
53
|
-
exports.METHOD_NOT_ALLOWED = 405;
|
|
54
|
-
exports.NO_CONTENT = 204;
|
|
55
|
-
exports.FORBIDDEN = 403;
|
|
56
|
-
exports.UNAUTHORIZED = 401;
|
|
57
|
-
exports.IS_WINDOWS = process.platform === 'win32';
|
|
58
|
-
const IS_BINARY = !(0, path_1.basename)(process.argv0).includes('node'); // this won't be node if pkg was used
|
|
59
|
-
exports.APP_PATH = (0, path_1.dirname)(IS_BINARY ? process.argv0 : __dirname);
|
|
60
|
-
// we want this to be the first stuff to be printed, then we print it in this module, that is executed at the beginning
|
|
61
|
-
if (exports.DEV)
|
|
62
|
-
console.clear();
|
|
63
|
-
else
|
|
64
|
-
console.debug = () => { };
|
|
65
|
-
console.log(`HFS ~ HTTP File Server - Copyright 2021-2022, Massimo Melina <a@rejetto.com>`);
|
|
66
|
-
console.log(`License https://www.gnu.org/licenses/gpl-3.0.txt`);
|
|
67
|
-
console.log('started', exports.HFS_STARTED.toLocaleString(), exports.DEV);
|
|
68
|
-
console.log('version', exports.VERSION || '-');
|
|
69
|
-
console.log('build', exports.BUILD_TIMESTAMP || '-');
|
|
70
|
-
if (exports.argv.cwd)
|
|
71
|
-
process.chdir(exports.argv.cwd);
|
|
72
|
-
else if (!process.argv0.endsWith('.exe')) { // still considering whether to use this behavior with Windows users, who may be less accustomed to it
|
|
73
|
-
const dir = (0, path_1.join)((0, os_1.homedir)(), '.hfs');
|
|
74
|
-
try {
|
|
75
|
-
(0, fs_1.mkdirSync)(dir);
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
if (e.code !== 'EEXIST')
|
|
79
|
-
console.error(e);
|
|
80
|
-
}
|
|
81
|
-
process.chdir(dir);
|
|
82
|
-
}
|
|
83
|
-
console.log('cwd', process.cwd());
|
package/src/crypt.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is part of HFS - Copyright 2021-2022, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.verifyPassword = exports.hashPassword = void 0;
|
|
8
|
-
// simple wrapper
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
const pbkdf2_1 = require("./pbkdf2");
|
|
11
|
-
const assert_1 = __importDefault(require("assert"));
|
|
12
|
-
async function hashPassword(s) {
|
|
13
|
-
return 'p2:' + await (0, pbkdf2_1.pbkdf2)(s);
|
|
14
|
-
}
|
|
15
|
-
exports.hashPassword = hashPassword;
|
|
16
|
-
async function verifyPassword(hashed, given) {
|
|
17
|
-
const i = hashed.indexOf(':');
|
|
18
|
-
(0, assert_1.default)(i > 0, 'bad hashed');
|
|
19
|
-
return await (0, pbkdf2_1.pbkdf2Verify)(hashed.slice(i + 1), given); // for the time being we totally ignore the "method" part
|
|
20
|
-
}
|
|
21
|
-
exports.verifyPassword = verifyPassword;
|
package/src/debounceAsync.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// like lodash.debounce, but also avoids async invocations to overlap
|
|
4
|
-
function debounceAsync(callback, wait = 100, { leading = false, maxWait = Infinity } = {}) {
|
|
5
|
-
let started = 0; // latest callback invocation
|
|
6
|
-
let runningCallback; // latest callback invocation result
|
|
7
|
-
let runningDebouncer; // latest wrapper invocation
|
|
8
|
-
let waitingSince = 0; // we are delaying invocation since
|
|
9
|
-
let whoIsWaiting; // args' array object identifies the pending instance, and incidentally stores args
|
|
10
|
-
const interceptingWrapper = (...args) => runningDebouncer = debouncer.apply(null, args);
|
|
11
|
-
return Object.assign(interceptingWrapper, {
|
|
12
|
-
cancel: () => {
|
|
13
|
-
waitingSince = 0;
|
|
14
|
-
whoIsWaiting = undefined;
|
|
15
|
-
},
|
|
16
|
-
flush: () => runningCallback !== null && runningCallback !== void 0 ? runningCallback : exec(),
|
|
17
|
-
});
|
|
18
|
-
async function debouncer(...args) {
|
|
19
|
-
if (runningCallback)
|
|
20
|
-
return await runningCallback;
|
|
21
|
-
whoIsWaiting = args;
|
|
22
|
-
waitingSince || (waitingSince = Date.now());
|
|
23
|
-
const waitingCap = maxWait - (Date.now() - (waitingSince || started));
|
|
24
|
-
const waitFor = Math.min(waitingCap, leading ? wait - (Date.now() - started) : wait);
|
|
25
|
-
if (waitFor > 0)
|
|
26
|
-
await new Promise(resolve => setTimeout(resolve, waitFor));
|
|
27
|
-
if (!whoIsWaiting) // canceled
|
|
28
|
-
return void (waitingSince = 0);
|
|
29
|
-
if (whoIsWaiting !== args) // another fresher call is waiting
|
|
30
|
-
return runningDebouncer;
|
|
31
|
-
return await exec();
|
|
32
|
-
}
|
|
33
|
-
async function exec() {
|
|
34
|
-
if (!whoIsWaiting)
|
|
35
|
-
return;
|
|
36
|
-
waitingSince = 0;
|
|
37
|
-
started = Date.now();
|
|
38
|
-
try {
|
|
39
|
-
runningCallback = callback.apply(null, whoIsWaiting);
|
|
40
|
-
return await runningCallback;
|
|
41
|
-
}
|
|
42
|
-
finally {
|
|
43
|
-
whoIsWaiting = undefined;
|
|
44
|
-
runningCallback = undefined;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.default = debounceAsync;
|
package/src/events.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is part of HFS - Copyright 2021-2022, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const events_1 = __importDefault(require("events"));
|
|
8
|
-
// app-wide events
|
|
9
|
-
exports.default = new events_1.default();
|
package/src/frontEndApis.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is part of HFS - Copyright 2021-2022, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.frontEndApis = void 0;
|
|
28
|
-
const api_file_list_1 = require("./api.file_list");
|
|
29
|
-
const api_auth = __importStar(require("./api.auth"));
|
|
30
|
-
const config_1 = require("./config");
|
|
31
|
-
const customHeader = (0, config_1.defineConfig)('custom_header');
|
|
32
|
-
exports.frontEndApis = {
|
|
33
|
-
file_list: api_file_list_1.file_list,
|
|
34
|
-
...api_auth,
|
|
35
|
-
config() {
|
|
36
|
-
return Object.fromEntries([customHeader].map(x => [x.key(), x.get()]));
|
|
37
|
-
}
|
|
38
|
-
};
|
package/src/github.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.searchPlugins = exports.getFolder2repo = exports.readOnlinePlugin = exports.getRepoInfo = exports.downloadPlugin = void 0;
|
|
7
|
-
const events_1 = __importDefault(require("./events"));
|
|
8
|
-
const misc_1 = require("./misc");
|
|
9
|
-
const plugins_1 = require("./plugins");
|
|
10
|
-
const apiMiddleware_1 = require("./apiMiddleware");
|
|
11
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
12
|
-
const DIST_ROOT = 'dist/';
|
|
13
|
-
const downloading = {};
|
|
14
|
-
function downloadProgress(id, status) {
|
|
15
|
-
if (status === undefined)
|
|
16
|
-
delete downloading[id];
|
|
17
|
-
else
|
|
18
|
-
downloading[id] = status;
|
|
19
|
-
events_1.default.emit('pluginDownload_' + id, status);
|
|
20
|
-
}
|
|
21
|
-
async function downloadPlugin(repo, branch = '', overwrite) {
|
|
22
|
-
if (downloading[repo])
|
|
23
|
-
return new apiMiddleware_1.ApiError(409, "already downloading");
|
|
24
|
-
downloadProgress(repo, true);
|
|
25
|
-
const rec = await getRepoInfo(repo);
|
|
26
|
-
if (!branch)
|
|
27
|
-
branch = rec.default_branch;
|
|
28
|
-
const short = repo.split('/')[1]; // second part, repo without the owner
|
|
29
|
-
const folder2repo = getFolder2repo();
|
|
30
|
-
const folder = overwrite ? lodash_1.default.findKey(folder2repo, x => x === repo) // use existing folder
|
|
31
|
-
: short in folder2repo ? repo.replace('/', '-') // longer form only if another plugin is using short form
|
|
32
|
-
: short;
|
|
33
|
-
const installPath = plugins_1.PATH + '/' + folder;
|
|
34
|
-
const GITHUB_ZIP_ROOT = short + '-' + branch; // GitHub puts everything within this folder
|
|
35
|
-
const rootWithinZip = GITHUB_ZIP_ROOT + '/' + DIST_ROOT;
|
|
36
|
-
const stream = await (0, misc_1.httpsStream)(`https://github.com/${repo}/archive/refs/heads/${branch}.zip`);
|
|
37
|
-
await (0, misc_1.unzip)(stream, path => path.startsWith(rootWithinZip) && installPath + '/' + path.slice(rootWithinZip.length));
|
|
38
|
-
downloadProgress(repo, undefined);
|
|
39
|
-
await (0, plugins_1.rescan)(); // workaround: for some reason, operations are not triggering the rescan of the watched folder. Let's invoke it.
|
|
40
|
-
return folder;
|
|
41
|
-
}
|
|
42
|
-
exports.downloadPlugin = downloadPlugin;
|
|
43
|
-
function getRepoInfo(id) {
|
|
44
|
-
return apiGithub('repos/' + id);
|
|
45
|
-
}
|
|
46
|
-
exports.getRepoInfo = getRepoInfo;
|
|
47
|
-
async function readOnlinePlugin(repoInfo, branch = '') {
|
|
48
|
-
const url = `https://raw.githubusercontent.com/${repoInfo.full_name}/${branch || repoInfo.default_branch}/${DIST_ROOT}plugin.js`;
|
|
49
|
-
const res = await (0, misc_1.httpsString)(url);
|
|
50
|
-
if (!res.ok)
|
|
51
|
-
throw res.statusCode;
|
|
52
|
-
const pl = (0, plugins_1.parsePluginSource)(repoInfo.full_name, res.body); // use 'repo' as 'id' client-side
|
|
53
|
-
pl.branch = branch || undefined;
|
|
54
|
-
return pl;
|
|
55
|
-
}
|
|
56
|
-
exports.readOnlinePlugin = readOnlinePlugin;
|
|
57
|
-
function getFolder2repo() {
|
|
58
|
-
const ret = Object.fromEntries((0, plugins_1.getAvailablePlugins)().map(x => [x.id, x.repo]));
|
|
59
|
-
Object.assign(ret, Object.fromEntries((0, plugins_1.mapPlugins)(x => [x.id, x.getData().repo])));
|
|
60
|
-
return ret;
|
|
61
|
-
}
|
|
62
|
-
exports.getFolder2repo = getFolder2repo;
|
|
63
|
-
async function apiGithub(uri) {
|
|
64
|
-
const res = await (0, misc_1.httpsString)('https://api.github.com/' + uri, {
|
|
65
|
-
headers: {
|
|
66
|
-
'User-Agent': 'HFS',
|
|
67
|
-
Accept: 'application/vnd.github.v3+json',
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
if (!res.ok)
|
|
71
|
-
throw res.statusCode;
|
|
72
|
-
return JSON.parse(res.body);
|
|
73
|
-
}
|
|
74
|
-
async function* searchPlugins(text) {
|
|
75
|
-
var _a;
|
|
76
|
-
const res = await apiGithub('search/repositories?q=topic:hfs-plugin+' + encodeURI(text));
|
|
77
|
-
for (const it of res.items) {
|
|
78
|
-
const repo = it.full_name;
|
|
79
|
-
let pl = await readOnlinePlugin(it);
|
|
80
|
-
if (!pl.apiRequired)
|
|
81
|
-
continue; // mandatory field
|
|
82
|
-
if (pl.badApi) { // we try other branches (starting with 'api')
|
|
83
|
-
const branches = (await apiGithub('repos/' + it.full_name + '/branches'))
|
|
84
|
-
.map((x) => x.name).filter((x) => x.startsWith('api')).sort();
|
|
85
|
-
for (const branch of branches) {
|
|
86
|
-
pl = await readOnlinePlugin(it, branch);
|
|
87
|
-
if (!pl.apiRequired)
|
|
88
|
-
pl.badApi = '-';
|
|
89
|
-
if (!pl.badApi)
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (pl.badApi)
|
|
94
|
-
continue;
|
|
95
|
-
Object.assign(pl, {
|
|
96
|
-
downloading: downloading[repo],
|
|
97
|
-
license: (_a = it.license) === null || _a === void 0 ? void 0 : _a.spdx_id,
|
|
98
|
-
}, lodash_1.default.pick(it, ['pushed_at', 'stargazers_count']));
|
|
99
|
-
yield pl;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.searchPlugins = searchPlugins;
|
package/src/index.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
// This file is part of HFS - Copyright 2021-2022, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
var _a;
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.app = void 0;
|
|
10
|
-
const koa_1 = __importDefault(require("koa"));
|
|
11
|
-
const koa_mount_1 = __importDefault(require("koa-mount"));
|
|
12
|
-
const apiMiddleware_1 = require("./apiMiddleware");
|
|
13
|
-
const const_1 = require("./const");
|
|
14
|
-
const frontEndApis_1 = require("./frontEndApis");
|
|
15
|
-
const log_1 = require("./log");
|
|
16
|
-
const plugins_1 = require("./plugins");
|
|
17
|
-
const throttler_1 = require("./throttler");
|
|
18
|
-
const middlewares_1 = require("./middlewares");
|
|
19
|
-
require("./listen");
|
|
20
|
-
require("./commands");
|
|
21
|
-
const adminApis_1 = require("./adminApis");
|
|
22
|
-
const config_1 = require("./config");
|
|
23
|
-
const assert_1 = require("assert");
|
|
24
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
25
|
-
const misc_1 = require("./misc");
|
|
26
|
-
(0, assert_1.ok)(lodash_1.default.intersection(Object.keys(frontEndApis_1.frontEndApis), Object.keys(adminApis_1.adminApis)).length === 0); // they share same endpoints
|
|
27
|
-
const keys = ((_a = process.env.COOKIE_SIGN_KEYS) === null || _a === void 0 ? void 0 : _a.split(',')) || [(0, misc_1.randomId)(30)];
|
|
28
|
-
exports.app = new koa_1.default({ keys });
|
|
29
|
-
exports.app.use(middlewares_1.someSecurity)
|
|
30
|
-
.use((0, middlewares_1.sessions)(exports.app))
|
|
31
|
-
.use(middlewares_1.prepareState)
|
|
32
|
-
.use(middlewares_1.headRequests)
|
|
33
|
-
.use((0, log_1.log)())
|
|
34
|
-
.use(throttler_1.throttler)
|
|
35
|
-
.use(middlewares_1.gzipper)
|
|
36
|
-
.use((0, plugins_1.pluginsMiddleware)())
|
|
37
|
-
.use((0, koa_mount_1.default)(const_1.API_URI, (0, apiMiddleware_1.apiMiddleware)({ ...frontEndApis_1.frontEndApis, ...adminApis_1.adminApis })))
|
|
38
|
-
.use(middlewares_1.serveGuiAndSharedFiles)
|
|
39
|
-
.on('error', errorHandler);
|
|
40
|
-
function errorHandler(err) {
|
|
41
|
-
const { code } = err;
|
|
42
|
-
if (const_1.DEV && code === 'ENOENT' && err.path.endsWith('sockjs-node'))
|
|
43
|
-
return; // spam out dev stuff
|
|
44
|
-
if (code === 'ECANCELED' || code === 'ECONNRESET' || code === 'ECONNABORTED' || code === 'EPIPE')
|
|
45
|
-
return; // someone interrupted, don't care
|
|
46
|
-
console.error('server error', err);
|
|
47
|
-
}
|
|
48
|
-
process.on('uncaughtException', err => {
|
|
49
|
-
if (err.syscall !== 'watch')
|
|
50
|
-
console.error(err);
|
|
51
|
-
});
|
|
52
|
-
(0, config_1.defineConfig)('proxies', 0).sub(n => {
|
|
53
|
-
exports.app.proxy = n > 0;
|
|
54
|
-
exports.app.maxIpsCount = n;
|
|
55
|
-
});
|
package/src/listen.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is part of HFS - Copyright 2021-2022, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.getUrls = exports.getStatus = exports.httpsPortCfg = exports.openAdmin = exports.portCfg = void 0;
|
|
31
|
-
const http = __importStar(require("http"));
|
|
32
|
-
const config_1 = require("./config");
|
|
33
|
-
const index_1 = require("./index");
|
|
34
|
-
const https = __importStar(require("https"));
|
|
35
|
-
const watchLoad_1 = require("./watchLoad");
|
|
36
|
-
const os_1 = require("os");
|
|
37
|
-
const connections_1 = require("./connections");
|
|
38
|
-
const open_1 = __importDefault(require("open"));
|
|
39
|
-
const misc_1 = require("./misc");
|
|
40
|
-
const const_1 = require("./const");
|
|
41
|
-
const find_process_1 = __importDefault(require("find-process"));
|
|
42
|
-
const perm_1 = require("./perm");
|
|
43
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
44
|
-
let httpSrv;
|
|
45
|
-
let httpsSrv;
|
|
46
|
-
const openBrowserAtStart = (0, config_1.defineConfig)('open_browser_at_start', !const_1.DEV);
|
|
47
|
-
exports.portCfg = (0, config_1.defineConfig)('port', 80);
|
|
48
|
-
exports.portCfg.sub(async (port) => {
|
|
49
|
-
while (!index_1.app)
|
|
50
|
-
await (0, misc_1.wait)(100);
|
|
51
|
-
stopServer(httpSrv).then();
|
|
52
|
-
httpSrv = Object.assign(http.createServer(index_1.app.callback()), { name: 'http' });
|
|
53
|
-
port = await startServer(httpSrv, { port });
|
|
54
|
-
if (!port)
|
|
55
|
-
return;
|
|
56
|
-
httpSrv.on('connection', connections_1.newConnection);
|
|
57
|
-
printUrls(port, 'http');
|
|
58
|
-
if (openBrowserAtStart.get())
|
|
59
|
-
openAdmin();
|
|
60
|
-
});
|
|
61
|
-
function openAdmin() {
|
|
62
|
-
for (const srv of [httpSrv, httpsSrv]) {
|
|
63
|
-
const a = srv.address();
|
|
64
|
-
if (!a || typeof a === 'string')
|
|
65
|
-
continue;
|
|
66
|
-
const baseUrl = srv.name + '://localhost:' + a.port;
|
|
67
|
-
(0, open_1.default)(baseUrl + const_1.ADMIN_URI, { wait: true }).catch(e => {
|
|
68
|
-
console.debug(String(e));
|
|
69
|
-
console.warn("cannot launch browser on this machine >PLEASE< open your browser and reach one of these (you may need a different address)", ...Object.values(getUrls()).flat().map(x => '\n - ' + x + const_1.ADMIN_URI));
|
|
70
|
-
if (!(0, perm_1.anyAccountCanLoginAdmin)())
|
|
71
|
-
console.log(`HINT: you can enter command: create-admin YOUR_PASSWORD`);
|
|
72
|
-
});
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
console.log("openAdmin failed");
|
|
76
|
-
}
|
|
77
|
-
exports.openAdmin = openAdmin;
|
|
78
|
-
const considerHttps = (0, misc_1.debounceAsync)(async () => {
|
|
79
|
-
var _a, _b;
|
|
80
|
-
stopServer(httpsSrv).then();
|
|
81
|
-
let port = exports.httpsPortCfg.get();
|
|
82
|
-
try {
|
|
83
|
-
while (!index_1.app)
|
|
84
|
-
await (0, misc_1.wait)(100);
|
|
85
|
-
httpsSrv = Object.assign(https.createServer(port < 0 ? {} : { key: httpsOptions.private_key, cert: httpsOptions.cert }, index_1.app.callback()), { name: 'https', error: undefined });
|
|
86
|
-
if (port >= 0) {
|
|
87
|
-
const namesForOutput = { cert: 'certificate', private_key: 'private key' };
|
|
88
|
-
const missing = (_a = httpsNeeds.find(x => !x.get())) === null || _a === void 0 ? void 0 : _a.key();
|
|
89
|
-
if (missing)
|
|
90
|
-
return httpsSrv.error = "missing " + namesForOutput[missing];
|
|
91
|
-
const cantRead = (_b = httpsNeeds.find(x => !httpsOptions[x.key()])) === null || _b === void 0 ? void 0 : _b.key();
|
|
92
|
-
if (cantRead)
|
|
93
|
-
return httpsSrv.error = "cannot read " + namesForOutput[cantRead];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
catch (e) {
|
|
97
|
-
httpsSrv.error = "bad private key or certificate";
|
|
98
|
-
console.log("failed to create https server: check your private key and certificate", String(e));
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
port = await startServer(httpsSrv, { port });
|
|
102
|
-
if (!port)
|
|
103
|
-
return;
|
|
104
|
-
httpsSrv.on('connection', connections_1.newConnection);
|
|
105
|
-
printUrls(port, 'https');
|
|
106
|
-
});
|
|
107
|
-
const cert = (0, config_1.defineConfig)('cert');
|
|
108
|
-
const privateKey = (0, config_1.defineConfig)('private_key');
|
|
109
|
-
const httpsNeeds = [cert, privateKey];
|
|
110
|
-
const httpsOptions = { cert: '', private_key: '' };
|
|
111
|
-
for (const cfg of httpsNeeds) {
|
|
112
|
-
let unwatch;
|
|
113
|
-
cfg.sub(async (v) => {
|
|
114
|
-
unwatch === null || unwatch === void 0 ? void 0 : unwatch();
|
|
115
|
-
const k = cfg.key();
|
|
116
|
-
httpsOptions[k] = v;
|
|
117
|
-
if (!v || v.includes('\n'))
|
|
118
|
-
return considerHttps();
|
|
119
|
-
// v is a path
|
|
120
|
-
httpsOptions[k] = '';
|
|
121
|
-
unwatch = (0, watchLoad_1.watchLoad)(v, data => {
|
|
122
|
-
httpsOptions[k] = data;
|
|
123
|
-
considerHttps();
|
|
124
|
-
}).unwatch;
|
|
125
|
-
await considerHttps();
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
exports.httpsPortCfg = (0, config_1.defineConfig)('https_port', -1);
|
|
129
|
-
exports.httpsPortCfg.sub(considerHttps);
|
|
130
|
-
function startServer(srv, { port, host }) {
|
|
131
|
-
return new Promise(async (resolve) => {
|
|
132
|
-
try {
|
|
133
|
-
if (port < 0 || !host && !await testIpV4()) // !host means ipV4+6, and if v4 port alone is busy we won't be notified of the failure, so we'll first test it on its own
|
|
134
|
-
return resolve(0);
|
|
135
|
-
port = await listen(host);
|
|
136
|
-
if (port)
|
|
137
|
-
console.log(srv.name, "serving on", host || "any network", ':', port);
|
|
138
|
-
resolve(port);
|
|
139
|
-
}
|
|
140
|
-
catch (e) {
|
|
141
|
-
srv.error = String(e);
|
|
142
|
-
console.error(srv.name, "couldn't listen on port", port, srv.error);
|
|
143
|
-
resolve(0);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
async function testIpV4() {
|
|
147
|
-
const res = await listen('0.0.0.0');
|
|
148
|
-
await new Promise(res => srv.close(res));
|
|
149
|
-
return res > 0;
|
|
150
|
-
}
|
|
151
|
-
function listen(host) {
|
|
152
|
-
return new Promise(async (resolve, reject) => {
|
|
153
|
-
srv.listen({ port, host }, () => {
|
|
154
|
-
const ad = srv.address();
|
|
155
|
-
if (!ad)
|
|
156
|
-
return reject('no address');
|
|
157
|
-
if (typeof ad === 'string') {
|
|
158
|
-
srv.close();
|
|
159
|
-
return reject('type of socket not supported');
|
|
160
|
-
}
|
|
161
|
-
resolve(ad.port);
|
|
162
|
-
}).on('error', async (e) => {
|
|
163
|
-
srv.error = String(e);
|
|
164
|
-
srv.busy = undefined;
|
|
165
|
-
const { code } = e;
|
|
166
|
-
if (code === 'EADDRINUSE') {
|
|
167
|
-
srv.busy = (0, find_process_1.default)('port', port).then(res => { var _a; return ((_a = res === null || res === void 0 ? void 0 : res[0]) === null || _a === void 0 ? void 0 : _a.name) || ''; }, () => '');
|
|
168
|
-
srv.error = `port ${port} busy: ${await srv.busy || "unknown process"}`;
|
|
169
|
-
}
|
|
170
|
-
console.error(srv.name, srv.error);
|
|
171
|
-
const k = (srv === httpSrv ? exports.portCfg : exports.httpsPortCfg).key();
|
|
172
|
-
console.log(` >> try specifying a different port, enter this command: config ${k} 8011`);
|
|
173
|
-
resolve(0);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
function stopServer(srv) {
|
|
179
|
-
return new Promise(resolve => {
|
|
180
|
-
if (!(srv === null || srv === void 0 ? void 0 : srv.listening))
|
|
181
|
-
return resolve(null);
|
|
182
|
-
const ad = srv.address();
|
|
183
|
-
if (ad && typeof ad !== 'string')
|
|
184
|
-
console.log("stopped port", ad.port);
|
|
185
|
-
srv.close(err => {
|
|
186
|
-
if (err && err.code !== 'ERR_SERVER_NOT_RUNNING')
|
|
187
|
-
console.debug("failed to stop server", String(err));
|
|
188
|
-
resolve(err);
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
function getStatus() {
|
|
193
|
-
return {
|
|
194
|
-
httpSrv,
|
|
195
|
-
httpsSrv,
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
exports.getStatus = getStatus;
|
|
199
|
-
const ignore = /^(lo|.*loopback.*|virtualbox.*|.*\(wsl\).*|llw\d|awdl\d|utun\d|anpi\d)$/i; // avoid giving too much information
|
|
200
|
-
function getUrls() {
|
|
201
|
-
return Object.fromEntries((0, misc_1.onlyTruthy)([httpSrv, httpsSrv].map(srv => {
|
|
202
|
-
var _a;
|
|
203
|
-
if (!(srv === null || srv === void 0 ? void 0 : srv.listening))
|
|
204
|
-
return false;
|
|
205
|
-
const port = (_a = srv === null || srv === void 0 ? void 0 : srv.address()) === null || _a === void 0 ? void 0 : _a.port;
|
|
206
|
-
const appendPort = port === (srv.name === 'https' ? 443 : 80) ? '' : ':' + port;
|
|
207
|
-
const urls = (0, misc_1.onlyTruthy)(Object.entries((0, os_1.networkInterfaces)()).map(([name, nets]) => nets && !ignore.test(name) && nets.map(net => {
|
|
208
|
-
if (net.internal)
|
|
209
|
-
return;
|
|
210
|
-
let { address } = net;
|
|
211
|
-
if (address.includes(':'))
|
|
212
|
-
address = '[' + address + ']';
|
|
213
|
-
return srv.name + '://' + address + appendPort;
|
|
214
|
-
})).flat());
|
|
215
|
-
return urls.length && [srv.name, urls];
|
|
216
|
-
})));
|
|
217
|
-
}
|
|
218
|
-
exports.getUrls = getUrls;
|
|
219
|
-
function printUrls(port, proto) {
|
|
220
|
-
if (!port)
|
|
221
|
-
return;
|
|
222
|
-
for (const [name, nets] of Object.entries((0, os_1.networkInterfaces)())) {
|
|
223
|
-
if (!nets || ignore.test(name))
|
|
224
|
-
continue;
|
|
225
|
-
lodash_1.default.remove(nets, 'internal');
|
|
226
|
-
if (!nets.length)
|
|
227
|
-
continue;
|
|
228
|
-
const best = lodash_1.default.find(nets, { family: 'IPv4' }) || nets[0];
|
|
229
|
-
const appendPort = port === (proto === 'https' ? 443 : 80) ? '' : ':' + port;
|
|
230
|
-
let { address } = best;
|
|
231
|
-
if (address.includes(':'))
|
|
232
|
-
address = '[' + address + ']';
|
|
233
|
-
console.log('network', name, proto + '://' + address + appendPort);
|
|
234
|
-
}
|
|
235
|
-
}
|