@lzwme/sserver 0.0.9 → 0.0.11
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/LICENSE +21 -21
- package/README.MD +40 -0
- package/bin/sserver.js +0 -0
- package/dist/cli.js +25 -1
- package/dist/config.d.ts +15 -5
- package/dist/config.js +10 -2
- package/dist/get-logger.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/lib/get-cert.js +11 -11
- package/dist/lib/mkcert.js +5 -5
- package/dist/lib/utils.js +3 -3
- package/dist/localsend/index.html +531 -0
- package/dist/localsend.d.ts +19 -0
- package/dist/localsend.js +217 -0
- package/dist/proxy/express-proxy.d.ts +1 -1
- package/dist/proxy/express-proxy.js +2 -2
- package/dist/proxy/php-proxy.d.ts +1 -1
- package/dist/proxy/php-proxy.js +35 -13
- package/dist/proxy/socket-proxy.js +2 -2
- package/dist/static-server.js +8 -3
- package/package.json +15 -11
- package/ss.config.sample.js +8 -0
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 任侠
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 任侠
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.MD
CHANGED
|
@@ -47,6 +47,9 @@ ss -H --host local.lzw.me
|
|
|
47
47
|
|
|
48
48
|
# 启用 https,并保存默认生成的 ssl 证书
|
|
49
49
|
ss -H --ssl-cache ./cache
|
|
50
|
+
|
|
51
|
+
# 开启 localsend 局域网文件传输功能
|
|
52
|
+
ss --localsend
|
|
50
53
|
```
|
|
51
54
|
|
|
52
55
|
### 配置代理转发
|
|
@@ -86,6 +89,43 @@ module.exports = {
|
|
|
86
89
|
}
|
|
87
90
|
```
|
|
88
91
|
|
|
92
|
+
### LocalSend 局域网文件传输
|
|
93
|
+
|
|
94
|
+
开启后可通过 `http://<本机IP>:<port>/localsend` 访问,实现同网段设备间的文件快速传输(支持多文件上传/下载、实时进度、二维码扫码访问、扫码直连下载、文件预览与排序等):
|
|
95
|
+
|
|
96
|
+
下载时按文件大小自动分流:**大于 50MB 的文件**交由浏览器原生下载(流式写盘,内存占用恒定,不会因为大文件撑爆浏览器内存),**小文件**仍在页面内显示实时进度与速度;批量下载为串行执行,避免多个大文件同时占用内存。
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# 命令行方式开启
|
|
100
|
+
ss --localsend
|
|
101
|
+
|
|
102
|
+
# 指定文件存储目录(也可用环境变量 SS_LOCALSEND_DIR 指定)
|
|
103
|
+
ss --localsend --localsend-dir /tmp/localsend
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
配置文件方式开启:
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
// ss.config.js
|
|
110
|
+
module.exports = {
|
|
111
|
+
port: 8888,
|
|
112
|
+
localsend: {
|
|
113
|
+
enabled: true,
|
|
114
|
+
// 文件存储目录。默认 ~/.static-server/localsend,可用环境变量 SS_LOCALSEND_DIR 覆盖
|
|
115
|
+
dir: '/tmp/localsend',
|
|
116
|
+
// 单个文件上传大小限制(字节),默认 1GB
|
|
117
|
+
maxSize: 1024 * 1024 * 1024,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
中文文件名上传后显示乱码时(多见于旧版本上传的文件),可用以下命令批量修复存储目录中的乱码文件名:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# 修复存储目录中的乱码文件名(默认使用配置中的目录,也可用 --localsend-dir 指定)
|
|
126
|
+
ss fix-localsend-names
|
|
127
|
+
```
|
|
128
|
+
|
|
89
129
|
## 开发
|
|
90
130
|
|
|
91
131
|
本地二次开发:
|
package/bin/sserver.js
CHANGED
|
File without changes
|
package/dist/cli.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const node_fs_1 = require("node:fs");
|
|
4
|
+
const node_os_1 = require("node:os");
|
|
4
5
|
const node_path_1 = require("node:path");
|
|
5
6
|
const commander_1 = require("commander");
|
|
6
7
|
const console_log_colors_1 = require("console-log-colors");
|
|
7
8
|
const config_1 = require("./config");
|
|
8
9
|
const get_logger_1 = require("./get-logger");
|
|
10
|
+
const localsend_1 = require("./localsend");
|
|
9
11
|
const static_server_1 = require("./static-server");
|
|
10
12
|
const pkg = require('../package.json');
|
|
11
13
|
commander_1.program
|
|
12
14
|
.aliases(['ss'])
|
|
13
15
|
.version(pkg.version, '-v, --version')
|
|
14
|
-
.description(console_log_colors_1.color.yellow(pkg.description)
|
|
16
|
+
.description(`${console_log_colors_1.color.yellow(pkg.description)} [version@${console_log_colors_1.color.cyanBright(pkg.version)}]`)
|
|
15
17
|
// .option('-c, --config-path [filepath]', `配置文件 ${color.yellow(config.configPath)} 的路径`)
|
|
16
18
|
.option('-d, --root-dir [dirpath]', '静态服务器的根目录路径')
|
|
17
19
|
.option('-a, --autoindex', '是否开启目录列表浏览')
|
|
@@ -26,6 +28,8 @@ commander_1.program
|
|
|
26
28
|
.option('--cors', '是否启用 cors。会全局设置 cors 的 header')
|
|
27
29
|
.option('--no-cors', '是否禁用 cors')
|
|
28
30
|
.option('--log [dirpath]', `指定日志路径`)
|
|
31
|
+
.option('--localsend', '开启 localsend 局域网文件传输功能')
|
|
32
|
+
.option('--localsend-dir <dir>', 'localsend 文件存储目录。默认 ~/.static-server/localsend,可用环境变量 SS_LOCALSEND_DIR 覆盖')
|
|
29
33
|
.option('--debug', `开启调试模式。`, false)
|
|
30
34
|
.action(async (opts) => {
|
|
31
35
|
if (opts.cert)
|
|
@@ -42,6 +46,9 @@ commander_1.program
|
|
|
42
46
|
'Cross-Origin-Embedder-Policy': 'require-corp',
|
|
43
47
|
};
|
|
44
48
|
}
|
|
49
|
+
if (opts.localsend) {
|
|
50
|
+
opts.localsend = { enabled: true, dir: opts.localsendDir || undefined };
|
|
51
|
+
}
|
|
45
52
|
(0, config_1.getConfig)(false, opts).then(() => (0, static_server_1.initServer)());
|
|
46
53
|
});
|
|
47
54
|
commander_1.program
|
|
@@ -61,4 +68,21 @@ commander_1.program
|
|
|
61
68
|
(0, node_fs_1.writeFileSync)(confFile, (0, node_fs_1.readFileSync)(tplFile));
|
|
62
69
|
get_logger_1.logger.info('已生成配置文件:', console_log_colors_1.color.greenBright(confFile));
|
|
63
70
|
});
|
|
71
|
+
commander_1.program
|
|
72
|
+
.command('fix-localsend-names')
|
|
73
|
+
.description('修复 localsend 存储目录中因编码问题产生的乱码文件名')
|
|
74
|
+
.option('--localsend-dir <dir>', 'localsend 文件存储目录。默认使用配置中的目录')
|
|
75
|
+
.action(async (opts) => {
|
|
76
|
+
const config = await (0, config_1.getConfig)(false, opts.localsendDir ? { localsend: { enabled: true, dir: opts.localsendDir } } : {});
|
|
77
|
+
const ls = typeof config.localsend === 'object' && config.localsend ? config.localsend : {};
|
|
78
|
+
const dir = opts.localsendDir || ls.dir || process.env.SS_LOCALSEND_DIR || (0, node_path_1.resolve)((0, node_os_1.homedir)(), '.static-server/localsend');
|
|
79
|
+
const renamed = (0, localsend_1.repairLocalsendNames)(dir);
|
|
80
|
+
if (!renamed.length) {
|
|
81
|
+
get_logger_1.logger.info('未发现乱码文件名。目录:', console_log_colors_1.color.cyanBright(dir));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
for (const [from, to] of renamed)
|
|
85
|
+
get_logger_1.logger.info(`已重命名:${console_log_colors_1.color.yellow(from)} → ${console_log_colors_1.color.greenBright(to)}`);
|
|
86
|
+
get_logger_1.logger.info(`共修复 ${console_log_colors_1.color.cyanBright(renamed.length)} 个文件名。目录:`, console_log_colors_1.color.cyanBright(dir));
|
|
87
|
+
});
|
|
64
88
|
commander_1.program.parse(process.argv);
|
package/dist/config.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { Stats } from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
1
|
+
import { type Stats } from 'node:fs';
|
|
2
|
+
import type { ServerOptions } from 'node:https';
|
|
3
|
+
import { type color, type NLogger } from '@lzwme/fe-utils';
|
|
4
|
+
import type { Express, Response } from 'express';
|
|
5
|
+
import type { Options } from 'http-proxy-middleware';
|
|
6
|
+
export interface LocalSendConfig {
|
|
7
|
+
/** 是否开启 localsend 局域网文件传输功能 */
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
/** 文件存储目录。默认 ~/.static-server/localsend,可通过环境变量 SS_LOCALSEND_DIR 指定 */
|
|
10
|
+
dir?: string;
|
|
11
|
+
/** 单个文件上传大小限制(字节)。默认 1GB */
|
|
12
|
+
maxSize?: number;
|
|
13
|
+
}
|
|
6
14
|
export interface SSConfig {
|
|
7
15
|
/** 是否开启目录列表 */
|
|
8
16
|
autoindex?: boolean;
|
|
@@ -12,6 +20,8 @@ export interface SSConfig {
|
|
|
12
20
|
host?: string;
|
|
13
21
|
/** 是否开启日志记录。默认为 false。若设置为 true 则默认为 ~/.sserver/log.log;若为字符串,则设置为日志路径 */
|
|
14
22
|
log?: boolean | string;
|
|
23
|
+
/** localsend 局域网文件传输功能。可设置为 true 开启,或传入配置对象 */
|
|
24
|
+
localsend?: LocalSendConfig | boolean;
|
|
15
25
|
/** 启动后是否打开首页 */
|
|
16
26
|
open?: boolean;
|
|
17
27
|
/** 监听端口号。默认 80,开启 https 则为 443 */
|
package/dist/config.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getConfig = getConfig;
|
|
4
|
-
const node_path_1 = require("node:path");
|
|
5
|
-
const node_os_1 = require("node:os");
|
|
6
4
|
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_os_1 = require("node:os");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
7
|
const fe_utils_1 = require("@lzwme/fe-utils");
|
|
8
8
|
const get_logger_1 = require("./get-logger");
|
|
9
9
|
const get_cert_1 = require("./lib/get-cert");
|
|
@@ -32,6 +32,14 @@ async function getConfig(useCache = true, cfg) {
|
|
|
32
32
|
if (cfg)
|
|
33
33
|
(0, fe_utils_1.assign)(ssConfig, cfg);
|
|
34
34
|
ssConfig.rootDir = (0, node_path_1.resolve)(process.cwd(), typeof ssConfig.rootDir === 'string' ? ssConfig.rootDir : '.');
|
|
35
|
+
// localsend 配置归一化:支持 true / 配置对象,支持环境变量 SS_LOCALSEND_DIR 指定存储目录
|
|
36
|
+
if (ssConfig.localsend) {
|
|
37
|
+
const localsend = typeof ssConfig.localsend === 'boolean' ? { enabled: ssConfig.localsend } : { ...ssConfig.localsend };
|
|
38
|
+
localsend.enabled = typeof ssConfig.localsend === 'boolean' ? ssConfig.localsend : localsend.enabled !== false;
|
|
39
|
+
localsend.dir = process.env.SS_LOCALSEND_DIR || localsend.dir || (0, node_path_1.resolve)((0, node_os_1.homedir)(), '.static-server/localsend');
|
|
40
|
+
localsend.maxSize = localsend.maxSize || 1024 * 1024 * 1024;
|
|
41
|
+
ssConfig.localsend = localsend;
|
|
42
|
+
}
|
|
35
43
|
if (ssConfig.log) {
|
|
36
44
|
get_logger_1.logger.setLogDir(typeof ssConfig.log === 'boolean' ? (0, node_path_1.resolve)((0, node_os_1.homedir)(), '.sserver/log.log') : ssConfig.log);
|
|
37
45
|
}
|
package/dist/get-logger.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.logger = void 0;
|
|
4
|
-
const console_log_colors_1 = require("console-log-colors");
|
|
5
4
|
const fe_utils_1 = require("@lzwme/fe-utils");
|
|
5
|
+
const console_log_colors_1 = require("console-log-colors");
|
|
6
6
|
function getLogger(levelType, logDir) {
|
|
7
7
|
return fe_utils_1.NLogger.getLogger('[sserver]', { levelType, color: console_log_colors_1.color, logDir });
|
|
8
8
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/lib/get-cert.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCert = getCert;
|
|
4
|
-
const
|
|
5
|
-
const promises_1 = require("fs/promises");
|
|
6
|
-
const
|
|
7
|
-
const path_1 = require("path");
|
|
8
|
-
const get_logger_1 = require("../get-logger");
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
9
7
|
const console_log_colors_1 = require("console-log-colors");
|
|
8
|
+
const get_logger_1 = require("../get-logger");
|
|
9
|
+
const mkcert_1 = require("./mkcert");
|
|
10
10
|
async function getCert(host = 'localhost', cacheDir = '') {
|
|
11
11
|
const result = {
|
|
12
12
|
caKey: '',
|
|
@@ -15,16 +15,16 @@ async function getCert(host = 'localhost', cacheDir = '') {
|
|
|
15
15
|
certCrt: '',
|
|
16
16
|
};
|
|
17
17
|
const dirs = {
|
|
18
|
-
caKey: (0,
|
|
19
|
-
caCrt: (0,
|
|
20
|
-
certKey: (0,
|
|
21
|
-
certCrt: (0,
|
|
18
|
+
caKey: (0, node_path_1.resolve)(cacheDir, 'ca.key'),
|
|
19
|
+
caCrt: (0, node_path_1.resolve)(cacheDir, 'ca.crt'),
|
|
20
|
+
certKey: (0, node_path_1.resolve)(cacheDir, `${host}.key`),
|
|
21
|
+
certCrt: (0, node_path_1.resolve)(cacheDir, `${host}.crt`),
|
|
22
22
|
};
|
|
23
23
|
if (cacheDir) {
|
|
24
|
-
if (!(0,
|
|
24
|
+
if (!(0, node_fs_1.existsSync)(cacheDir))
|
|
25
25
|
(0, promises_1.mkdir)(cacheDir, { recursive: true });
|
|
26
26
|
for (const [key, filepath] of Object.entries(dirs)) {
|
|
27
|
-
if ((0,
|
|
27
|
+
if ((0, node_fs_1.existsSync)(filepath))
|
|
28
28
|
result[key] = await (0, promises_1.readFile)(filepath, 'utf8');
|
|
29
29
|
}
|
|
30
30
|
}
|
package/dist/lib/mkcert.js
CHANGED
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.generateCert = generateCert;
|
|
5
5
|
exports.createCA = createCA;
|
|
6
6
|
exports.createCert = createCert;
|
|
7
|
+
const node_util_1 = require("node:util");
|
|
7
8
|
const node_forge_1 = require("node-forge");
|
|
8
|
-
const
|
|
9
|
-
const generateKeyPair = (0, util_1.promisify)(node_forge_1.pki.rsa.generateKeyPair.bind(node_forge_1.pki.rsa));
|
|
9
|
+
const generateKeyPair = (0, node_util_1.promisify)(node_forge_1.pki.rsa.generateKeyPair.bind(node_forge_1.pki.rsa));
|
|
10
10
|
async function generateCert(options) {
|
|
11
|
-
|
|
11
|
+
const { subject, issuer, extensions = [], validityDays = 36500, signWith } = options;
|
|
12
12
|
// create serial from and integer between 50000 and 99999
|
|
13
13
|
const serial = Math.floor(Math.random() * 95000 + 50000).toString();
|
|
14
14
|
const keyPair = await generateKeyPair({ bits: 2048, workers: 4 });
|
|
@@ -45,7 +45,7 @@ function createCert(options) {
|
|
|
45
45
|
// certificate Attributes: https://git.io/fptna
|
|
46
46
|
if (!options.subject)
|
|
47
47
|
options.subject = [];
|
|
48
|
-
if (!options.subject.find(d => d.name === 'commonName')) {
|
|
48
|
+
if (!options.subject.find((d) => d.name === 'commonName')) {
|
|
49
49
|
// use the first address as common name
|
|
50
50
|
options.subject.push({ name: 'commonName', value: options.domains[0] });
|
|
51
51
|
}
|
|
@@ -56,7 +56,7 @@ function createCert(options) {
|
|
|
56
56
|
{ name: 'extKeyUsage', serverAuth: true, clientAuth: true },
|
|
57
57
|
{
|
|
58
58
|
name: 'subjectAltName',
|
|
59
|
-
altNames: options.domains.map(domain => {
|
|
59
|
+
altNames: options.domains.map((domain) => {
|
|
60
60
|
const types = { domain: 2, ip: 7 }; // available Types: https://git.io/fptng
|
|
61
61
|
const isIp = isIP(domain);
|
|
62
62
|
if (isIp)
|
package/dist/lib/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getIp = getIp;
|
|
4
|
-
const
|
|
4
|
+
const node_os_1 = require("node:os");
|
|
5
5
|
function getIp() {
|
|
6
|
-
const nif = (0,
|
|
6
|
+
const nif = (0, node_os_1.networkInterfaces)();
|
|
7
7
|
let list = [];
|
|
8
8
|
for (const key of Object.keys(nif)) {
|
|
9
9
|
for (const item of nif[key]) {
|
|
@@ -11,7 +11,7 @@ function getIp() {
|
|
|
11
11
|
list.push(item);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
list = list.sort((
|
|
14
|
+
list = list.sort((_a, b) => {
|
|
15
15
|
if (b.address.startsWith('172.'))
|
|
16
16
|
return -1;
|
|
17
17
|
return 0;
|