@maiyunnet/kebab 3.1.1 → 3.1.3

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 CHANGED
@@ -8,7 +8,7 @@
8
8
  * ------------------------
9
9
  */
10
10
  /** --- 当前系统版本号 --- */
11
- export declare const VER = "3.1.1";
11
+ export declare const VER = "3.1.3";
12
12
  /** --- 框架根目录,以 / 结尾 --- */
13
13
  export declare const ROOT_PATH: string;
14
14
  export declare const LIB_PATH: string;
package/index.js CHANGED
@@ -8,7 +8,7 @@
8
8
  * ------------------------
9
9
  */
10
10
  /** --- 当前系统版本号 --- */
11
- export const VER = '3.1.1';
11
+ export const VER = '3.1.3';
12
12
  // --- 服务端用的路径 ---
13
13
  const imu = import.meta.url.replace('file://', '').replace(/^\/(\w:)/, '$1').replace(/\\/g, '/');
14
14
  /** --- /xxx/xxx --- */
package/lib/db.js CHANGED
@@ -171,7 +171,7 @@ export class Pool {
171
171
  link.on('error', function (err) {
172
172
  c.setLost();
173
173
  if (err.code !== 'PROTOCOL_CONNECTION_LOST') {
174
- lCore.debug('[DB][_getConnection]', err);
174
+ lCore.debug('[DB][_getConnection][error]', err);
175
175
  }
176
176
  }).on('end', () => {
177
177
  // lCore.debug('[DB][_getConnection] connection end.');
package/lib/lang.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /** --- 支持的语言缩写列表 --- */
2
+ export declare const codes: string[];
3
+ export declare const names: string[];
4
+ /** --- 浏览器常用映射为本语言 --- */
5
+ export declare const map: Record<string, string>;
6
+ /**
7
+ * --- 根据常用语言字符串获取语言 code ---
8
+ * @param accept 常用字符串,如 zh-cn,或包含 zh-cn 的字符串
9
+ */
10
+ export declare function getCodeByAccept(accept?: string): string;
package/lib/lang.js ADDED
@@ -0,0 +1,45 @@
1
+ /** --- 支持的语言缩写列表 --- */
2
+ export const codes = [
3
+ 'sc', 'tc', 'ja', 'ko', 'en', 'es', 'th', 'vi',
4
+ 'de', 'fr', 'pt', 'ru', 'ar', 'id', 'it', 'tr',
5
+ ];
6
+ export const names = [
7
+ '简体中文', '繁體中文', '日本語', '한국어', 'English', 'Español', 'ไทย', 'Tiếng việt',
8
+ 'Deutsch', 'Français', 'Português', 'Русский', 'العربية', 'Bahasa Indonesia', 'Italiano', 'Türkçe',
9
+ ];
10
+ /** --- 浏览器常用映射为本语言 --- */
11
+ export const map = {
12
+ 'cn': 'sc',
13
+ 'zh': 'tc',
14
+ 'ja': 'ja',
15
+ 'ko': 'ko',
16
+ 'en': 'en',
17
+ 'es': 'es',
18
+ 'th': 'th',
19
+ 'vi': 'vi',
20
+ 'de': 'de',
21
+ 'fr': 'fr',
22
+ 'pt': 'pt',
23
+ 'ru': 'ru',
24
+ 'ar': 'ar',
25
+ 'id': 'id',
26
+ 'it': 'it',
27
+ 'tr': 'tr',
28
+ };
29
+ /**
30
+ * --- 根据常用语言字符串获取语言 code ---
31
+ * @param accept 常用字符串,如 zh-cn,或包含 zh-cn 的字符串
32
+ */
33
+ export function getCodeByAccept(accept) {
34
+ if (accept === '*') {
35
+ return 'sc';
36
+ }
37
+ const ulang = accept?.toLowerCase() ?? 'en';
38
+ for (const l in map) {
39
+ if (!ulang.includes(l)) {
40
+ continue;
41
+ }
42
+ return map[l];
43
+ }
44
+ return 'en';
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -18,8 +18,8 @@
18
18
  "#*": "./*"
19
19
  },
20
20
  "dependencies": {
21
- "@aws-sdk/client-s3": "^3.891.0",
22
- "@aws-sdk/lib-storage": "^3.891.0",
21
+ "@aws-sdk/client-s3": "^3.893.0",
22
+ "@aws-sdk/lib-storage": "^3.893.0",
23
23
  "@litert/http-client": "^1.1.2",
24
24
  "@litert/mime": "^0.1.3",
25
25
  "@litert/redis": "^3.0.5",
@@ -30,7 +30,7 @@
30
30
  "mysql2": "^3.15.0",
31
31
  "ssh2": "^1.17.0",
32
32
  "svg-captcha": "^1.4.0",
33
- "tencentcloud-sdk-nodejs": "^4.1.118"
33
+ "tencentcloud-sdk-nodejs": "^4.1.119"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@litert/eslint-plugin-rules": "^0.3.1",
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
- // --- data.path 是安全的,不会是 ../../ 来访问到了外层,已经做过处理 ---
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
- let isDirect = false;
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
- const alang = data.req.headers['accept-language']?.toLowerCase() ?? config.lang.list[0];
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
- for (const lang of config.lang.list) {
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('');