@maiyunnet/kebab 3.1.2 → 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.2";
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.2';
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "3.1.2",
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": [
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('');