mm_session 1.5.3 → 1.5.5
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/lib/session.js +0 -22
- package/lib/store.js +0 -2
- package/package.json +5 -5
package/lib/session.js
CHANGED
|
@@ -118,18 +118,9 @@ Session.prototype.get = async function (ctx) {
|
|
|
118
118
|
* @param {Function} next 下一个中间件
|
|
119
119
|
*/
|
|
120
120
|
Session.prototype._handle = async function (ctx, next) {
|
|
121
|
-
console.log(' - _handle方法开始执行');
|
|
122
121
|
let session_id = await this.get(ctx);
|
|
123
|
-
|
|
124
|
-
// 执行业务逻辑(包括登录/退出)
|
|
125
|
-
console.log(' - 执行next()之前');
|
|
126
122
|
await next();
|
|
127
|
-
console.log(' - 执行next()之后');
|
|
128
|
-
|
|
129
|
-
// 保存session(基于session是否被修改)
|
|
130
|
-
console.log(' - 准备调用save方法');
|
|
131
123
|
await this._save(ctx, session_id);
|
|
132
|
-
console.log(' - save方法执行完成');
|
|
133
124
|
};
|
|
134
125
|
|
|
135
126
|
/**
|
|
@@ -279,21 +270,16 @@ Session.prototype._extractSessionData = function (ctx) {
|
|
|
279
270
|
|
|
280
271
|
// 使用Reflect.ownKeys确保正确枚举Proxy对象的所有属性
|
|
281
272
|
const keys = Reflect.ownKeys(ctx.session);
|
|
282
|
-
console.log(' - 保存前session对象属性列表:', keys);
|
|
283
273
|
|
|
284
274
|
for (const key of keys) {
|
|
285
275
|
// 跳过Symbol类型的属性
|
|
286
276
|
if (typeof key === 'symbol') {
|
|
287
|
-
console.log(` - 跳过Symbol属性: ${key.toString()}`);
|
|
288
277
|
continue;
|
|
289
278
|
}
|
|
290
279
|
|
|
291
280
|
// 跳过函数属性和内部属性
|
|
292
281
|
if (typeof ctx.session[key] !== 'function' && !key.startsWith('_')) {
|
|
293
282
|
session_to_save[key] = ctx.session[key];
|
|
294
|
-
console.log(` - 保存属性到session_to_save: ${key} = ${ctx.session[key]}`);
|
|
295
|
-
} else {
|
|
296
|
-
console.log(` - 跳过属性: ${key} (类型: ${typeof ctx.session[key]})`);
|
|
297
283
|
}
|
|
298
284
|
}
|
|
299
285
|
|
|
@@ -329,8 +315,6 @@ Session.prototype._save = async function (ctx, session_id) {
|
|
|
329
315
|
await this._delSession(ctx, session_id);
|
|
330
316
|
return;
|
|
331
317
|
}
|
|
332
|
-
|
|
333
|
-
console.log(' - save方法: 检查session._modified标志:', ctx.session._modified);
|
|
334
318
|
|
|
335
319
|
// 如果session被修改过,需要保存
|
|
336
320
|
if (ctx.session._modified) {
|
|
@@ -339,8 +323,6 @@ Session.prototype._save = async function (ctx, session_id) {
|
|
|
339
323
|
// 提取session数据
|
|
340
324
|
const session_to_save = this._extractSessionData(ctx);
|
|
341
325
|
|
|
342
|
-
console.log(' - 保存前的session_to_save对象:', session_to_save);
|
|
343
|
-
|
|
344
326
|
// 保存内部属性(_is_new和_modified)
|
|
345
327
|
if (ctx.session._is_new !== undefined) {
|
|
346
328
|
session_to_save._is_new = ctx.session._is_new;
|
|
@@ -349,13 +331,9 @@ Session.prototype._save = async function (ctx, session_id) {
|
|
|
349
331
|
session_to_save._modified = ctx.session._modified;
|
|
350
332
|
}
|
|
351
333
|
|
|
352
|
-
console.log(' - 保存内部属性后的session_to_save对象:', session_to_save);
|
|
353
|
-
|
|
354
334
|
// 清理session
|
|
355
335
|
this._cleanup(ctx);
|
|
356
336
|
|
|
357
|
-
console.log(' - 清理session后的session_to_save对象:', session_to_save);
|
|
358
|
-
|
|
359
337
|
// 保存session到存储
|
|
360
338
|
return await this._store.set(ctx.session.uuid, session_to_save, this.config.max_age || 7200);
|
|
361
339
|
}
|
package/lib/store.js
CHANGED
|
@@ -50,10 +50,8 @@ Store.prototype.get = async function (uuid) {
|
|
|
50
50
|
Store.prototype.set = async function (uuid, session, max_age = 7200) {
|
|
51
51
|
let session_str = session;
|
|
52
52
|
try {
|
|
53
|
-
console.log(' - Store.set接收到的session对象:', session);
|
|
54
53
|
if (typeof (session_str) == 'object') {
|
|
55
54
|
session_str = JSON.stringify(session_str);
|
|
56
|
-
console.log(' - JSON序列化后的session:', session_str);
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
await $.cache.set(this.key + uuid, session_str, max_age);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_session",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"description": "这是超级美眉session函数模块,用于web服务端session缓存",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"url": "https://gitee.com/qiuwenwu91/mm_session/issues"
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://gitee.com/qiuwenwu91/mm_session#readme",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"mm_cache": "^1.4.8"
|
|
34
|
+
},
|
|
32
35
|
"devDependencies": {
|
|
33
36
|
"eslint-plugin-jsdoc": "^61.5.0",
|
|
34
|
-
"mm_eslint": "^1.
|
|
35
|
-
},
|
|
36
|
-
"dependencies": {
|
|
37
|
-
"mm_cache": "^1.4.7"
|
|
37
|
+
"mm_eslint": "^1.3.7"
|
|
38
38
|
}
|
|
39
39
|
}
|