@maiyunnet/kebab 3.1.2 → 3.1.4
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/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/net.d.ts +5 -5
- package/lib/net.js +6 -6
- package/package.json +1 -1
- package/sys/route.d.ts +1 -1
- package/sys/route.js +9 -32
- package/tsconfig.json +26 -0
- package/types/index.d.ts +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* ------------------------
|
|
9
9
|
*/
|
|
10
10
|
/** --- 当前系统版本号 --- */
|
|
11
|
-
export const VER = '3.1.
|
|
11
|
+
export const VER = '3.1.4';
|
|
12
12
|
// --- 服务端用的路径 ---
|
|
13
13
|
const imu = import.meta.url.replace('file://', '').replace(/^\/(\w:)/, '$1').replace(/\\/g, '/');
|
|
14
14
|
/** --- /xxx/xxx --- */
|
package/lib/net.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import * as ctr from '#sys/ctr.js';
|
|
|
11
11
|
import * as types from '#types/index.js';
|
|
12
12
|
import * as fd from './net/formdata.js';
|
|
13
13
|
import * as lRequest from './net/request.js';
|
|
14
|
-
import * as
|
|
14
|
+
import * as lResponse from './net/response.js';
|
|
15
15
|
/** --- 请求的传入参数选项 --- */
|
|
16
16
|
export interface IRequestOptions {
|
|
17
17
|
'method'?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS';
|
|
@@ -74,26 +74,26 @@ export declare function open(u: string): lRequest.Request;
|
|
|
74
74
|
* @param u 请求的 URL
|
|
75
75
|
* @param opt 参数
|
|
76
76
|
*/
|
|
77
|
-
export declare function get(u: string, opt?: IRequestOptions): Promise<
|
|
77
|
+
export declare function get(u: string, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
78
78
|
/**
|
|
79
79
|
* --- 发起一个 post 请求 ---
|
|
80
80
|
* @param u 请求的 URL
|
|
81
81
|
* @param data 要发送的数据
|
|
82
82
|
* @param opt 参数
|
|
83
83
|
*/
|
|
84
|
-
export declare function post(u: string, data: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<
|
|
84
|
+
export declare function post(u: string, data: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
85
85
|
/**
|
|
86
86
|
* --- 发起 JSON 请求 ---
|
|
87
87
|
* @param u
|
|
88
88
|
* @param data
|
|
89
89
|
* @param opt
|
|
90
90
|
*/
|
|
91
|
-
export declare function postJson(u: string, data: types.Json[] | Record<string, types.Json>, opt?: IRequestOptions): Promise<
|
|
91
|
+
export declare function postJson(u: string, data: types.Json[] | Record<string, types.Json>, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
92
92
|
/**
|
|
93
93
|
* --- 发起一个请求 ---
|
|
94
94
|
* @param opt 配置项
|
|
95
95
|
*/
|
|
96
|
-
export declare function request(u: string, data?: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<
|
|
96
|
+
export declare function request(u: string, data?: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
97
97
|
/**
|
|
98
98
|
* --- 对 cookie 对象进行操作 ---
|
|
99
99
|
* @param cookie 要操作的对象
|
package/lib/net.js
CHANGED
|
@@ -15,7 +15,7 @@ import * as kebab from '#index.js';
|
|
|
15
15
|
// --- 自己 ---
|
|
16
16
|
import * as fd from './net/formdata.js';
|
|
17
17
|
import * as lRequest from './net/request.js';
|
|
18
|
-
import * as
|
|
18
|
+
import * as lResponse from './net/response.js';
|
|
19
19
|
/** --- ca 根证书内容 --- */
|
|
20
20
|
let ca = '';
|
|
21
21
|
/** --- 获取 CA 证书 --- */
|
|
@@ -28,7 +28,7 @@ export async function getCa() {
|
|
|
28
28
|
}
|
|
29
29
|
/** --- 复用的 hc 对象列表 --- */
|
|
30
30
|
const reuses = {
|
|
31
|
-
'default': hc.createHttpClient()
|
|
31
|
+
'default': hc.createHttpClient(),
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
34
|
* --- 创建一个请求对象 ---
|
|
@@ -129,7 +129,7 @@ export async function request(u, data, opt = {}) {
|
|
|
129
129
|
// --- 重定义 IP ---
|
|
130
130
|
const host = (puri ? puri.hostname : uri.hostname) ?? '';
|
|
131
131
|
if (!host) {
|
|
132
|
-
const res = new
|
|
132
|
+
const res = new lResponse.Response(null);
|
|
133
133
|
res.error = {
|
|
134
134
|
'name': 'Possible mProxy error',
|
|
135
135
|
'message': 'host not found'
|
|
@@ -137,7 +137,7 @@ export async function request(u, data, opt = {}) {
|
|
|
137
137
|
return res;
|
|
138
138
|
}
|
|
139
139
|
if (hosts[host] !== undefined && !hosts[host]) {
|
|
140
|
-
const res = new
|
|
140
|
+
const res = new lResponse.Response(null);
|
|
141
141
|
res.error = {
|
|
142
142
|
'name': 'hosts error',
|
|
143
143
|
'message': 'hosts param error'
|
|
@@ -165,7 +165,7 @@ export async function request(u, data, opt = {}) {
|
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
catch (err) {
|
|
168
|
-
const res = new
|
|
168
|
+
const res = new lResponse.Response(null);
|
|
169
169
|
res.error = err;
|
|
170
170
|
return res;
|
|
171
171
|
}
|
|
@@ -193,7 +193,7 @@ export async function request(u, data, opt = {}) {
|
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
// --- 创建 Response 对象 ---
|
|
196
|
-
const res = new
|
|
196
|
+
const res = new lResponse.Response(req);
|
|
197
197
|
if (total) {
|
|
198
198
|
res.setContent(total.toString());
|
|
199
199
|
}
|
package/package.json
CHANGED
package/sys/route.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-4-15 13:40
|
|
4
|
-
* Last: 2020-4-14 13:52:00, 2022-09-07 01:43:31, 2023-12-29 17:24:03, 2024-2-7 00:28:50, 2024-6-6 15:15:54, 2025-6-13 19:23:53
|
|
4
|
+
* Last: 2020-4-14 13:52:00, 2022-09-07 01:43:31, 2023-12-29 17:24:03, 2024-2-7 00:28:50, 2024-6-6 15:15:54, 2025-6-13 19:23:53, 2025-9-22 15:48:53
|
|
5
5
|
*/
|
|
6
6
|
import * as http from 'http';
|
|
7
7
|
import * as http2 from 'http2';
|
package/sys/route.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-4-15 13:40
|
|
4
|
-
* Last: 2020-4-14 13:52:00, 2022-09-07 01:43:31, 2023-12-29 17:24:03, 2024-2-7 00:28:50, 2024-6-6 15:15:54, 2025-6-13 19:23:53
|
|
4
|
+
* Last: 2020-4-14 13:52:00, 2022-09-07 01:43:31, 2023-12-29 17:24:03, 2024-2-7 00:28:50, 2024-6-6 15:15:54, 2025-6-13 19:23:53, 2025-9-22 15:48:53
|
|
5
5
|
*/
|
|
6
6
|
import * as http from 'http';
|
|
7
7
|
import * as stream from 'stream';
|
|
@@ -15,6 +15,7 @@ import * as lText from '#lib/text.js';
|
|
|
15
15
|
import * as lTime from '#lib/time.js';
|
|
16
16
|
import * as lResponse from '#lib/net/response.js';
|
|
17
17
|
import * as lWs from '#lib/ws.js';
|
|
18
|
+
import * as lLang from '#lib/lang.js';
|
|
18
19
|
import * as sCtr from './ctr.js';
|
|
19
20
|
import * as kebab from '#index.js';
|
|
20
21
|
/** --- 动态层 kebab.json 缓存(文件路径: 最终合并值) --- */
|
|
@@ -116,7 +117,7 @@ export async function run(data) {
|
|
|
116
117
|
if (lText.isFalsy(config.set.staticPathFull)) {
|
|
117
118
|
config.set.staticPathFull = config.const.urlStcFull;
|
|
118
119
|
}
|
|
119
|
-
|
|
120
|
+
/** --- data.path 是安全的,不会是 ../../ 来访问到了外层,已经做过处理 --- */
|
|
120
121
|
let path = data.path;
|
|
121
122
|
// --- 如果为空则定义为 @ ---
|
|
122
123
|
if (path === '') {
|
|
@@ -127,38 +128,14 @@ export async function run(data) {
|
|
|
127
128
|
if (config.lang && data.res) {
|
|
128
129
|
// --- 仅仅 res 模式支持 config.lang ---
|
|
129
130
|
if (path[2] !== '/') {
|
|
130
|
-
// --- 不管是首页还是 @
|
|
131
|
-
|
|
132
|
-
if (!path) {
|
|
133
|
-
if (config.lang.direct.includes('@')) {
|
|
134
|
-
isDirect = true;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
for (const ditem of config.lang.direct) {
|
|
139
|
-
if (!path.startsWith(ditem)) {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
// --- 放行 ---
|
|
143
|
-
isDirect = true;
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (!isDirect) {
|
|
131
|
+
// --- 不管是首页还是 @ 页,都会到此处(已经有语言目录不会到这里) ---
|
|
132
|
+
if (config.lang.direct.every(item => !path.startsWith(item))) {
|
|
148
133
|
// --- 不放行 ---
|
|
149
|
-
|
|
134
|
+
/** --- 浏览器语种 --- */
|
|
135
|
+
const lang = lLang.getCodeByAccept(data.req.headers['accept-language']?.toLowerCase() ?? config.lang.list[0]);
|
|
136
|
+
/** --- 组合要跳转的路径 --- */
|
|
150
137
|
const apath = config.const.path + (config.const.qs ? '?' + config.const.qs : '');
|
|
151
|
-
|
|
152
|
-
let checkLang = lang;
|
|
153
|
-
if (lang === 'sc') {
|
|
154
|
-
checkLang = 'cn';
|
|
155
|
-
}
|
|
156
|
-
else if (lang === 'tc') {
|
|
157
|
-
checkLang = 'zh';
|
|
158
|
-
}
|
|
159
|
-
if (!alang.includes(checkLang)) {
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
138
|
+
if (config.lang.list.includes(lang)) {
|
|
162
139
|
data.res.setHeader('location', config.const.urlBase + lang + '/' + apath);
|
|
163
140
|
data.res.writeHead(302);
|
|
164
141
|
data.res.end('');
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "esnext",
|
|
4
|
+
"removeComments": false,
|
|
5
|
+
"preserveConstEnums": true, // 保留 const 和 enum 声明
|
|
6
|
+
"outDir": "./",
|
|
7
|
+
"sourceMap": false,
|
|
8
|
+
"target": "ES2021",
|
|
9
|
+
"strict": true, // 严格模式
|
|
10
|
+
"declaration": true, // d.ts
|
|
11
|
+
"declarationMap": false, // d.ts 的 map
|
|
12
|
+
"newLine": "LF",
|
|
13
|
+
"paths": {
|
|
14
|
+
"#*": ["./*"]
|
|
15
|
+
},
|
|
16
|
+
"moduleResolution": "node",
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"esModuleInterop": true
|
|
19
|
+
},
|
|
20
|
+
"include": [
|
|
21
|
+
"./**/*.ts"
|
|
22
|
+
],
|
|
23
|
+
"exclude": [
|
|
24
|
+
"node_modules"
|
|
25
|
+
]
|
|
26
|
+
}
|