@maiyunnet/kebab 9.29.6 → 10.1.0
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/abox/proxy.js +24 -2
- package/abox/response.js +36 -17
- package/abox/session-login.js +1 -13
- package/doc/kebab-rag.md +1687 -1061
- package/index.d.ts +14 -2
- package/index.js +1 -1
- package/lib/ai.d.ts +4 -0
- package/lib/ai.js +32 -16
- package/lib/cookie.d.ts +2 -0
- package/lib/cookie.js +47 -45
- package/lib/core.d.ts +26 -0
- package/lib/core.js +36 -13
- package/lib/cron.js +1 -8
- package/lib/crypto.js +20 -6
- package/lib/db/conn.d.ts +4 -2
- package/lib/db/conn.js +1 -0
- package/lib/db/pool.d.ts +17 -4
- package/lib/db/pool.js +41 -23
- package/lib/db/tran.d.ts +6 -4
- package/lib/db.d.ts +10 -5
- package/lib/db.js +36 -6
- package/lib/fs.js +78 -31
- package/lib/kv.d.ts +182 -79
- package/lib/kv.js +518 -214
- package/lib/s3.d.ts +2 -0
- package/lib/s3.js +14 -27
- package/lib/session.d.ts +7 -0
- package/lib/session.js +23 -2
- package/lib/socket.d.ts +4 -1
- package/lib/socket.js +1 -0
- package/lib/sql.d.ts +0 -5
- package/lib/sql.js +48 -12
- package/lib/text.d.ts +10 -5
- package/lib/text.js +22 -12
- package/lib/turnstile.d.ts +6 -0
- package/lib/turnstile.js +16 -9
- package/lib/undici/response.d.ts +1 -1
- package/lib/undici.d.ts +7 -1
- package/lib/undici.js +72 -36
- package/lib/ws.d.ts +1 -1
- package/lib/ws.js +85 -128
- package/lib/zip.js +46 -45
- package/package.json +2 -2
- package/sys/child.js +178 -146
- package/sys/cmd.js +196 -210
- package/sys/ctr.d.ts +16 -16
- package/sys/ctr.js +147 -61
- package/sys/master.js +111 -80
- package/sys/mod.d.ts +24 -2
- package/sys/mod.js +56 -26
- package/sys/monitor/files.d.ts +2 -1
- package/sys/monitor/files.js +77 -21
- package/sys/monitor/watchdog.d.ts +7 -0
- package/sys/monitor/watchdog.js +311 -203
- package/sys/monitor.d.ts +59 -54
- package/sys/monitor.js +742 -681
- package/sys/route.d.ts +4 -4
- package/sys/route.js +93 -52
- package/www/example/ctr/test.d.ts +1 -1
- package/www/example/ctr/test.js +34 -15
- package/www/example/mod/test.js +0 -1
package/index.d.ts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* Date: 2019-3-30 12:46:41
|
|
4
4
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
5
5
|
*/
|
|
6
|
+
import type * as tls from 'node:tls';
|
|
6
7
|
/** --- 当前系统版本号 --- */
|
|
7
|
-
export declare const VER = "
|
|
8
|
+
export declare const VER = "10.1.0";
|
|
8
9
|
/** --- 框架根目录,以 / 结尾 --- */
|
|
9
10
|
export declare const ROOT_PATH: string;
|
|
10
11
|
/** --- 框架的 LIB,以 / 结尾 --- */
|
|
@@ -40,7 +41,8 @@ export interface IConfig {
|
|
|
40
41
|
'const': IConfigConst;
|
|
41
42
|
'db': Record<string, {
|
|
42
43
|
'default': IConfigDb;
|
|
43
|
-
|
|
44
|
+
/** --- 可选只读从库配置,支持单节点或节点数组;省略的字段自动继承 default --- */
|
|
45
|
+
'read'?: Partial<IConfigDb> | Array<Partial<IConfigDb>>;
|
|
44
46
|
}> & {
|
|
45
47
|
'default': 'MYSQL' | 'PGSQL';
|
|
46
48
|
};
|
|
@@ -130,12 +132,22 @@ export interface IConfigDns {
|
|
|
130
132
|
}
|
|
131
133
|
/** --- kv --- */
|
|
132
134
|
export interface IConfigKv {
|
|
135
|
+
/** --- 服务端地址(IP 或域名) --- */
|
|
133
136
|
'host': string;
|
|
137
|
+
/** --- 服务端端口 --- */
|
|
134
138
|
'port': number;
|
|
139
|
+
/** --- 数据库编号(0 起) --- */
|
|
135
140
|
'index': number;
|
|
141
|
+
/** --- 业务键名前缀 --- */
|
|
136
142
|
'pre': string;
|
|
143
|
+
/** --- ACL 用户名(留空则走传统单密码认证) --- */
|
|
137
144
|
'user': string;
|
|
145
|
+
/** --- 认证密码或 Kvrocks namespace token --- */
|
|
138
146
|
'pwd': string;
|
|
147
|
+
/** --- 为 true 时将非 0 的 index 折算为键名前缀(如 db1:),不再向服务端发 SELECT --- */
|
|
148
|
+
'dbPre'?: boolean;
|
|
149
|
+
/** --- 是否启用 TLS 连接;传入对象时自动启用 TLS 并透传证书/SNI 等参数(如 servername、ca) --- */
|
|
150
|
+
'tls'?: boolean | tls.ConnectionOptions;
|
|
139
151
|
}
|
|
140
152
|
/** --- sql --- */
|
|
141
153
|
export interface IConfigSql {
|
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
5
5
|
*/
|
|
6
6
|
/** --- 当前系统版本号 --- */
|
|
7
|
-
export const VER = '
|
|
7
|
+
export const VER = '10.1.0';
|
|
8
8
|
// --- 服务端用的路径 ---
|
|
9
9
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
10
10
|
/** --- /xxx/xxx --- */
|
package/lib/ai.d.ts
CHANGED
|
@@ -65,6 +65,8 @@ export declare class Ai {
|
|
|
65
65
|
constructor(ctrEtc: sCtr.Ctr | kebab.IConfigAi, opt: IOptions);
|
|
66
66
|
/** --- 获取当前服务商 --- */
|
|
67
67
|
get service(): ESERVICE;
|
|
68
|
+
/** --- 获取阿里云 DashScope 对应区域的域名 --- */
|
|
69
|
+
private _getDashScopeOrigin;
|
|
68
70
|
/** --- 创建非流式对话 --- */
|
|
69
71
|
chat(body: openai.default.Chat.Completions.ChatCompletionCreateParamsNonStreaming): Promise<openai.APIPromise<openai.default.Chat.ChatCompletion> | false>;
|
|
70
72
|
/** --- 创建流式对话 --- */
|
|
@@ -88,6 +90,7 @@ export declare class Ai {
|
|
|
88
90
|
'negative'?: string;
|
|
89
91
|
/** --- 长 x 宽,不同模型要求不同,如 [1664, 928] --- */
|
|
90
92
|
'size': number[];
|
|
93
|
+
/** --- 生成图片的数量,默认为 1 --- */
|
|
91
94
|
'n'?: number;
|
|
92
95
|
/** --- 随机种子,默认为随机 --- */
|
|
93
96
|
'seed'?: number;
|
|
@@ -110,6 +113,7 @@ export declare class Ai {
|
|
|
110
113
|
'prompt': string;
|
|
111
114
|
/** --- 文本(默认)、首尾帧、参考图 --- */
|
|
112
115
|
'mode'?: 'text' | 'frame' | 'ref';
|
|
116
|
+
/** --- 参考图,1 张为首帧,2 张为首尾帧 --- */
|
|
113
117
|
'imgs'?: string[];
|
|
114
118
|
/** --- 负面提示词,用于引导模型避免生成某些内容 --- */
|
|
115
119
|
'negative'?: string;
|
package/lib/ai.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Date: 2025-10-27 21:31:06
|
|
4
4
|
* Last: 2025-10-27 21:31:08
|
|
5
5
|
*/
|
|
6
|
+
// --- 第三方 ---
|
|
6
7
|
import * as openai from 'openai';
|
|
7
8
|
import * as lCore from '#kebab/lib/core.js';
|
|
8
9
|
import * as lText from '#kebab/lib/text.js';
|
|
@@ -148,6 +149,16 @@ export class Ai {
|
|
|
148
149
|
get service() {
|
|
149
150
|
return this._service;
|
|
150
151
|
}
|
|
152
|
+
/** --- 获取阿里云 DashScope 对应区域的域名 --- */
|
|
153
|
+
_getDashScopeOrigin() {
|
|
154
|
+
if (this._service === ESERVICE.ALIAS) {
|
|
155
|
+
return 'https://dashscope-intl.aliyuncs.com';
|
|
156
|
+
}
|
|
157
|
+
if (this._service === ESERVICE.ALINE) {
|
|
158
|
+
return 'https://dashscope-us.aliyuncs.com';
|
|
159
|
+
}
|
|
160
|
+
return 'https://dashscope.aliyuncs.com';
|
|
161
|
+
}
|
|
151
162
|
/** --- 创建对话 --- */
|
|
152
163
|
async chat(body) {
|
|
153
164
|
try {
|
|
@@ -198,8 +209,9 @@ export class Ai {
|
|
|
198
209
|
case ESERVICE.ALICN:
|
|
199
210
|
case ESERVICE.ALIAS:
|
|
200
211
|
case ESERVICE.ALINE: {
|
|
212
|
+
// --- 阿里云 DashScope 图像生成 ---
|
|
201
213
|
try {
|
|
202
|
-
const res = await this._fetch(
|
|
214
|
+
const res = await this._fetch(`${this._getDashScopeOrigin()}/api/v1/services/aigc/multimodal-generation/generation`, {
|
|
203
215
|
'method': 'POST',
|
|
204
216
|
'headers': {
|
|
205
217
|
'authorization': `Bearer ${this.link.apiKey}`,
|
|
@@ -430,8 +442,23 @@ export class Ai {
|
|
|
430
442
|
}
|
|
431
443
|
}
|
|
432
444
|
}
|
|
445
|
+
// --- 按模式组装参考图/首尾帧参数 ---
|
|
446
|
+
const frameParams = {};
|
|
447
|
+
if (mode === 'frame') {
|
|
448
|
+
if (imgs.length > 1) {
|
|
449
|
+
frameParams['first_frame_url'] = imgs[0];
|
|
450
|
+
frameParams['last_frame_url'] = imgs[1];
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
frameParams['img_url'] = imgs[0];
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
else if (mode !== 'text') {
|
|
457
|
+
frameParams['reference_urls'] = imgs;
|
|
458
|
+
}
|
|
459
|
+
// --- 提交异步视频生成任务 ---
|
|
433
460
|
try {
|
|
434
|
-
const res = await this._fetch(
|
|
461
|
+
const res = await this._fetch(`${this._getDashScopeOrigin()}/api/v1/services/aigc/video-generation/video-synthesis`, {
|
|
435
462
|
'method': 'POST',
|
|
436
463
|
'headers': {
|
|
437
464
|
'authorization': `Bearer ${this.link.apiKey}`,
|
|
@@ -442,9 +469,7 @@ export class Ai {
|
|
|
442
469
|
'model': opt.model,
|
|
443
470
|
'input': {
|
|
444
471
|
'prompt': opt.prompt.replace(/\[I(\d+)\]/g, 'Character$1'),
|
|
445
|
-
...(typeof audio === 'string' ? {
|
|
446
|
-
'audio_url': audio,
|
|
447
|
-
} : {})
|
|
472
|
+
...(typeof audio === 'string' ? { 'audio_url': audio } : {}),
|
|
448
473
|
},
|
|
449
474
|
'parameters': {
|
|
450
475
|
'negative_prompt': opt.negative ?? ' ',
|
|
@@ -455,16 +480,7 @@ export class Ai {
|
|
|
455
480
|
'duration': duration,
|
|
456
481
|
'shot_type': shot,
|
|
457
482
|
'prompt_extend': extend,
|
|
458
|
-
...
|
|
459
|
-
// --- 首尾帧 ---
|
|
460
|
-
'first_frame_url': imgs[0],
|
|
461
|
-
'last_frame_url': imgs[1],
|
|
462
|
-
} : {
|
|
463
|
-
// --- 首帧 ---
|
|
464
|
-
'img_url': imgs[0],
|
|
465
|
-
}) : {
|
|
466
|
-
'reference_urls': imgs,
|
|
467
|
-
})),
|
|
483
|
+
...frameParams,
|
|
468
484
|
},
|
|
469
485
|
}),
|
|
470
486
|
});
|
|
@@ -497,7 +513,7 @@ export class Ai {
|
|
|
497
513
|
return false;
|
|
498
514
|
}
|
|
499
515
|
try {
|
|
500
|
-
const res = await this._fetch(
|
|
516
|
+
const res = await this._fetch(`${this._getDashScopeOrigin()}/api/v1/tasks/${opt.task}`, {
|
|
501
517
|
'method': 'GET',
|
|
502
518
|
'headers': {
|
|
503
519
|
'authorization': `Bearer ${this.link.apiKey}`,
|
package/lib/cookie.d.ts
CHANGED
package/lib/cookie.js
CHANGED
|
@@ -11,7 +11,7 @@ import * as lTime from '#kebab/lib/time.js';
|
|
|
11
11
|
export function setCookie(cookie, name, value, domain, opt = {}) {
|
|
12
12
|
const tim = lTime.stamp();
|
|
13
13
|
const ttl = opt.ttl ?? 0;
|
|
14
|
-
domain = lText.parseHost(domain).hostname;
|
|
14
|
+
domain = lText.parseHost(domain).hostname.toLowerCase();
|
|
15
15
|
const domainN = domain.startsWith('.') ? domain.slice(1) : domain;
|
|
16
16
|
let exp = -1992199400;
|
|
17
17
|
if (ttl) {
|
|
@@ -24,7 +24,8 @@ export function setCookie(cookie, name, value, domain, opt = {}) {
|
|
|
24
24
|
'path': opt['path'] ?? '/',
|
|
25
25
|
'domain': domainN,
|
|
26
26
|
'secure': opt['ssl'] ? true : false,
|
|
27
|
-
'httponly': opt['httponly'] ? true : false
|
|
27
|
+
'httponly': opt['httponly'] ? true : false,
|
|
28
|
+
'hostOnly': !domain.startsWith('.'),
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
@@ -68,10 +69,15 @@ export async function buildCookieObject(cookie, setCookies, uri) {
|
|
|
68
69
|
cookieTmp[key.toLowerCase()] = val;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
72
|
+
if (!cookieTmp['name']) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
71
75
|
// --- 获取定义的 domain ---
|
|
76
|
+
const reqHost = (uri.hostname ?? '').toLowerCase();
|
|
72
77
|
let domain = '', domainN = '';
|
|
78
|
+
let hostOnly = false;
|
|
73
79
|
if (cookieTmp['domain']) {
|
|
74
|
-
cookieTmp['domain'] = lText.parseHost(cookieTmp['domain']).hostname;
|
|
80
|
+
cookieTmp['domain'] = lText.parseHost(cookieTmp['domain']).hostname.toLowerCase();
|
|
75
81
|
if (!(cookieTmp['domain'].startsWith('.'))) {
|
|
76
82
|
domain = '.' + cookieTmp['domain'];
|
|
77
83
|
domainN = cookieTmp['domain'];
|
|
@@ -82,8 +88,9 @@ export async function buildCookieObject(cookie, setCookies, uri) {
|
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
else {
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
hostOnly = true;
|
|
92
|
+
domain = '.' + reqHost;
|
|
93
|
+
domainN = reqHost;
|
|
87
94
|
}
|
|
88
95
|
// --- 判断有没有设置 domain 的权限 ---
|
|
89
96
|
// --- uri.hostname vs domain(domainN) ---
|
|
@@ -91,18 +98,18 @@ export async function buildCookieObject(cookie, setCookies, uri) {
|
|
|
91
98
|
// --- ok.xxx.com vs .xxx.com: true ---
|
|
92
99
|
// --- z.ok.xxx.com vs .xxx.com: true ---
|
|
93
100
|
// --- ok.xxx.com vs .zz.ok.xxx.com: false ---
|
|
94
|
-
if (
|
|
101
|
+
if (reqHost !== domainN) {
|
|
95
102
|
// --- 设置的域名和当前 host 不相等,如果是 IP、无 . 域名,则直接失败 ---
|
|
96
|
-
if (!lText.isDomain(
|
|
103
|
+
if (!lText.isDomain(reqHost)) {
|
|
97
104
|
continue;
|
|
98
105
|
}
|
|
99
106
|
const parseDomain = await lText.parseDomain(domainN);
|
|
100
|
-
if (parseDomain.tld === domainN
|
|
107
|
+
if (parseDomain.tld === domainN) {
|
|
101
108
|
// --- 不能给 tld 设置 cookie ---
|
|
102
109
|
continue;
|
|
103
110
|
}
|
|
104
111
|
// --- 判断访问路径 (uri['host']) 是不是设置域名 (domain) 的孩子,domain 必须是 uriHost 的同级或者父辈 ---
|
|
105
|
-
if (!(
|
|
112
|
+
if (!(reqHost.endsWith(domain))) {
|
|
106
113
|
// --- false 代表进入了,代表失败 ---
|
|
107
114
|
// --- ok.xxx.com, .xxx.com: true ---
|
|
108
115
|
// --- ok.xxx.com, .ppp.com: false ---
|
|
@@ -112,15 +119,13 @@ export async function buildCookieObject(cookie, setCookies, uri) {
|
|
|
112
119
|
}
|
|
113
120
|
const cookieKey = cookieTmp['name'] + '-' + domainN;
|
|
114
121
|
let exp = -1992199400;
|
|
115
|
-
if (cookieTmp['max-age'] !== undefined) {
|
|
122
|
+
if (cookieTmp['max-age'] !== undefined && /^-?\d+$/.test(cookieTmp['max-age'])) {
|
|
116
123
|
const maxAge = Number(cookieTmp['max-age']);
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
exp = tim + maxAge;
|
|
124
|
+
if (maxAge <= 0) {
|
|
125
|
+
delete cookie[cookieKey];
|
|
126
|
+
continue;
|
|
123
127
|
}
|
|
128
|
+
exp = tim + maxAge;
|
|
124
129
|
}
|
|
125
130
|
if ((exp === -1992199400) && cookieTmp['expires']) {
|
|
126
131
|
const expires = lTime.stamp(cookieTmp['expires']);
|
|
@@ -134,21 +139,19 @@ export async function buildCookieObject(cookie, setCookies, uri) {
|
|
|
134
139
|
}
|
|
135
140
|
// --- path ---
|
|
136
141
|
let path = cookieTmp['path'] ?? '';
|
|
137
|
-
if (path === '') {
|
|
138
|
-
const srp = (uri.pathname ?? '').lastIndexOf('/');
|
|
139
|
-
path = (uri.pathname ?? '').slice(0, srp + 1);
|
|
140
|
-
}
|
|
141
|
-
else if (!path.startsWith('/')) {
|
|
142
|
-
path = '/' + path;
|
|
142
|
+
if (path === '' || !path.startsWith('/')) {
|
|
143
|
+
const srp = (uri.pathname ?? '/').lastIndexOf('/');
|
|
144
|
+
path = (uri.pathname ?? '/').slice(0, srp + 1) || '/';
|
|
143
145
|
}
|
|
144
146
|
cookie[cookieKey] = {
|
|
145
147
|
'name': cookieTmp['name'],
|
|
146
|
-
'value': cookieTmp['value'],
|
|
148
|
+
'value': cookieTmp['value'] ?? '',
|
|
147
149
|
'exp': exp,
|
|
148
150
|
'path': path,
|
|
149
151
|
'domain': domainN,
|
|
150
152
|
'secure': cookieTmp['secure'] !== undefined,
|
|
151
|
-
'httponly': cookieTmp['httponly'] !== undefined
|
|
153
|
+
'httponly': cookieTmp['httponly'] !== undefined,
|
|
154
|
+
'hostOnly': hostOnly,
|
|
152
155
|
};
|
|
153
156
|
}
|
|
154
157
|
}
|
|
@@ -159,6 +162,9 @@ export async function buildCookieObject(cookie, setCookies, uri) {
|
|
|
159
162
|
*/
|
|
160
163
|
export function buildCookieQuery(cookie, uri) {
|
|
161
164
|
const tim = lTime.stamp();
|
|
165
|
+
const reqHost = (uri.hostname ?? '').toLowerCase();
|
|
166
|
+
const reqPath = uri.pathname ?? uri.path ?? '/';
|
|
167
|
+
const isSecure = uri.protocol === 'https:' || uri.protocol === 'wss:';
|
|
162
168
|
let cookieStr = '';
|
|
163
169
|
for (const key in cookie) {
|
|
164
170
|
const item = cookie[key];
|
|
@@ -166,30 +172,26 @@ export function buildCookieQuery(cookie, uri) {
|
|
|
166
172
|
delete cookie[key];
|
|
167
173
|
continue;
|
|
168
174
|
}
|
|
169
|
-
|
|
170
|
-
if (item.secure && (uri.protocol !== 'https:')) {
|
|
175
|
+
if (item.secure && !isSecure) {
|
|
171
176
|
continue;
|
|
172
177
|
}
|
|
173
|
-
// ---
|
|
174
|
-
|
|
178
|
+
// --- 按 RFC 6265 路径段边界判断 path 是否匹配(/app 不匹配 /app-evil) ---
|
|
179
|
+
const cPath = item.path || '/';
|
|
180
|
+
const pathMatch = reqPath === cPath ||
|
|
181
|
+
(cPath.endsWith('/') ? reqPath.startsWith(cPath) : reqPath.startsWith(cPath + '/'));
|
|
182
|
+
if (!pathMatch) {
|
|
175
183
|
continue;
|
|
176
184
|
}
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (
|
|
185
|
-
// ---
|
|
186
|
-
if (!
|
|
187
|
-
// --- false 代表进入,被排除了,因为 cookie 的 domain 和当前 host 后半部分,代表不是 domain 的孩子 ---
|
|
188
|
-
// --- ok.xxx.com, .zz.ok.xxx.com: false ---
|
|
189
|
-
// --- pp.ok.xxx.com, .zz.ok.xxx.com: false ---
|
|
190
|
-
// --- q.b.ok.xx.com, .zz.ok.xxx.com: false ---
|
|
191
|
-
// --- z.ok.xxx.com, .xxx.com: true ---
|
|
192
|
-
// --- xx.xxx.com, .ok.xxx.com: false ---
|
|
185
|
+
const itemDomain = item.domain.toLowerCase();
|
|
186
|
+
if (item.hostOnly) {
|
|
187
|
+
// --- 未指定 Domain 属性的 host-only Cookie 仅限精确匹配主机 ---
|
|
188
|
+
if (reqHost !== itemDomain) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else if (reqHost !== itemDomain) {
|
|
193
|
+
// --- 域名不相等时,判断当前 host 是不是 cookie domain 的子域 ---
|
|
194
|
+
if (!reqHost.endsWith('.' + itemDomain)) {
|
|
193
195
|
continue;
|
|
194
196
|
}
|
|
195
197
|
}
|
|
@@ -209,7 +211,7 @@ export function buildCookieQuery(cookie, uri) {
|
|
|
209
211
|
export function resetCookieSession(cookie) {
|
|
210
212
|
for (const key in cookie) {
|
|
211
213
|
const item = cookie[key];
|
|
212
|
-
if (item.exp === -
|
|
214
|
+
if (item.exp === -1992199400) {
|
|
213
215
|
delete cookie[key];
|
|
214
216
|
}
|
|
215
217
|
}
|
package/lib/core.d.ts
CHANGED
|
@@ -24,11 +24,17 @@ export declare const globalConfig: kebab.IConfig & {
|
|
|
24
24
|
};
|
|
25
25
|
/** --- Cookie 设置的选项 --- */
|
|
26
26
|
export interface ICookieOptions {
|
|
27
|
+
/** --- 有效期秒数,不设或 undefined 表示关闭浏览器失效 --- */
|
|
27
28
|
'ttl'?: number;
|
|
29
|
+
/** --- 生效路径,默认 / --- */
|
|
28
30
|
'path'?: string;
|
|
31
|
+
/** --- 生效域名 --- */
|
|
29
32
|
'domain'?: string;
|
|
33
|
+
/** --- 是否仅 HTTPS 发送 --- */
|
|
30
34
|
'ssl'?: boolean;
|
|
35
|
+
/** --- 是否禁止前端脚本读取 --- */
|
|
31
36
|
'httponly'?: boolean;
|
|
37
|
+
/** --- 跨站发送策略 --- */
|
|
32
38
|
'samesite'?: 'None' | 'Lax' | 'Strict';
|
|
33
39
|
}
|
|
34
40
|
/**
|
|
@@ -302,11 +308,17 @@ export declare function sendVhost(files: Record<string, string>, hosts?: string[
|
|
|
302
308
|
}>>;
|
|
303
309
|
/** --- log 设置的选项 --- */
|
|
304
310
|
export interface ILogOptions {
|
|
311
|
+
/** --- 当前请求路径 --- */
|
|
305
312
|
'path'?: string;
|
|
313
|
+
/** --- 站点完整基础 URL --- */
|
|
306
314
|
'urlFull'?: string;
|
|
315
|
+
/** --- 主机名,用于日志分目录,默认 system --- */
|
|
307
316
|
'hostname'?: string;
|
|
317
|
+
/** --- 原始 HTTP 请求对象 --- */
|
|
308
318
|
'req'?: http2.Http2ServerRequest | http.IncomingMessage | null;
|
|
319
|
+
/** --- GET 查询参数 --- */
|
|
309
320
|
'get'?: Record<string, any>;
|
|
321
|
+
/** --- 请求头 --- */
|
|
310
322
|
'headers'?: http.IncomingHttpHeaders;
|
|
311
323
|
}
|
|
312
324
|
/**
|
|
@@ -342,27 +354,41 @@ export declare function getLog(opt: {
|
|
|
342
354
|
} | false>;
|
|
343
355
|
/** --- 已保存监控事件的简短摘要,path 相对于 log/monitor/ --- */
|
|
344
356
|
export interface IMonitorEventSummary {
|
|
357
|
+
/** --- 事件目录相对路径 --- */
|
|
345
358
|
'path': string;
|
|
359
|
+
/** --- 触发事件的进程 PID --- */
|
|
346
360
|
'pid': number;
|
|
361
|
+
/** --- 事件确认时间戳,单位 ms --- */
|
|
347
362
|
'time': number;
|
|
363
|
+
/** --- 事件来源:主线程监控或看门狗线程 --- */
|
|
348
364
|
'source': 'main' | 'watchdog';
|
|
365
|
+
/** --- 事件当前状态或结束原因 --- */
|
|
349
366
|
'status': string;
|
|
367
|
+
/** --- 触发告警的指标原因列表 --- */
|
|
350
368
|
'reasons': string[];
|
|
351
369
|
}
|
|
352
370
|
/** --- 监控文件元数据;复杂格式或超过 1 MiB 的文件不提供预览 --- */
|
|
353
371
|
export interface IMonitorFile {
|
|
372
|
+
/** --- 文件相对路径 --- */
|
|
354
373
|
'path': string;
|
|
374
|
+
/** --- 文件名 --- */
|
|
355
375
|
'name': string;
|
|
376
|
+
/** --- 文件字节数 --- */
|
|
356
377
|
'size': number;
|
|
357
378
|
/** --- 最后修改时间,单位 ms --- */
|
|
358
379
|
'mtime': number;
|
|
380
|
+
/** --- 支持的在线预览格式,不可预览时为 null --- */
|
|
359
381
|
'preview': 'json' | 'text' | null;
|
|
360
382
|
}
|
|
361
383
|
/** --- 事件原始数据与可读取的文件;data 为 null 时可下载原始记录复盘 --- */
|
|
362
384
|
export interface IMonitorEvent {
|
|
385
|
+
/** --- 事件摘要 --- */
|
|
363
386
|
'summary': IMonitorEventSummary;
|
|
387
|
+
/** --- 事件记录 JSON 数据,未成功加载时为 null --- */
|
|
364
388
|
'data': Record<string, unknown> | null;
|
|
389
|
+
/** --- 事件记录文件的读取状态 --- */
|
|
365
390
|
'recordStatus': 'loaded' | 'missing' | 'too-large' | 'invalid' | 'unreadable';
|
|
391
|
+
/** --- 关联的可下载诊断文件清单 --- */
|
|
366
392
|
'files': IMonitorFile[];
|
|
367
393
|
}
|
|
368
394
|
/**
|
package/lib/core.js
CHANGED
|
@@ -3,15 +3,19 @@
|
|
|
3
3
|
* Date: 2019-5-3 23:54
|
|
4
4
|
* Last: 2020-4-11 22:34:58, 2022-10-2 14:13:06, 2022-12-28 20:33:24, 2023-12-15 11:49:02, 2024-7-2 15:23:35, 2025-6-13 19:45:53, 2026-05-20 09:50:00, 2026-8-22
|
|
5
5
|
*/
|
|
6
|
+
// --- 系统 ---
|
|
6
7
|
import * as cp from 'child_process';
|
|
7
8
|
import * as http2 from 'http2';
|
|
8
9
|
import * as stream from 'stream';
|
|
9
10
|
import * as os from 'os';
|
|
10
11
|
import * as net from 'net';
|
|
11
12
|
import * as crypto from 'crypto';
|
|
13
|
+
import * as nodeFs from 'node:fs';
|
|
14
|
+
// --- 第三方 ---
|
|
12
15
|
import Ajv from 'ajv';
|
|
13
16
|
import addFormats from 'ajv-formats';
|
|
14
17
|
import * as valibot from 'valibot';
|
|
18
|
+
// --- 库和定义 ---
|
|
15
19
|
import * as kebab from '#kebab/index.js';
|
|
16
20
|
import * as lTime from '#kebab/lib/time.js';
|
|
17
21
|
import * as lFs from '#kebab/lib/fs.js';
|
|
@@ -22,7 +26,6 @@ import * as lNetResponse from '#kebab/lib/net/response.js';
|
|
|
22
26
|
import * as lUndiciResponse from '#kebab/lib/undici/response.js';
|
|
23
27
|
import * as sCtr from '#kebab/sys/ctr.js';
|
|
24
28
|
import * as rpc from '#kebab/lib/core/rpc.js';
|
|
25
|
-
import * as nodeFs from 'node:fs';
|
|
26
29
|
/** --- Valibot 数据校验工具,业务侧可通过 lCore.v 使用 --- */
|
|
27
30
|
export { valibot as v };
|
|
28
31
|
/** --- 全局参数 --- */
|
|
@@ -45,19 +48,26 @@ export function setCookie(ctr, name, value, opt = {}) {
|
|
|
45
48
|
if (!res) {
|
|
46
49
|
return;
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
if (!name || /[;\r\n\u0000-\u001f\u007f=]/.test(name)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const cleanPath = opt.path ?? '/';
|
|
55
|
+
if (/[;\r\n\u0000-\u001f\u007f]/.test(cleanPath)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (opt.domain && /[;\r\n\u0000-\u001f\u007f]/.test(opt.domain)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const maxAge = (opt.ttl !== undefined && Number.isFinite(opt.ttl)) ? `; Max-Age=${Math.trunc(opt.ttl)}` : '';
|
|
62
|
+
const path = `; path=${cleanPath}`;
|
|
55
63
|
const domain = opt.domain ? `; domain=${opt.domain}` : '';
|
|
56
64
|
const secure = opt.ssl ? '; secure' : '';
|
|
57
65
|
const httpOnly = opt.httponly ? '; HttpOnly' : '';
|
|
58
66
|
const sameSite = opt.samesite ? '; SameSite=' + opt.samesite : '';
|
|
59
|
-
const
|
|
60
|
-
|
|
67
|
+
const existing = res.getHeader('set-cookie');
|
|
68
|
+
const cookies = Array.isArray(existing)
|
|
69
|
+
? existing.map(String)
|
|
70
|
+
: (existing !== undefined ? [String(existing)] : []);
|
|
61
71
|
cookies.push(`${name}=${encodeURIComponent(value)}${maxAge}${path}${domain}${secure}${httpOnly}${sameSite}`);
|
|
62
72
|
res.setHeader('set-cookie', cookies);
|
|
63
73
|
}
|
|
@@ -120,6 +130,7 @@ export function random(length = 8, source = RANDOM_LN, block = '') {
|
|
|
120
130
|
}
|
|
121
131
|
return temp;
|
|
122
132
|
}
|
|
133
|
+
/** --- 62 进制编码字符表 --- */
|
|
123
134
|
const CONVERT62_CHAR = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
124
135
|
/**
|
|
125
136
|
* --- 将 10 进制转换为 62 进制 ---
|
|
@@ -887,7 +898,12 @@ export async function updateCode(sourcePath, path, hosts, config = true, strict
|
|
|
887
898
|
}
|
|
888
899
|
/** --- 各主机使用独立上传流并行部署,结果保持输入顺序 --- */
|
|
889
900
|
const results = await Promise.all(hosts.map(async (host) => {
|
|
890
|
-
const command = rpc.sign({
|
|
901
|
+
const command = rpc.sign({
|
|
902
|
+
'action': 'code',
|
|
903
|
+
'path': path,
|
|
904
|
+
'config': config,
|
|
905
|
+
'strict': strict ? '1' : '0',
|
|
906
|
+
}, globalConfig.rpcSecret, 'POST', bodyHash);
|
|
891
907
|
const res = await lUndici.post(`http://${host}:${globalConfig.rpcPort}/${command}`, nodeFs.createReadStream(sourcePath), {
|
|
892
908
|
'timeout': 180,
|
|
893
909
|
});
|
|
@@ -1014,6 +1030,7 @@ export async function sendVhost(files, hosts) {
|
|
|
1014
1030
|
*/
|
|
1015
1031
|
export function log(opt, msg, fend = '') {
|
|
1016
1032
|
(async () => {
|
|
1033
|
+
// --- 解析请求上下文 ---
|
|
1017
1034
|
let req;
|
|
1018
1035
|
let headers;
|
|
1019
1036
|
let get;
|
|
@@ -1041,6 +1058,7 @@ export function log(opt, msg, fend = '') {
|
|
|
1041
1058
|
hostname = 'system';
|
|
1042
1059
|
}
|
|
1043
1060
|
hostname = hostname.replace(/:/g, '_');
|
|
1061
|
+
// --- 提取客户端 IP 与构建日志目录 ---
|
|
1044
1062
|
const realIp = req?.socket.remoteAddress ?? '';
|
|
1045
1063
|
const ipss = req ? ips(headers) : {
|
|
1046
1064
|
'cf': '',
|
|
@@ -1054,6 +1072,7 @@ export function log(opt, msg, fend = '') {
|
|
|
1054
1072
|
if (!rtn) {
|
|
1055
1073
|
return;
|
|
1056
1074
|
}
|
|
1075
|
+
// --- 按配置的日志格式追加写入 ---
|
|
1057
1076
|
const format = globalConfig.logFormat ?? 'jsonl';
|
|
1058
1077
|
if (format === 'jsonl') {
|
|
1059
1078
|
// --- JSON Lines 格式 ---
|
|
@@ -1147,8 +1166,12 @@ async function requestMonitor(action, opt) {
|
|
|
1147
1166
|
return false;
|
|
1148
1167
|
}
|
|
1149
1168
|
const command = rpc.sign({
|
|
1150
|
-
action
|
|
1151
|
-
'
|
|
1169
|
+
'action': action,
|
|
1170
|
+
'time': lTime.stamp(),
|
|
1171
|
+
'path': opt.path,
|
|
1172
|
+
'offset': opt.offset,
|
|
1173
|
+
'limit': opt.limit,
|
|
1174
|
+
'preview': opt.preview,
|
|
1152
1175
|
}, globalConfig.rpcSecret);
|
|
1153
1176
|
const res = await lUndici.get(`http://${opt.host ?? '127.0.0.1'}:${globalConfig.rpcPort}/${command}`, {
|
|
1154
1177
|
'timeout': action === 'monitor-file' ? 300 : 5,
|
package/lib/cron.js
CHANGED
|
@@ -123,12 +123,5 @@ async function saveCronData(obj) {
|
|
|
123
123
|
* --- 获取 Kv 实例(内部使用,用于分布式锁) ---
|
|
124
124
|
*/
|
|
125
125
|
function get() {
|
|
126
|
-
return lKv.get({
|
|
127
|
-
'host': lCore.globalConfig.kv.host,
|
|
128
|
-
'port': lCore.globalConfig.kv.port,
|
|
129
|
-
'index': lCore.globalConfig.kv.index,
|
|
130
|
-
'pre': lCore.globalConfig.kv.pre,
|
|
131
|
-
'user': lCore.globalConfig.kv.user,
|
|
132
|
-
'pwd': lCore.globalConfig.kv.pwd,
|
|
133
|
-
});
|
|
126
|
+
return lKv.get({ ...lCore.globalConfig.kv });
|
|
134
127
|
}
|
package/lib/crypto.js
CHANGED
|
@@ -113,8 +113,15 @@ export const SM4_CFB = 'sm4-cfb';
|
|
|
113
113
|
*/
|
|
114
114
|
export function cipherEncrypt(original, key, iv = '', method = AES_256_ECB, output = 'base64') {
|
|
115
115
|
try {
|
|
116
|
-
if (
|
|
117
|
-
|
|
116
|
+
if (typeof key === 'string') {
|
|
117
|
+
if (method.startsWith('sm4-')) {
|
|
118
|
+
if (Buffer.byteLength(key) !== 16) {
|
|
119
|
+
key = hashHmac('md5', key, 'MaiyunSalt', 'buffer');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else if (key.length !== 32) {
|
|
123
|
+
key = hashHmac('md5', key, 'MaiyunSalt');
|
|
124
|
+
}
|
|
118
125
|
}
|
|
119
126
|
if (iv) {
|
|
120
127
|
if (method === AES_256_CTR) {
|
|
@@ -195,8 +202,15 @@ export function sm4Encrypt(original, key, iv = '', method = SM4_ECB, output = 'b
|
|
|
195
202
|
*/
|
|
196
203
|
export function cipherDecrypt(encrypt, key, iv = '', method = AES_256_ECB, output = 'binary') {
|
|
197
204
|
try {
|
|
198
|
-
if (
|
|
199
|
-
|
|
205
|
+
if (typeof key === 'string') {
|
|
206
|
+
if (method.startsWith('sm4-')) {
|
|
207
|
+
if (Buffer.byteLength(key) !== 16) {
|
|
208
|
+
key = hashHmac('md5', key, 'MaiyunSalt', 'buffer');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else if (key.length !== 32) {
|
|
212
|
+
key = hashHmac('md5', key, 'MaiyunSalt');
|
|
213
|
+
}
|
|
200
214
|
}
|
|
201
215
|
if (iv) {
|
|
202
216
|
if (method === AES_256_CTR) {
|
|
@@ -267,7 +281,7 @@ export function sm4Decrypt(encrypt, key, iv = '', method = SM4_ECB, output = 'bi
|
|
|
267
281
|
return cipherDecrypt(encrypt, key, iv, method, output);
|
|
268
282
|
}
|
|
269
283
|
export function hashHmac(algorithm, data, key, format = 'hex') {
|
|
270
|
-
const cry = key ? crypto.createHmac(algorithm, key) : crypto.createHash(algorithm);
|
|
284
|
+
const cry = key !== undefined ? crypto.createHmac(algorithm, key) : crypto.createHash(algorithm);
|
|
271
285
|
cry.update(data);
|
|
272
286
|
if (format === 'buffer') {
|
|
273
287
|
return cry.digest();
|
|
@@ -278,7 +292,7 @@ export function hashHmac(algorithm, data, key, format = 'hex') {
|
|
|
278
292
|
}
|
|
279
293
|
export function hashHmacFile(algorithm, path, key, encoding = 'hex') {
|
|
280
294
|
return new Promise(function (resolve) {
|
|
281
|
-
const cry = key ? crypto.createHmac(algorithm, key) : crypto.createHash(algorithm);
|
|
295
|
+
const cry = key !== undefined ? crypto.createHmac(algorithm, key) : crypto.createHash(algorithm);
|
|
282
296
|
const rs = lFs.createReadStream(path);
|
|
283
297
|
rs.on('data', (chunk) => {
|
|
284
298
|
cry.update(chunk);
|
package/lib/db/conn.d.ts
CHANGED
|
@@ -76,17 +76,19 @@ export declare class Connection {
|
|
|
76
76
|
* --- 执行一条 SQL 并获得返回数据 ---
|
|
77
77
|
* @param sql 执行的 SQL 字符串
|
|
78
78
|
* @param values SQL 占位符绑定的值
|
|
79
|
+
* @param opt 查询选项(单连接模式下忽略)
|
|
79
80
|
* @returns 查询结果,result = -500 表示查询失败
|
|
80
81
|
*/
|
|
81
|
-
query(sql: string, values?: kebab.DbValue[]): Promise<lDb.IData>;
|
|
82
|
+
query(sql: string, values?: kebab.DbValue[], opt?: lDb.IQueryOptions): Promise<lDb.IData>;
|
|
82
83
|
/**
|
|
83
84
|
* --- 执行一条 SQL,按指定类型返回数据行 ---
|
|
84
85
|
* @typeParam TRow SQL 返回的行结构,由调用方根据查询字段指定
|
|
85
86
|
* @param sql 执行的 SQL 字符串
|
|
86
87
|
* @param values SQL 占位符绑定的值
|
|
88
|
+
* @param opt 查询选项(单连接模式下忽略)
|
|
87
89
|
* @returns 查询结果,result = -500 表示查询失败
|
|
88
90
|
*/
|
|
89
|
-
query<TRow extends object>(sql: string, values?: kebab.DbValue[]): Promise<lDb.IData<TRow>>;
|
|
91
|
+
query<TRow extends object>(sql: string, values?: kebab.DbValue[], opt?: lDb.IQueryOptions): Promise<lDb.IData<TRow>>;
|
|
90
92
|
/**
|
|
91
93
|
* --- 执行一条 SQL 并获得影响行数对象 packet ---
|
|
92
94
|
* @param sql 执行的 SQL 字符串
|