@maiyunnet/kebab 8.5.4 → 8.6.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/doc/kebab-rag.md +15 -7
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/session.d.ts +1 -0
- package/lib/session.js +5 -2
- package/package.json +1 -1
- package/sys/ctr.d.ts +1 -1
- package/sys/ctr.js +1 -1
- package/www/example/ctr/test.d.ts +1 -0
- package/www/example/ctr/test.js +9 -0
package/doc/kebab-rag.md
CHANGED
|
@@ -1410,7 +1410,7 @@ index/variables/VER.md
|
|
|
1410
1410
|
|
|
1411
1411
|
# Variable: VER
|
|
1412
1412
|
|
|
1413
|
-
> `const` **VER**: `"8.
|
|
1413
|
+
> `const` **VER**: `"8.6.0"` = `'8.6.0'`
|
|
1414
1414
|
|
|
1415
1415
|
Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
|
|
1416
1416
|
|
|
@@ -12771,7 +12771,7 @@ lib/session/classes/Session.md
|
|
|
12771
12771
|
|
|
12772
12772
|
# Class: Session
|
|
12773
12773
|
|
|
12774
|
-
Defined in: [lib/session.ts:
|
|
12774
|
+
Defined in: [lib/session.ts:39](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L39)
|
|
12775
12775
|
|
|
12776
12776
|
## Constructors
|
|
12777
12777
|
|
|
@@ -12789,7 +12789,7 @@ Defined in: [lib/session.ts:38](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
12789
12789
|
|
|
12790
12790
|
> **getName**(): `string`
|
|
12791
12791
|
|
|
12792
|
-
Defined in: [lib/session.ts:
|
|
12792
|
+
Defined in: [lib/session.ts:207](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L207)
|
|
12793
12793
|
|
|
12794
12794
|
获取当前的 cookie 的 name 值
|
|
12795
12795
|
|
|
@@ -12803,7 +12803,7 @@ Defined in: [lib/session.ts:203](https://github.com/maiyunnet/kebab/blob/master/
|
|
|
12803
12803
|
|
|
12804
12804
|
> **getToken**(): `string`
|
|
12805
12805
|
|
|
12806
|
-
Defined in: [lib/session.ts:
|
|
12806
|
+
Defined in: [lib/session.ts:200](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L200)
|
|
12807
12807
|
|
|
12808
12808
|
获取当前的 token 值
|
|
12809
12809
|
|
|
@@ -12817,7 +12817,7 @@ Defined in: [lib/session.ts:196](https://github.com/maiyunnet/kebab/blob/master/
|
|
|
12817
12817
|
|
|
12818
12818
|
> **init**(`ctr`, `link`, `auth?`, `opt?`): `Promise`\<`boolean`\>
|
|
12819
12819
|
|
|
12820
|
-
Defined in: [lib/session.ts:
|
|
12820
|
+
Defined in: [lib/session.ts:67](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L67)
|
|
12821
12821
|
|
|
12822
12822
|
初始化函数,相当于 construct
|
|
12823
12823
|
|
|
@@ -12859,7 +12859,7 @@ false 表示系统错误
|
|
|
12859
12859
|
|
|
12860
12860
|
> **update**(): `Promise`\<`void`\>
|
|
12861
12861
|
|
|
12862
|
-
Defined in: [lib/session.ts:
|
|
12862
|
+
Defined in: [lib/session.ts:214](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L214)
|
|
12863
12863
|
|
|
12864
12864
|
页面整体结束时,要写入到 Kv 或 数据库
|
|
12865
12865
|
|
|
@@ -12933,6 +12933,14 @@ Defined in: [lib/session.ts:33](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
12933
12933
|
|
|
12934
12934
|
***
|
|
12935
12935
|
|
|
12936
|
+
### token?
|
|
12937
|
+
|
|
12938
|
+
> `optional` **token**: `string`
|
|
12939
|
+
|
|
12940
|
+
Defined in: [lib/session.ts:36](https://github.com/maiyunnet/kebab/blob/master/lib/session.ts#L36)
|
|
12941
|
+
|
|
12942
|
+
***
|
|
12943
|
+
|
|
12936
12944
|
### ttl?
|
|
12937
12945
|
|
|
12938
12946
|
> `optional` **ttl**: `number`
|
|
@@ -20423,7 +20431,7 @@ Kv 或 Db 实例
|
|
|
20423
20431
|
|
|
20424
20432
|
[`IOptions`](../../../lib/session/interfaces/IOptions.md) = `{}`
|
|
20425
20433
|
|
|
20426
|
-
|
|
20434
|
+
选项
|
|
20427
20435
|
|
|
20428
20436
|
#### Returns
|
|
20429
20437
|
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '8.
|
|
9
|
+
export const VER = '8.6.0';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/session.d.ts
CHANGED
package/lib/session.js
CHANGED
|
@@ -51,7 +51,10 @@ export class Session {
|
|
|
51
51
|
this._ttl = opt.ttl ?? config.session.ttl ?? 172800;
|
|
52
52
|
const tim = lTime.stamp();
|
|
53
53
|
this._ctr = ctr;
|
|
54
|
-
if (
|
|
54
|
+
if (opt.token) {
|
|
55
|
+
this._token = opt.token;
|
|
56
|
+
}
|
|
57
|
+
else if (auth) {
|
|
55
58
|
const a = ctr.getAuthorization();
|
|
56
59
|
if (a && typeof a !== 'string' && (a.user === 'token')) {
|
|
57
60
|
this._token = a.pwd;
|
|
@@ -125,7 +128,7 @@ export class Session {
|
|
|
125
128
|
}
|
|
126
129
|
this._token = lCore.random(16, lCore.RANDOM_LUN);
|
|
127
130
|
++count;
|
|
128
|
-
} while (!await this._link.set(this._name + '_' + this._token,
|
|
131
|
+
} while (!await this._link.set(this._name + '_' + this._token, {}, this._ttl, 'nx'));
|
|
129
132
|
}
|
|
130
133
|
else {
|
|
131
134
|
let count = 0;
|
package/package.json
CHANGED
package/sys/ctr.d.ts
CHANGED
|
@@ -213,7 +213,7 @@ export declare class Ctr {
|
|
|
213
213
|
* --- 开启 Session ---
|
|
214
214
|
* @param link Kv 或 Db 实例
|
|
215
215
|
* @param auth 设为 true 则从头 Authorization 或 post _auth 值读取 token
|
|
216
|
-
* @param opt
|
|
216
|
+
* @param opt 选项
|
|
217
217
|
*/
|
|
218
218
|
protected _startSession(link: lDb.Pool | lKv.Kv, auth?: boolean, opt?: lSession.IOptions): Promise<boolean>;
|
|
219
219
|
/**
|
package/sys/ctr.js
CHANGED
|
@@ -549,7 +549,7 @@ export class Ctr {
|
|
|
549
549
|
* --- 开启 Session ---
|
|
550
550
|
* @param link Kv 或 Db 实例
|
|
551
551
|
* @param auth 设为 true 则从头 Authorization 或 post _auth 值读取 token
|
|
552
|
-
* @param opt
|
|
552
|
+
* @param opt 选项
|
|
553
553
|
*/
|
|
554
554
|
_startSession(link, auth = false, opt = {}) {
|
|
555
555
|
this._sess = new lSession.Session();
|
|
@@ -28,6 +28,7 @@ export default class extends sCtr.Ctr {
|
|
|
28
28
|
ctrAsynctask(): any[];
|
|
29
29
|
ctrTimeoutLong(): Promise<any[]>;
|
|
30
30
|
ctrTimeoutShort(): Promise<any[]>;
|
|
31
|
+
ctrSessionToken(): Promise<kebab.Json[]>;
|
|
31
32
|
ctr500(): Promise<void>;
|
|
32
33
|
modTest(): Promise<kebab.Json[] | string | boolean>;
|
|
33
34
|
modSplit(): Promise<string>;
|
package/www/example/ctr/test.js
CHANGED
|
@@ -115,6 +115,7 @@ export default class extends sCtr.Ctr {
|
|
|
115
115
|
`<br><a href="${this._config.const.urlBase}test/ctr-asynctask">View "test/ctr-asynctask"</a>`,
|
|
116
116
|
`<br><a href="${this._config.const.urlBase}test/ctr-timeout-long">View "test/ctr-timeout-long"</a>`,
|
|
117
117
|
`<br><a href="${this._config.const.urlBase}test/ctr-timeout-short">View "test/ctr-timeout-short"</a>`,
|
|
118
|
+
`<br><a href="${this._config.const.urlBase}test/ctr-session-token">View "test/ctr-session-token"</a>`,
|
|
118
119
|
`<br><a href="${this._config.const.urlBase}test/ctr-500">View "test/ctr-500"</a>`,
|
|
119
120
|
'<br><br><b>Middle:</b>',
|
|
120
121
|
`<br><br><a href="${this._config.const.urlBase}test/middle">View "test/middle"</a>`,
|
|
@@ -611,6 +612,14 @@ Result:<pre id="result">Nothing.</pre>` + this._getEnd();
|
|
|
611
612
|
echo.push('5');
|
|
612
613
|
return [1, { 'list': echo }];
|
|
613
614
|
}
|
|
615
|
+
async ctrSessionToken() {
|
|
616
|
+
const link = lDb.get(this);
|
|
617
|
+
await this._startSession(link, false, {
|
|
618
|
+
'token': 'TEST_TOKEN_1234'
|
|
619
|
+
});
|
|
620
|
+
const currentToken = this._sess?.getToken();
|
|
621
|
+
return [1, { 'status': currentToken === 'TEST_TOKEN_1234' ? 'success' : 'failed', 'token': currentToken }];
|
|
622
|
+
}
|
|
614
623
|
async ctr500() {
|
|
615
624
|
await lCore.sleep(100);
|
|
616
625
|
lCore.writeHead(this._res, 200);
|