hfs 0.52.0-beta4 → 0.52.0-beta6
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 +2 -3
- package/admin/assets/index-4CQRk-yB.css +1 -0
- package/admin/assets/index-sqjqhfQh.js +810 -0
- package/admin/assets/{sha512-3tDoWWX4.js → sha512-t1dU12Dj.js} +1 -1
- package/admin/index.html +2 -2
- package/frontend/assets/index-fqsRmx7w.css +1 -0
- package/frontend/assets/index-w_Bu3TcZ.js +101 -0
- package/frontend/assets/{sha512-I2H28VIm.js → sha512-U8GKU-vd.js} +1 -1
- package/frontend/index.html +2 -3
- package/package.json +3 -3
- package/src/acme.js +29 -12
- package/src/adminApis.js +3 -3
- package/src/api.get_file_list.js +2 -1
- package/src/api.monitor.js +3 -1
- package/src/api.net.js +3 -1
- package/src/api.vfs.js +6 -1
- package/src/apiMiddleware.js +1 -1
- package/src/block.js +1 -1
- package/src/connections.js +3 -1
- package/src/const.js +2 -2
- package/src/cross.js +16 -4
- package/src/geo.js +1 -1
- package/src/index.js +1 -1
- package/src/langs/hfs-lang-fi.json +37 -5
- package/src/langs/hfs-lang-it.json +6 -2
- package/src/langs/hfs-lang-nl.json +20 -3
- package/src/langs/hfs-lang-ru.json +21 -3
- package/src/langs/hfs-lang-vi.json +68 -22
- package/src/langs/hfs-lang-zh.json +13 -5
- package/src/listen.js +4 -3
- package/src/log.js +11 -2
- package/src/middlewares.js +2 -2
- package/src/misc.js +2 -1
- package/src/roots.js +1 -1
- package/src/selfCheck.js +4 -5
- package/src/serveGuiAndSharedFiles.js +6 -6
- package/src/serveGuiFiles.js +56 -43
- package/src/update.js +5 -4
- package/src/upload.js +5 -4
- package/src/util-files.js +1 -1
- package/src/util-os.js +53 -15
- package/src/vfs.js +9 -5
- package/admin/assets/index-gtPWo_px.js +0 -809
- package/admin/assets/index-oSvCg3xb.css +0 -1
- package/frontend/assets/index-Kys6yJtN.css +0 -1
- package/frontend/assets/index-SY22o0dA.js +0 -101
- package/plugins/download-counter/storage/counters.yaml +0 -663
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"author": "
|
|
3
|
-
"version": 1
|
|
4
|
-
"hfs_version": "0.
|
|
2
|
+
"author": "thenoppy12 (Nguyễn Văn Ngu)",
|
|
3
|
+
"version": 2.1,
|
|
4
|
+
"hfs_version": "0.52.0",
|
|
5
5
|
"translate": {
|
|
6
6
|
"Select": "Chọn",
|
|
7
7
|
"n_files": "{n,plural,one{# tập tin} other{# tập tin}}",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"zip_tooltip_whole": "Tải xuống toàn bộ danh sách (chưa được lọc) dưới dạng một tệp zip. Nếu bạn chọn một số mục, chỉ những phần tử đó sẽ được tải xuống.",
|
|
16
16
|
"zip_confirm_search": "Tải xuống TẤT CẢ kết quả của tìm kiếm này dưới dạng lưu trữ ZIP?",
|
|
17
17
|
"zip_confirm_folder": "Tải xuống TOÀN BỘ thư mục dưới dạng lưu trữ ZIP?",
|
|
18
|
-
"select_tooltip": "Lựa chọn áp dụng cho \"Zip\" và \"
|
|
18
|
+
"select_tooltip": "Lựa chọn áp dụng cho \"Zip\" và \"Xoá\" (nếu có), nhưng bạn cũng có thể lọc danh sách",
|
|
19
19
|
"delete_hint": "Để xóa, trước tiên hãy nhấp vào \"Chọn\"",
|
|
20
20
|
"delete_confirm": "Xoá {n,plural, one{# cái} other{# cái}}?",
|
|
21
21
|
"delete_completed": "Xóa: {n} thành công",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"Options": "Tùy chọn",
|
|
26
26
|
"Search": "Tìm kiếm",
|
|
27
27
|
"Zip": "Zip",
|
|
28
|
-
"search_msg": "
|
|
28
|
+
"search_msg": "Gõ tên file cần tìm ↓",
|
|
29
29
|
"Searching": "Đang tìm",
|
|
30
30
|
"Searched": "Đã tìm xong!",
|
|
31
31
|
"Clear search": "Xoá tìm kiếm",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"stopped_before": "Đã dừng",
|
|
34
34
|
"empty_list": "Trống",
|
|
35
35
|
"filter_none": "Ko có gì để lọc",
|
|
36
|
-
"Admin-panel": "
|
|
36
|
+
"Admin-panel": "Admin-panel",
|
|
37
37
|
"Login": "Đăng nhập nàh",
|
|
38
38
|
"Username": "Username",
|
|
39
|
-
"Password": "
|
|
39
|
+
"Password": "Password",
|
|
40
40
|
"login_untrusted": "Đăng nhập bị hủy bỏ: danh tính máy chủ không tin cậy",
|
|
41
41
|
"login_bad_credentials": "Thông tin đăng nhập SAI",
|
|
42
42
|
"login_bad_cookies": "Cookies không hoạt động - đăng nhập không thành công",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"Pick folder": "Chọn folders",
|
|
60
60
|
"send_files": "Gửi {n,plural,one{# file} other{# file}}, {size}",
|
|
61
61
|
"Clear": "Dẹp",
|
|
62
|
-
"failed_upload": "
|
|
63
|
-
"confirm_resume": "
|
|
64
|
-
"file too large": "File NẶNG VÃI
|
|
62
|
+
"failed_upload": "Không thể up {name}",
|
|
63
|
+
"confirm_resume": "Tiếp tục up?",
|
|
64
|
+
"file too large": "File NẶNG VÃI, SẬP SERVER GIỜ :V",
|
|
65
65
|
"Enter folder name": "Nhập tên folder",
|
|
66
66
|
"Successfully created": "Tạo folder thành công!",
|
|
67
67
|
"enter_folder": "Nhập thư mục",
|
|
@@ -86,31 +86,77 @@
|
|
|
86
86
|
"Warning": "Cảnh báo",
|
|
87
87
|
"Error": "Lỗi",
|
|
88
88
|
"Info": "Thông tin",
|
|
89
|
-
"Unauthorized": "
|
|
89
|
+
"Unauthorized": "Không có quyền",
|
|
90
90
|
"Forbidden": "Thư mục / file này CẤM vào",
|
|
91
|
-
"Not found": "
|
|
91
|
+
"Not found": "Không thấy",
|
|
92
92
|
"Server error": "Lỗi vật lý (server)",
|
|
93
93
|
"Upload": "Up",
|
|
94
94
|
"upload_concluded": "Tải lên đã kết thúc:",
|
|
95
95
|
"upload_finished": "{n} thành công ({size})",
|
|
96
96
|
"upload_errors": "{n} thất bại",
|
|
97
97
|
"upload_file_rejected": "Một số file server không chấp nhận",
|
|
98
|
-
"
|
|
98
|
+
"Download counter": "Bộ đếm download",
|
|
99
99
|
"File menu": "File menu",
|
|
100
100
|
"Folder menu": "Folder menu",
|
|
101
101
|
"Name": "Tên",
|
|
102
|
-
"file_open": "Mở
|
|
103
|
-
"Download": "Tải
|
|
104
|
-
"Missing permission": "Thiếu quyền
|
|
102
|
+
"file_open": "Mở",
|
|
103
|
+
"Download": "Tải",
|
|
104
|
+
"Missing permission": "Thiếu quyền",
|
|
105
105
|
"Reload": "Tải lại",
|
|
106
|
-
"Get list": "Lấy
|
|
107
|
-
"Skip existing files": "Bỏ qua
|
|
108
|
-
"Size": "
|
|
106
|
+
"Get list": "Lấy list",
|
|
107
|
+
"Skip existing files": "Bỏ qua file có sẳn",
|
|
108
|
+
"Size": "Kích cỡ",
|
|
109
109
|
"Timestamp": "Mốc thời gian",
|
|
110
110
|
"Show": "Hiện",
|
|
111
|
-
"Loading failed": "Load
|
|
111
|
+
"Loading failed": "Load thất bại (?)",
|
|
112
112
|
"Rename": "Đổi tên",
|
|
113
|
-
"
|
|
114
|
-
"
|
|
113
|
+
"Tiles mode:": "Chia ô:",
|
|
114
|
+
"off": "Tắt",
|
|
115
|
+
"Operation successful": "Thành công",
|
|
116
|
+
"Uploader": "Người upload",
|
|
117
|
+
"Switch zoom mode": "Chuyển qua mode zoom",
|
|
118
|
+
"Full screen": "Full màn",
|
|
119
|
+
"File Show help": "File Show help",
|
|
120
|
+
"showHelpMain": "Có thể dùng bàn phím ntn:",
|
|
121
|
+
"showHelp_←/→": "←/→",
|
|
122
|
+
"showHelp_↑/↓": "↑/↓",
|
|
123
|
+
"showHelp_space": "cách",
|
|
124
|
+
"showHelp_←/→_body": "tới file trước/file tiếp",
|
|
125
|
+
"showHelp_↑/↓_body": "scroll tall images (cant be translated)",
|
|
126
|
+
"showHelp_space_body": "chọn",
|
|
127
|
+
"showHelp_D_body": "tải",
|
|
128
|
+
"showHelp_Z_body": "mode zoom",
|
|
129
|
+
"showHelp_F_body": "full màn",
|
|
130
|
+
"Destination": "Đến",
|
|
131
|
+
"in_queue": "{n} ở hàng chờ",
|
|
132
|
+
"enter_comment": "Comment của file",
|
|
133
|
+
"Comment": "Comment",
|
|
134
|
+
"upload_dd_hint": "Có thể up file = cách thả lên màn hình",
|
|
135
|
+
"Upload not available": "Upload còn đang fix",
|
|
136
|
+
"Cut": "Cắt",
|
|
137
|
+
"good_bad": "{good} đã di chuyển, {bad} thất bại",
|
|
138
|
+
"after_cut": "Cái đã chọn đã lưu trong clipboard.\nTới folder khác để dán.",
|
|
139
|
+
"Cancel clipboard": "Bỏ clipboard",
|
|
140
|
+
"to_clipboard_source": "Tới folder",
|
|
141
|
+
"Paste": "Dán",
|
|
142
|
+
"clipboard_list": "Clipboard:",
|
|
143
|
+
"Close": "Đóng",
|
|
144
|
+
"Folder": "Thư mục",
|
|
145
|
+
"Web page": "Trang web",
|
|
146
|
+
"Link": "Link",
|
|
147
|
+
"Auto-play": "Tự động phát",
|
|
148
|
+
"autoplay_seconds": "Số giây chờ ảnh",
|
|
149
|
+
"Select all": "Chọn hết",
|
|
150
|
+
"go_first": "Tới trước",
|
|
151
|
+
"go_last": "Tới sau",
|
|
152
|
+
"Shuffle": "Ngẫu nhiên",
|
|
153
|
+
"Repeat": "Lặp",
|
|
154
|
+
"showHelpListShortcut": "Ở file list, giữ {key} để Hiện nhanh chóng",
|
|
155
|
+
"Invalid value": "🤷 what u think something in ur freakin' brain?",
|
|
156
|
+
"upload_skipped": "{n} đã bỏ qua",
|
|
157
|
+
"Overwrite policy": "Chính sách ghi đè",
|
|
158
|
+
"Rename to avoid overwriting": "Đổi tên để tránh ghi đè file có sẳn",
|
|
159
|
+
"Overwrite existing files": "Ghi đè file có sẳn",
|
|
160
|
+
"Menu": "Menu"
|
|
115
161
|
}
|
|
116
162
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"author": "yx3016 & MircoH0 & CMJNB",
|
|
3
|
-
"version": 1.
|
|
2
|
+
"author": "yx3016 & MircoH0 & CMJNB & Cheuksing",
|
|
3
|
+
"version": 1.5,
|
|
4
4
|
"hfs_version": "0.50.0",
|
|
5
5
|
"translate": {
|
|
6
6
|
"Select": "选择",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"empty_list": "空",
|
|
35
35
|
"filter_none": "无过滤",
|
|
36
36
|
"Admin-panel": "管理面板",
|
|
37
|
-
"Login": "
|
|
37
|
+
"Login": "登录",
|
|
38
38
|
"Username": "用户名",
|
|
39
39
|
"Password": "密码",
|
|
40
40
|
"login_untrusted": "登录中止:服务器标识不可信!",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"Skip existing files": "跳过已存在的文件",
|
|
107
107
|
"Size": "大小",
|
|
108
108
|
"Timestamp": "时间戳",
|
|
109
|
-
"Show": "
|
|
109
|
+
"Show": "显示/播放",
|
|
110
110
|
"Loading failed": "加载失败",
|
|
111
111
|
"Rename": "重命名",
|
|
112
112
|
"Tiles mode:": "图标平铺模式:",
|
|
@@ -132,6 +132,14 @@
|
|
|
132
132
|
"enter_comment": "对此文件的评论",
|
|
133
133
|
"Comment": "评论",
|
|
134
134
|
"upload_dd_hint": "您可以将文件拖放到文件列表中进行上传",
|
|
135
|
-
"Upload not available": "上传不可用"
|
|
135
|
+
"Upload not available": "上传不可用",
|
|
136
|
+
"Cut": "剪切",
|
|
137
|
+
"n_items": "{n,plural, one{# item} other{# items}}",
|
|
138
|
+
"good_bad": "{good}个已移动, {bad}个失败",
|
|
139
|
+
"after_cut": "您的选择已成功添加到剪贴板,\n请前往目标文件夹粘贴。",
|
|
140
|
+
"Cancel clipboard": "取消剪贴板",
|
|
141
|
+
"to_clipboard_source": "至文件夹",
|
|
142
|
+
"Paste": "粘贴",
|
|
143
|
+
"clipboard_list": "剪贴板文件:"
|
|
136
144
|
}
|
|
137
145
|
}
|
package/src/listen.js
CHANGED
|
@@ -58,11 +58,12 @@ function getHttpsWorkingPort() {
|
|
|
58
58
|
return (httpsSrv === null || httpsSrv === void 0 ? void 0 : httpsSrv.listening) && ((_a = httpsSrv.address()) === null || _a === void 0 ? void 0 : _a.port);
|
|
59
59
|
}
|
|
60
60
|
exports.getHttpsWorkingPort = getHttpsWorkingPort;
|
|
61
|
-
const
|
|
61
|
+
const commonServerOptions = { requestTimeout: 0 };
|
|
62
|
+
const commonServerAssign = { headersTimeout: 30000, timeout: misc_1.MINUTE }; // 'headersTimeout' is not recognized by type lib, and 'timeout' is not effective when passed in parameters
|
|
62
63
|
const considerHttp = (0, misc_1.debounceAsync)(async () => {
|
|
63
64
|
await (0, misc_1.waitFor)(() => index_1.app);
|
|
64
65
|
stopServer(httpSrv).then();
|
|
65
|
-
httpSrv = Object.assign(http.createServer(
|
|
66
|
+
httpSrv = Object.assign(http.createServer(commonServerOptions, index_1.app.callback()), { name: 'http' }, commonServerAssign);
|
|
66
67
|
const port = await startServer(httpSrv, { port: exports.portCfg.get(), host: listenInterface.get() });
|
|
67
68
|
if (!port)
|
|
68
69
|
return;
|
|
@@ -110,7 +111,7 @@ const considerHttps = (0, misc_1.debounceAsync)(async () => {
|
|
|
110
111
|
let port = exports.httpsPortCfg.get();
|
|
111
112
|
try {
|
|
112
113
|
await (0, misc_1.waitFor)(() => index_1.app);
|
|
113
|
-
httpsSrv = Object.assign(https.createServer(port === const_1.PORT_DISABLED ? {} : { ...
|
|
114
|
+
httpsSrv = Object.assign(https.createServer(port === const_1.PORT_DISABLED ? {} : { ...commonServerOptions, key: httpsOptions.private_key, cert: httpsOptions.cert }, index_1.app.callback()), { name: 'https' }, commonServerAssign);
|
|
114
115
|
if (port >= 0) {
|
|
115
116
|
const cert = getCertObject();
|
|
116
117
|
if (cert) {
|
package/src/log.js
CHANGED
|
@@ -158,12 +158,21 @@ function doubleDigit(n) {
|
|
|
158
158
|
return n > 9 ? n : '0' + n;
|
|
159
159
|
}
|
|
160
160
|
// dump console.error to file
|
|
161
|
-
|
|
162
|
-
debugLogFile.
|
|
161
|
+
let debugLogFile = (0, fs_1.createWriteStream)('debug.log', { flags: 'a' });
|
|
162
|
+
debugLogFile.once('open', () => {
|
|
163
163
|
const was = console.error;
|
|
164
164
|
console.error = function (...args) {
|
|
165
165
|
was.apply(this, args);
|
|
166
166
|
args = args.map(x => { var _a; return typeof x === 'string' ? x : ((_a = (0, misc_1.tryJson)(x)) !== null && _a !== void 0 ? _a : String(x)); });
|
|
167
167
|
debugLogFile.write(new Date().toLocaleString() + ': ' + args.join(' ') + '\n');
|
|
168
168
|
};
|
|
169
|
+
// limit log size
|
|
170
|
+
const LIMIT = 1000000;
|
|
171
|
+
const { path } = debugLogFile;
|
|
172
|
+
(0, misc_1.repeat)(misc_1.DAY, () => {
|
|
173
|
+
if ((0, fs_1.statSync)(path).size < LIMIT)
|
|
174
|
+
return; // no need
|
|
175
|
+
(0, fs_1.renameSync)(path, 'old-' + path);
|
|
176
|
+
debugLogFile = (0, fs_1.createWriteStream)(path, { flags: 'w' }); // new file
|
|
177
|
+
});
|
|
169
178
|
}).on('error', () => console.log("cannot create debug.log"));
|
package/src/middlewares.js
CHANGED
|
@@ -75,8 +75,8 @@ const someSecurity = async (ctx, next) => {
|
|
|
75
75
|
catch (_a) {
|
|
76
76
|
return ctx.status = const_1.HTTP_FOOL;
|
|
77
77
|
}
|
|
78
|
-
if (!ctx.state.skipFilters && forceBaseUrl.get() && !(0, misc_1.isLocalHost)(ctx) && ctx.host !== listen_1.baseUrl.compiled())
|
|
79
|
-
return (0, connections_1.disconnect)(ctx);
|
|
78
|
+
if (!ctx.state.skipFilters && forceBaseUrl.get() && listen_1.baseUrl.compiled() && !(0, misc_1.isLocalHost)(ctx) && ctx.host !== listen_1.baseUrl.compiled())
|
|
79
|
+
return (0, connections_1.disconnect)(ctx, 'force-domain');
|
|
80
80
|
if (!ctx.secure && forceHttps.get() && (0, listen_1.getHttpsWorkingPort)() && !(0, misc_1.isLocalHost)(ctx)) {
|
|
81
81
|
const { URL } = ctx;
|
|
82
82
|
URL.protocol = 'https';
|
package/src/misc.js
CHANGED
|
@@ -50,7 +50,8 @@ function onFirstEvent(emitter, events, cb) {
|
|
|
50
50
|
}
|
|
51
51
|
exports.onFirstEvent = onFirstEvent;
|
|
52
52
|
function pattern2filter(pattern) {
|
|
53
|
-
const matcher = (0, cross_1.makeMatcher)(pattern.includes('*') ? pattern
|
|
53
|
+
const matcher = (0, cross_1.makeMatcher)(pattern.includes('*') ? pattern // if you specify *, we'll respect its position
|
|
54
|
+
: pattern.split('|').map(x => `*${x}*`).join('|'));
|
|
54
55
|
return (s) => !s || !pattern || matcher((0, path_1.basename)(s));
|
|
55
56
|
}
|
|
56
57
|
exports.pattern2filter = pattern2filter;
|
package/src/roots.js
CHANGED
|
@@ -41,7 +41,7 @@ const rootsMiddleware = (ctx, next) => (() => {
|
|
|
41
41
|
if (root === undefined) {
|
|
42
42
|
if (ctx.state.skipFilters || !rootsMandatory.get() || (0, misc_1.isLocalHost)(ctx))
|
|
43
43
|
return;
|
|
44
|
-
(0, connections_1.disconnect)(ctx);
|
|
44
|
+
(0, connections_1.disconnect)(ctx, 'no-root');
|
|
45
45
|
return true; // true will avoid calling next
|
|
46
46
|
}
|
|
47
47
|
if (!params) {
|
package/src/selfCheck.js
CHANGED
|
@@ -13,11 +13,10 @@ const util_http_1 = require("./util-http");
|
|
|
13
13
|
let selfChecking = false;
|
|
14
14
|
const CHECK_URL = cross_const_1.SPECIAL_URI + 'self-check';
|
|
15
15
|
const selfCheckMiddleware = async (ctx, next) => {
|
|
16
|
-
if (selfChecking
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
await next();
|
|
16
|
+
if (!selfChecking || !ctx.url.startsWith(CHECK_URL))
|
|
17
|
+
return next();
|
|
18
|
+
ctx.body = 'HFS';
|
|
19
|
+
ctx.state.skipFilters = true;
|
|
21
20
|
};
|
|
22
21
|
exports.selfCheckMiddleware = selfCheckMiddleware;
|
|
23
22
|
async function selfCheck(url) {
|
|
@@ -55,7 +55,7 @@ const serveGuiAndSharedFiles = async (ctx, next) => {
|
|
|
55
55
|
}
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
if (ctx.originalUrl
|
|
58
|
+
if (/^\/favicon.ico(\??.*)/.test(ctx.originalUrl) && adminApis_1.favicon.get()) // originalUrl to not be subject to changes (vhosting plugin)
|
|
59
59
|
return (0, serveFile_1.serveFile)(ctx, adminApis_1.favicon.get());
|
|
60
60
|
let node = await (0, vfs_1.urlToNode)(path, ctx);
|
|
61
61
|
if (!node)
|
|
@@ -85,11 +85,11 @@ const serveGuiAndSharedFiles = async (ctx, next) => {
|
|
|
85
85
|
if (node.default && path.endsWith('/') && !get) // final/ needed on browser to make resource urls correctly with html pages
|
|
86
86
|
node = (_a = await (0, vfs_1.urlToNode)(node.default, ctx, node)) !== null && _a !== void 0 ? _a : node;
|
|
87
87
|
if (!await (0, vfs_1.nodeIsDirectory)(node))
|
|
88
|
-
return !node.source ? (0, errorPages_1.sendErrorPage)(ctx, cross_const_1.HTTP_METHOD_NOT_ALLOWED)
|
|
89
|
-
: !(0, vfs_1.statusCodeForMissingPerm)(node, 'can_read', ctx) ? (0, serveFile_1.serveFileNode)(ctx, node)
|
|
90
|
-
: ctx.status !== cross_const_1.HTTP_UNAUTHORIZED ? null
|
|
91
|
-
:
|
|
92
|
-
: (ctx.
|
|
88
|
+
return !node.source ? (0, errorPages_1.sendErrorPage)(ctx, cross_const_1.HTTP_METHOD_NOT_ALLOWED) // !dir && !source is not supported at this moment
|
|
89
|
+
: !(0, vfs_1.statusCodeForMissingPerm)(node, 'can_read', ctx) ? (0, serveFile_1.serveFileNode)(ctx, node) // all good
|
|
90
|
+
: ctx.status !== cross_const_1.HTTP_UNAUTHORIZED ? null // all errors don't need extra handling, except unauthorized
|
|
91
|
+
: path.endsWith('/') ? (ctx.state.serveApp = true) && serveFrontendFiles(ctx, next) // since this is no dir, final / means we are dealing with default file, for which we still provide fancy login
|
|
92
|
+
: (ctx.set('WWW-Authenticate', 'Basic'), (0, errorPages_1.sendErrorPage)(ctx)); // this is necessary to support standard urls with credentials
|
|
93
93
|
if (!path.endsWith('/'))
|
|
94
94
|
return ctx.redirect(ctx.state.revProxyPath + ctx.originalUrl.replace(/(\?|$)/, '/$1')); // keep query-string, if any
|
|
95
95
|
if ((0, vfs_1.statusCodeForMissingPerm)(node, 'can_list', ctx)) {
|
package/src/serveGuiFiles.js
CHANGED
|
@@ -42,6 +42,7 @@ const customHtml_1 = require("./customHtml");
|
|
|
42
42
|
const lodash_1 = __importDefault(require("lodash"));
|
|
43
43
|
const config_1 = require("./config");
|
|
44
44
|
const lang_1 = require("./lang");
|
|
45
|
+
const upload_1 = require("./upload");
|
|
45
46
|
exports.logGui = (0, config_1.defineConfig)(misc_1.CFG.log_gui, false);
|
|
46
47
|
lodash_1.default.each(misc_1.FRONTEND_OPTIONS, (v, k) => (0, config_1.defineConfig)(k, v)); // define default values
|
|
47
48
|
// in case of dev env we have our static files within the 'dist' folder'
|
|
@@ -84,6 +85,10 @@ function adjustBundlerLinks(ctx, uri, data) {
|
|
|
84
85
|
return ext && !ext.match(/\.(css|html|js|ts|scss)/) ? data
|
|
85
86
|
: String(data).replace(/((?:import[ (]| from )['"])\//g, `$1${ctx.state.revProxyPath}${uri}`);
|
|
86
87
|
}
|
|
88
|
+
const getFaviconTimestamp = (0, misc_1.debounceAsync)(async () => {
|
|
89
|
+
const f = adminApis_1.favicon.get();
|
|
90
|
+
return !f ? 0 : promises_1.default.stat(f).then(x => (x === null || x === void 0 ? void 0 : x.mtimeMs) || 0, () => 0);
|
|
91
|
+
}, 0, { retain: 5000 });
|
|
87
92
|
async function treatIndex(ctx, filesUri, body) {
|
|
88
93
|
const session = await (0, api_auth_1.refresh_session)({}, ctx);
|
|
89
94
|
ctx.set('etag', '');
|
|
@@ -102,51 +107,59 @@ async function treatIndex(ctx, filesUri, body) {
|
|
|
102
107
|
configs = ((_b = (_a = (0, plugins_1.getPluginInfo)(name)).onFrontendConfig) === null || _b === void 0 ? void 0 : _b.call(_a, configs)) || configs;
|
|
103
108
|
return !lodash_1.default.isEmpty(configs) && [name, configs];
|
|
104
109
|
})));
|
|
110
|
+
const timestamp = await getFaviconTimestamp();
|
|
105
111
|
const lang = await (0, lang_1.getLangData)(ctx);
|
|
106
|
-
|
|
112
|
+
return body
|
|
107
113
|
.replace(/((?:src|href) *= *['"])\/?(?!([a-z]+:\/)?\/)/g, '$1' + ctx.state.revProxyPath + filesUri)
|
|
108
|
-
.replace(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
114
|
+
.replace(/<(\/)?(head|body)>/g, (all, isClose, name) => {
|
|
115
|
+
const isHead = name === 'head';
|
|
116
|
+
const isBody = !isHead;
|
|
117
|
+
const isOpen = !isClose;
|
|
118
|
+
if (isHead && isOpen)
|
|
119
|
+
return all + `
|
|
120
|
+
${!isFrontend ? '' : `
|
|
121
|
+
<title>${adminApis_1.title.get()}</title>
|
|
122
|
+
<link rel="shortcut icon" href="/favicon.ico?${timestamp}" />
|
|
123
|
+
` + (0, customHtml_1.getSection)('htmlHead')}
|
|
124
|
+
<script>
|
|
125
|
+
HFS = ${JSON.stringify({
|
|
126
|
+
VERSION: const_1.VERSION,
|
|
127
|
+
API_VERSION: const_1.API_VERSION,
|
|
128
|
+
SPECIAL_URI: const_1.SPECIAL_URI, PLUGINS_PUB_URI: const_1.PLUGINS_PUB_URI, FRONTEND_URI: const_1.FRONTEND_URI,
|
|
129
|
+
session: session instanceof apiMiddleware_1.ApiError ? null : session,
|
|
130
|
+
plugins,
|
|
131
|
+
prefixUrl: ctx.state.revProxyPath,
|
|
132
|
+
dontOverwriteUploading: upload_1.dontOverwriteUploading.get(),
|
|
133
|
+
customHtml: lodash_1.default.omit(Object.fromEntries(customHtml_1.customHtmlState.sections), ['top', 'bottom']),
|
|
134
|
+
...(0, misc_1.newObj)(misc_1.FRONTEND_OPTIONS, (v, k) => (0, config_1.getConfig)(k)),
|
|
135
|
+
lang
|
|
136
|
+
}, null, 4).replace(/<(\/script)/g, '<"+"$1') /*avoid breaking our script container*/}
|
|
137
|
+
document.documentElement.setAttribute('ver', '${const_1.VERSION.split('-')[0] /*for style selectors*/}')
|
|
138
|
+
</script>
|
|
139
|
+
`;
|
|
140
|
+
if (isBody && isOpen)
|
|
141
|
+
return all + `
|
|
142
|
+
${!isFrontend ? '' : (0, customHtml_1.getSection)('top')}
|
|
143
|
+
<style>
|
|
144
|
+
:root {
|
|
145
|
+
${lodash_1.default.map(plugins, (configs, pluginName) => lodash_1.default.map(configs, (v, k) => `--${pluginName}-${k}: ${serializeCss(v)};`).join('\n')).join('')}
|
|
146
|
+
}
|
|
147
|
+
</style>
|
|
148
|
+
${!isFrontend ? '' : (0, plugins_1.mapPlugins)((plug, id) => {
|
|
149
|
+
var _a;
|
|
150
|
+
return (_a = plug.frontend_css) === null || _a === void 0 ? void 0 : _a.map(f => `<link rel='stylesheet' type='text/css' href='${f.includes('//') ? f : pub + id + '/' + f}' plugin=${JSON.stringify(id)}/>`);
|
|
151
|
+
})
|
|
152
|
+
.flat().filter(Boolean).join('\n')}
|
|
153
|
+
${!isFrontend ? '' : (0, plugins_1.mapPlugins)((plug, id) => {
|
|
154
|
+
var _a;
|
|
155
|
+
return (_a = plug.frontend_js) === null || _a === void 0 ? void 0 : _a.map(f => `<script defer plugin=${JSON.stringify(id)} src='${f.includes('//') ? f : pub + id + '/' + f}'></script>`);
|
|
156
|
+
})
|
|
157
|
+
.flat().filter(Boolean).join('\n')}
|
|
158
|
+
`;
|
|
159
|
+
if (isBody && isClose)
|
|
160
|
+
return (0, customHtml_1.getSection)('bottom') + all;
|
|
161
|
+
return all; // unchanged
|
|
162
|
+
});
|
|
150
163
|
}
|
|
151
164
|
function serializeCss(v) {
|
|
152
165
|
return typeof v === 'string' && /^#[0-9a-fA-F]{3,8}|rgba?\(.+\)$/.test(v) ? v
|
package/src/update.js
CHANGED
|
@@ -15,6 +15,7 @@ const plugins_1 = require("./plugins");
|
|
|
15
15
|
const promises_1 = require("fs/promises");
|
|
16
16
|
const open_1 = __importDefault(require("open"));
|
|
17
17
|
const config_1 = require("./config");
|
|
18
|
+
const util_os_1 = require("./util-os");
|
|
18
19
|
const updateToBeta = (0, config_1.defineConfig)('update_to_beta', false);
|
|
19
20
|
async function getUpdates() {
|
|
20
21
|
const stable = await (0, github_1.getRepoInfo)(const_1.HFS_REPO + '/releases/latest');
|
|
@@ -59,12 +60,12 @@ function localUpdateAvailable() {
|
|
|
59
60
|
return (0, promises_1.access)(LOCAL_UPDATE).then(() => true, () => false);
|
|
60
61
|
}
|
|
61
62
|
exports.localUpdateAvailable = localUpdateAvailable;
|
|
62
|
-
function updateSupported() {
|
|
63
|
-
return const_1.IS_BINARY;
|
|
63
|
+
async function updateSupported() {
|
|
64
|
+
return const_1.IS_BINARY && !await util_os_1.RUNNING_AS_SERVICE;
|
|
64
65
|
}
|
|
65
66
|
exports.updateSupported = updateSupported;
|
|
66
67
|
async function update(tagOrUrl = '') {
|
|
67
|
-
if (!updateSupported())
|
|
68
|
+
if (!await updateSupported())
|
|
68
69
|
throw "only binary versions supports automatic update for now";
|
|
69
70
|
let updateSource = tagOrUrl.includes('://') ? await (0, misc_1.httpStream)(tagOrUrl)
|
|
70
71
|
: await localUpdateAvailable() && (0, fs_1.createReadStream)(LOCAL_UPDATE);
|
|
@@ -114,7 +115,7 @@ async function update(tagOrUrl = '') {
|
|
|
114
115
|
console.log("launching new version in background", newBinFile);
|
|
115
116
|
launch(newBin, ['--updating', binFile], { sync: true }); // sync necessary to work on mac by double-click
|
|
116
117
|
});
|
|
117
|
-
console.log(
|
|
118
|
+
console.log("quitting");
|
|
118
119
|
setTimeout(() => process.exit()); // give time to return (and caller to complete, eg: rest api to reply)
|
|
119
120
|
}
|
|
120
121
|
catch (e) {
|
package/src/upload.js
CHANGED
|
@@ -18,7 +18,7 @@ const auth_1 = require("./auth");
|
|
|
18
18
|
const comments_1 = require("./comments");
|
|
19
19
|
exports.deleteUnfinishedUploadsAfter = (0, config_1.defineConfig)('delete_unfinished_uploads_after', 86400);
|
|
20
20
|
exports.minAvailableMb = (0, config_1.defineConfig)('min_available_mb', 100);
|
|
21
|
-
exports.dontOverwriteUploading = (0, config_1.defineConfig)('dont_overwrite_uploading',
|
|
21
|
+
exports.dontOverwriteUploading = (0, config_1.defineConfig)('dont_overwrite_uploading', true);
|
|
22
22
|
const waitingToBeDeleted = {};
|
|
23
23
|
const ATTR_UPLOADER = 'uploader';
|
|
24
24
|
function getUploadMeta(path) {
|
|
@@ -43,7 +43,7 @@ function uploadWriter(base, path, ctx) {
|
|
|
43
43
|
const reqSize = Number(ctx.headers["content-length"]);
|
|
44
44
|
if (reqSize)
|
|
45
45
|
try {
|
|
46
|
-
const free = (0, util_os_1.
|
|
46
|
+
const { free } = (0, util_os_1.getDiskSpaceSync)(dir);
|
|
47
47
|
if (typeof free !== 'number' || isNaN(free))
|
|
48
48
|
throw '';
|
|
49
49
|
if (reqSize > free - (min || 0))
|
|
@@ -52,7 +52,7 @@ function uploadWriter(base, path, ctx) {
|
|
|
52
52
|
catch (e) { // warn, but let it through
|
|
53
53
|
console.warn("can't check disk size:", e.message || String(e));
|
|
54
54
|
}
|
|
55
|
-
if (ctx.query.
|
|
55
|
+
if (ctx.query.existing === 'skip' && fs_1.default.existsSync(fullPath))
|
|
56
56
|
return fail(const_1.HTTP_CONFLICT);
|
|
57
57
|
if (fs_1.default.mkdirSync(dir, { recursive: true }))
|
|
58
58
|
setUploadMeta(dir, ctx);
|
|
@@ -116,7 +116,8 @@ function uploadWriter(base, path, ctx) {
|
|
|
116
116
|
});
|
|
117
117
|
return ret;
|
|
118
118
|
async function overwriteAnyway() {
|
|
119
|
-
if (ctx.query.overwrite === undefined
|
|
119
|
+
if (ctx.query.overwrite === undefined // legacy pre-0.52
|
|
120
|
+
&& ctx.query.existing !== 'overwrite')
|
|
120
121
|
return;
|
|
121
122
|
const n = await (0, vfs_1.getNodeByName)(path, base);
|
|
122
123
|
return n && (0, vfs_1.hasPermission)(n, 'can_delete', ctx);
|
package/src/util-files.js
CHANGED
|
@@ -182,7 +182,7 @@ function createFileWithPath(path, options) {
|
|
|
182
182
|
}
|
|
183
183
|
exports.createFileWithPath = createFileWithPath;
|
|
184
184
|
function isValidFileName(name) {
|
|
185
|
-
return
|
|
185
|
+
return !/[/*?<>|\\]/.test(name) && !dirTraversal(name);
|
|
186
186
|
}
|
|
187
187
|
exports.isValidFileName = isValidFileName;
|
|
188
188
|
const FILE_ATTR_PREFIX = 'user.hfs.'; // user. prefix to be linux compatible
|
package/src/util-os.js
CHANGED
|
@@ -1,41 +1,79 @@
|
|
|
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.runCmd = exports.getDrives = exports.
|
|
6
|
+
exports.RUNNING_AS_SERVICE = exports.runCmd = exports.getDrives = exports.getDiskSpaces = exports.getDiskSpaceSync = void 0;
|
|
4
7
|
const path_1 = require("path");
|
|
5
8
|
const child_process_1 = require("child_process");
|
|
6
9
|
const misc_1 = require("./misc");
|
|
10
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
11
|
+
const node_process_1 = require("node:process");
|
|
7
12
|
const util_1 = require("util");
|
|
8
13
|
const const_1 = require("./const");
|
|
9
|
-
function
|
|
10
|
-
var _a;
|
|
14
|
+
function getDiskSpaceSync(path) {
|
|
11
15
|
if (const_1.IS_WINDOWS) {
|
|
12
16
|
const drive = (0, path_1.resolve)(path).slice(0, 2).toUpperCase();
|
|
13
|
-
const out = (0, child_process_1.execSync)('wmic logicaldisk get FreeSpace,
|
|
14
|
-
const one = out
|
|
17
|
+
const out = (0, child_process_1.execSync)('wmic logicaldisk get Size,FreeSpace,Name /format:list').toString().replace(/\r/g, '');
|
|
18
|
+
const one = parseKeyValueObjects(out).find(x => x.Name === drive);
|
|
15
19
|
if (!one)
|
|
16
20
|
throw Error('miss');
|
|
17
|
-
return
|
|
21
|
+
return { free: Number(one.FreeSpace), total: Number(one.Size) };
|
|
22
|
+
}
|
|
23
|
+
const out = (0, misc_1.try_)(() => (0, child_process_1.execSync)(`df -k "${path}"`).toString(), err => { throw err.status === 1 ? Error('miss') : err.status === 127 ? Error('unsupported') : err; });
|
|
24
|
+
if (!(out === null || out === void 0 ? void 0 : out.startsWith('Filesystem')))
|
|
25
|
+
throw Error('unsupported');
|
|
26
|
+
const one = out.split('\n')[1];
|
|
27
|
+
const [used, free] = one.split(/\s+/).slice(2, 4).map(x => Number(x) * 1024);
|
|
28
|
+
return { free, total: used + free };
|
|
29
|
+
}
|
|
30
|
+
exports.getDiskSpaceSync = getDiskSpaceSync;
|
|
31
|
+
async function getDiskSpaces() {
|
|
32
|
+
var _a;
|
|
33
|
+
if (const_1.IS_WINDOWS) {
|
|
34
|
+
const fields = ['Size', 'FreeSpace', 'Name', 'Description'];
|
|
35
|
+
const out = await runCmd(`wmic logicaldisk get ${fields.join()} /format:list`);
|
|
36
|
+
const objs = parseKeyValueObjects(out);
|
|
37
|
+
return (0, misc_1.onlyTruthy)(objs.map(x => x.Size && {
|
|
38
|
+
total: Number(x.Size),
|
|
39
|
+
free: Number(x.FreeSpace),
|
|
40
|
+
name: x.Name,
|
|
41
|
+
description: x.Description
|
|
42
|
+
}));
|
|
18
43
|
}
|
|
19
|
-
const
|
|
44
|
+
const { stdout } = await (0, util_1.promisify)(child_process_1.exec)(`df -k`).catch(err => {
|
|
20
45
|
throw err.status === 1 ? Error('miss')
|
|
21
46
|
: err.status === 127 ? Error('unsupported')
|
|
22
47
|
: err;
|
|
23
48
|
});
|
|
24
|
-
|
|
49
|
+
const out = stdout.split('\n');
|
|
50
|
+
if (!((_a = out.shift()) === null || _a === void 0 ? void 0 : _a.startsWith('Filesystem')))
|
|
25
51
|
throw Error('unsupported');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
52
|
+
return (0, misc_1.onlyTruthy)(out.map(one => {
|
|
53
|
+
const bits = one.split(/\s+/);
|
|
54
|
+
const name = bits.shift() || '';
|
|
55
|
+
const [, used = 0, free = 0] = bits.map(x => Number(x) * 1024);
|
|
56
|
+
const total = used + free;
|
|
57
|
+
return total && { free, total, name };
|
|
58
|
+
}));
|
|
29
59
|
}
|
|
30
|
-
exports.
|
|
60
|
+
exports.getDiskSpaces = getDiskSpaces;
|
|
31
61
|
async function getDrives() {
|
|
32
|
-
const
|
|
62
|
+
const stdout = await runCmd('wmic logicaldisk get name');
|
|
33
63
|
return stdout.split('\n').slice(1).map(x => x.trim()).filter(Boolean);
|
|
34
64
|
}
|
|
35
65
|
exports.getDrives = getDrives;
|
|
36
66
|
// execute win32 shell commands
|
|
37
67
|
async function runCmd(cmd, args = []) {
|
|
38
|
-
const { stdout, stderr } = await (0, util_1.promisify)(child_process_1.
|
|
39
|
-
return stderr || stdout;
|
|
68
|
+
const { stdout, stderr } = await (0, util_1.promisify)(child_process_1.exec)(`@chcp 65001 >nul & cmd /c ${cmd} ${args.join(' ')}`, { encoding: 'utf-8' });
|
|
69
|
+
return (stderr || stdout).replace(/\r/g, '');
|
|
40
70
|
}
|
|
41
71
|
exports.runCmd = runCmd;
|
|
72
|
+
async function getWindowsServicePids() {
|
|
73
|
+
const res = await runCmd(`wmic service get ProcessId`);
|
|
74
|
+
return lodash_1.default.uniq(res.split('\n').slice(1).map(x => Number(x.trim())));
|
|
75
|
+
}
|
|
76
|
+
exports.RUNNING_AS_SERVICE = const_1.IS_WINDOWS && getWindowsServicePids().then(x => x.includes(node_process_1.pid));
|
|
77
|
+
function parseKeyValueObjects(all, keySep = '=', lineSep = '\n', objectSep = /\n\n+/) {
|
|
78
|
+
return all.split(objectSep).map(obj => Object.fromEntries(obj.split(lineSep).map(kv => (0, misc_1.splitAt)(keySep, kv))));
|
|
79
|
+
}
|