@yumerijs/core 1.0.0 → 1.0.2
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/dist/command.d.ts +8 -0
- package/dist/command.js +15 -0
- package/dist/command.js.map +1 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +1 -0
- package/dist/core.d.ts +25 -0
- package/dist/core.js +122 -0
- package/dist/core.js.map +1 -0
- package/dist/index.d.ts +11 -24
- package/dist/index.js +8 -117
- package/dist/index.js.map +1 -1
- package/dist/session.d.ts +15 -0
- package/dist/session.js +83 -0
- package/dist/session.js.map +1 -0
- package/package.json +2 -1
package/dist/command.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Command = void 0;
|
|
4
|
+
class Command {
|
|
5
|
+
constructor(command, session) {
|
|
6
|
+
this.command = command;
|
|
7
|
+
this.session = session;
|
|
8
|
+
}
|
|
9
|
+
excute(core) {
|
|
10
|
+
core.emit('onexcute', this.session);
|
|
11
|
+
core.emit('oncommand', this.command, this.session);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.Command = Command;
|
|
15
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":";;;AAIA,MAAa,OAAO;IAGlB,YAAY,OAAe,EAAE,OAAgB;QAC3C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,MAAM,CAAC,IAAU;QACf,IAAI,CAAC,IAAI,CAAC,UAAU,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAC,IAAI,CAAC,OAAO,EAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAClD,CAAC;CACF;AAZD,0BAYC"}
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Config = void 0;
|
|
4
|
+
class Config {
|
|
5
|
+
constructor(name, content) {
|
|
6
|
+
this.name = '';
|
|
7
|
+
this.content = {};
|
|
8
|
+
this.name = name;
|
|
9
|
+
this.content = content;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.Config = Config;
|
|
13
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAAA,MAAa,MAAM;IAIf,YAAY,IAAY,EAAE,OAAmC;QAHtD,SAAI,GAAW,EAAE,CAAC;QAClB,YAAO,GAA+B,EAAE,CAAC;QAG5C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;CACJ;AARD,wBAQC"}
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Config } from './config';
|
|
2
|
+
interface Plugin {
|
|
3
|
+
apply: (core: Core, config: Config) => Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
interface PluginLoader {
|
|
6
|
+
load: (pluginName: string) => Promise<Plugin>;
|
|
7
|
+
}
|
|
8
|
+
interface CoreOptions {
|
|
9
|
+
}
|
|
10
|
+
declare class Core {
|
|
11
|
+
plugins: {
|
|
12
|
+
[name: string]: Plugin;
|
|
13
|
+
};
|
|
14
|
+
config: any;
|
|
15
|
+
private eventListeners;
|
|
16
|
+
private components;
|
|
17
|
+
constructor(options?: CoreOptions);
|
|
18
|
+
loadConfig(configPath: string): Promise<void>;
|
|
19
|
+
loadPlugins(pluginLoader: PluginLoader): Promise<void>;
|
|
20
|
+
registerComponent(name: string, component: any): void;
|
|
21
|
+
getComponent(name: string): any;
|
|
22
|
+
on(event: string, listener: (...args: any[]) => Promise<void>): void;
|
|
23
|
+
emit(event: string, ...args: any[]): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export default Core;
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const yaml = __importStar(require("js-yaml"));
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const config_1 = require("./config");
|
|
39
|
+
class Core {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.plugins = {};
|
|
42
|
+
this.config = null;
|
|
43
|
+
this.eventListeners = {};
|
|
44
|
+
this.components = {};
|
|
45
|
+
// 可以根据 options 初始化
|
|
46
|
+
}
|
|
47
|
+
// 加载配置文件
|
|
48
|
+
async loadConfig(configPath) {
|
|
49
|
+
try {
|
|
50
|
+
const doc = yaml.load(fs.readFileSync(configPath, 'utf8'));
|
|
51
|
+
this.config = doc;
|
|
52
|
+
console.log('Config loaded:', this.config);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error('Failed to load config:', e);
|
|
56
|
+
throw e; // 抛出异常,让上层处理
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// 加载插件
|
|
60
|
+
async loadPlugins(pluginLoader) {
|
|
61
|
+
if (!this.config || !this.config.plugins) {
|
|
62
|
+
console.log('No plugins to load.');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
for (const plugins of this.config.plugins) {
|
|
66
|
+
try {
|
|
67
|
+
console.log(`Loading plugin: ${plugins.name}`);
|
|
68
|
+
const config = new config_1.Config(plugins.name, plugins.config);
|
|
69
|
+
const plugin = await pluginLoader.load(plugins.name);
|
|
70
|
+
this.plugins[plugins.name] = plugin;
|
|
71
|
+
console.log(`Plugin ${plugins.name} loaded.`);
|
|
72
|
+
if (plugin.apply) {
|
|
73
|
+
console.log(`Applying plugin: ${plugins.name}`);
|
|
74
|
+
await plugin.apply(this, config);
|
|
75
|
+
console.log(`Plugin ${plugins.name} applied.`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
console.error(`Failed to load plugin ${plugins.name}:`, err);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// 注册组件
|
|
84
|
+
registerComponent(name, component) {
|
|
85
|
+
if (this.components[name]) {
|
|
86
|
+
console.warn(`Component "${name}" already registered.`);
|
|
87
|
+
}
|
|
88
|
+
this.components[name] = component;
|
|
89
|
+
console.log(`Component "${name}" registered.`);
|
|
90
|
+
}
|
|
91
|
+
// 获取组件
|
|
92
|
+
getComponent(name) {
|
|
93
|
+
return this.components[name];
|
|
94
|
+
}
|
|
95
|
+
// 事件系统:监听事件
|
|
96
|
+
on(event, listener) {
|
|
97
|
+
if (!this.eventListeners[event]) {
|
|
98
|
+
this.eventListeners[event] = [];
|
|
99
|
+
}
|
|
100
|
+
this.eventListeners[event].push(listener);
|
|
101
|
+
console.log(`Listener added for event "${event}".`);
|
|
102
|
+
}
|
|
103
|
+
// 事件系统:触发事件
|
|
104
|
+
async emit(event, ...args) {
|
|
105
|
+
if (this.eventListeners[event]) {
|
|
106
|
+
console.log(`Emitting event "${event}" with args:`, args);
|
|
107
|
+
for (const listener of this.eventListeners[event]) {
|
|
108
|
+
try {
|
|
109
|
+
await listener(...args);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
console.error(`Error in event listener for "${event}":`, err);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
console.log(`No listeners for event "${event}".`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.default = Core;
|
|
122
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAE,8CAAgC;AAChC,u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AC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO,CAAC,GAAG,CAAC,6BAA6B,KAAK,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,YAAY;IACZ,KAAK,CAAC,IAAI,CAAC,KAAa,EAAE,GAAG,IAAW;QACtC,IAAI,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO,CAAC,GAAG,CAAC,mBAAmB,KAAK,cAAc,EAAE,IAAI,CAAC,CAAC;YAC1D,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClD,IAAI,CAAC;oBACH,MAAM,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;gBAC1B,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,CAAC,KAAK,CAAC,gCAAgC,KAAK,IAAI,EAAE,GAAG,CAAC,CAAC;gBAChE,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,IAAI,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;CACF;AAED,kBAAe,IAAI,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
config: any;
|
|
14
|
-
private eventListeners;
|
|
15
|
-
private components;
|
|
16
|
-
constructor(options?: CoreOptions);
|
|
17
|
-
loadConfig(configPath: string): Promise<void>;
|
|
18
|
-
loadPlugins(pluginLoader: PluginLoader): Promise<void>;
|
|
19
|
-
registerComponent(name: string, component: any): void;
|
|
20
|
-
getComponent(name: string): any;
|
|
21
|
-
on(event: string, listener: (...args: any[]) => Promise<void>): void;
|
|
22
|
-
emit(event: string, ...args: any[]): Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
export default Core;
|
|
1
|
+
import Core from './core';
|
|
2
|
+
import { Session } from './session';
|
|
3
|
+
import { Command } from './command';
|
|
4
|
+
import { Config } from './config';
|
|
5
|
+
declare const _default: {
|
|
6
|
+
Core: typeof Core;
|
|
7
|
+
Session: typeof Session;
|
|
8
|
+
Command: typeof Command;
|
|
9
|
+
Config: typeof Config;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,120 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
35
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.config = null;
|
|
42
|
-
this.eventListeners = {};
|
|
43
|
-
this.components = {};
|
|
44
|
-
// 可以根据 options 初始化
|
|
45
|
-
}
|
|
46
|
-
// 加载配置文件
|
|
47
|
-
async loadConfig(configPath) {
|
|
48
|
-
try {
|
|
49
|
-
const doc = yaml.load(fs.readFileSync(configPath, 'utf8'));
|
|
50
|
-
this.config = doc;
|
|
51
|
-
console.log('Config loaded:', this.config);
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
console.error('Failed to load config:', e);
|
|
55
|
-
throw e; // 抛出异常,让上层处理
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// 加载插件
|
|
59
|
-
async loadPlugins(pluginLoader) {
|
|
60
|
-
if (!this.config || !this.config.plugins) {
|
|
61
|
-
console.log('No plugins to load.');
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
for (const pluginName of this.config.plugins) {
|
|
65
|
-
try {
|
|
66
|
-
console.log(`Loading plugin: ${pluginName}`);
|
|
67
|
-
const plugin = await pluginLoader.load(pluginName);
|
|
68
|
-
this.plugins[pluginName] = plugin;
|
|
69
|
-
console.log(`Plugin ${pluginName} loaded.`);
|
|
70
|
-
if (plugin.apply) {
|
|
71
|
-
console.log(`Applying plugin: ${pluginName}`);
|
|
72
|
-
await plugin.apply(this);
|
|
73
|
-
console.log(`Plugin ${pluginName} applied.`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
console.error(`Failed to load plugin ${pluginName}:`, err);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
// 注册组件
|
|
82
|
-
registerComponent(name, component) {
|
|
83
|
-
if (this.components[name]) {
|
|
84
|
-
console.warn(`Component "${name}" already registered.`);
|
|
85
|
-
}
|
|
86
|
-
this.components[name] = component;
|
|
87
|
-
console.log(`Component "${name}" registered.`);
|
|
88
|
-
}
|
|
89
|
-
// 获取组件
|
|
90
|
-
getComponent(name) {
|
|
91
|
-
return this.components[name];
|
|
92
|
-
}
|
|
93
|
-
// 事件系统:监听事件
|
|
94
|
-
on(event, listener) {
|
|
95
|
-
if (!this.eventListeners[event]) {
|
|
96
|
-
this.eventListeners[event] = [];
|
|
97
|
-
}
|
|
98
|
-
this.eventListeners[event].push(listener);
|
|
99
|
-
console.log(`Listener added for event "${event}".`);
|
|
100
|
-
}
|
|
101
|
-
// 事件系统:触发事件
|
|
102
|
-
async emit(event, ...args) {
|
|
103
|
-
if (this.eventListeners[event]) {
|
|
104
|
-
console.log(`Emitting event "${event}" with args:`, args);
|
|
105
|
-
for (const listener of this.eventListeners[event]) {
|
|
106
|
-
try {
|
|
107
|
-
await listener(...args);
|
|
108
|
-
}
|
|
109
|
-
catch (err) {
|
|
110
|
-
console.error(`Error in event listener for "${event}":`, err);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
console.log(`No listeners for event "${event}".`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
exports.default = Core;
|
|
6
|
+
const core_1 = __importDefault(require("./core"));
|
|
7
|
+
const session_1 = require("./session");
|
|
8
|
+
const command_1 = require("./command");
|
|
9
|
+
const config_1 = require("./config");
|
|
10
|
+
exports.default = { Core: core_1.default, Session: session_1.Session, Command: command_1.Command, Config: config_1.Config };
|
|
120
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAC1B,uCAAoC;AACpC,uCAAoC;AACpC,qCAAkC;AAElC,kBAAe,EAAE,IAAI,EAAJ,cAAI,EAAE,OAAO,EAAP,iBAAO,EAAE,OAAO,EAAP,iBAAO,EAAE,MAAM,EAAN,eAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class Session {
|
|
2
|
+
ip: string;
|
|
3
|
+
cookie: string;
|
|
4
|
+
query: string | undefined;
|
|
5
|
+
sessionid: string;
|
|
6
|
+
data: Record<string, any>;
|
|
7
|
+
constructor(ip: string, cookie: string, query?: string);
|
|
8
|
+
private generateId;
|
|
9
|
+
private md5;
|
|
10
|
+
setData(key: string, value: any): void;
|
|
11
|
+
deleteData(key: string): void;
|
|
12
|
+
clearData(): void;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
private getCommand;
|
|
15
|
+
}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Session = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
class Session {
|
|
9
|
+
/*
|
|
10
|
+
* @ip: string,用户IP
|
|
11
|
+
* @cookie: string,会话cookie
|
|
12
|
+
* @query: string,请求字符串
|
|
13
|
+
*/
|
|
14
|
+
constructor(ip, cookie, query) {
|
|
15
|
+
this.data = {};
|
|
16
|
+
this.ip = ip;
|
|
17
|
+
this.cookie = cookie;
|
|
18
|
+
this.query = query;
|
|
19
|
+
let jsoncookie;
|
|
20
|
+
try {
|
|
21
|
+
jsoncookie = JSON.parse(this.cookie);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error("Error parsing cookie:", error);
|
|
25
|
+
jsoncookie = {};
|
|
26
|
+
}
|
|
27
|
+
if (jsoncookie.sessionid) {
|
|
28
|
+
this.sessionid = jsoncookie.sessionid;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.sessionid = this.generateId(this.ip);
|
|
32
|
+
// TODO: 在这里设置 cookie,将 sessionid 返回给客户端
|
|
33
|
+
// 例如设置响应头 Set-Cookie: sessionid=xxx; HttpOnly
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// 生成 sessionid
|
|
37
|
+
generateId(ip, option) {
|
|
38
|
+
const sessionId = this.md5(ip + Date.now().toString() + Math.random().toString()); // 添加随机性
|
|
39
|
+
return sessionId;
|
|
40
|
+
}
|
|
41
|
+
// MD5 加密
|
|
42
|
+
md5(str) {
|
|
43
|
+
const hash = crypto_1.default.createHash('md5');
|
|
44
|
+
hash.update(str);
|
|
45
|
+
return hash.digest('hex');
|
|
46
|
+
}
|
|
47
|
+
// 设置会话数据
|
|
48
|
+
setData(key, value) {
|
|
49
|
+
this.data[key] = value;
|
|
50
|
+
}
|
|
51
|
+
// 删除会话数据
|
|
52
|
+
deleteData(key) {
|
|
53
|
+
delete this.data[key];
|
|
54
|
+
}
|
|
55
|
+
// 清空会话数据
|
|
56
|
+
clearData() {
|
|
57
|
+
this.data = {};
|
|
58
|
+
}
|
|
59
|
+
// (可选)销毁会话
|
|
60
|
+
destroy() {
|
|
61
|
+
this.clearData(); // 清理会话数据
|
|
62
|
+
}
|
|
63
|
+
// 从请求路径提取指令和剩余的查询字符串
|
|
64
|
+
getCommand() {
|
|
65
|
+
try {
|
|
66
|
+
const jsoncookie = JSON.parse(this.cookie);
|
|
67
|
+
if (jsoncookie.requestPath) {
|
|
68
|
+
const path = jsoncookie.requestPath;
|
|
69
|
+
const pathParts = path.split('?'); // 分割路径和查询字符串
|
|
70
|
+
const command = pathParts[0].substring(1); // 移除开头的 '/' (如果存在)
|
|
71
|
+
const queryString = pathParts.length > 1 ? pathParts[1] : null; // 获取查询字符串,若没有则为 null
|
|
72
|
+
return { command: command || null, queryString };
|
|
73
|
+
}
|
|
74
|
+
return { command: null, queryString: null };
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
console.error('Could not extract path from cookie', e);
|
|
78
|
+
return { command: null, queryString: null };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.Session = Session;
|
|
83
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,MAAa,OAAO;IAQhB;;;;OAIG;IACH,YAAY,EAAU,EAAE,MAAc,EAAE,KAAc;QAR/C,SAAI,GAAwB,EAAE,CAAC;QASlC,IAAI,CAAC,EAAE,GAAI,EAAE,CAAC;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,IAAI,UAAe,CAAC;QACpB,IAAI,CAAC;YACA,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;YAC9C,UAAU,GAAG,EAAE,CAAC;QACpB,CAAC;QAED,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;YACvB,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;QAC1C,CAAC;aACI,CAAC;YACF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,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,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,mBAAmB;gBAC9D,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,qBAAqB;gBAErF,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,WAAW,EAAE,CAAC;YACnD,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QAC9C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,CAAC,CAAC,CAAC;YACvD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QAC9C,CAAC;IACH,CAAC;CACF;AAtFD,0BAsFC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yumerijs/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Core module for yumeri",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"typescript": "^5.8.2"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"js-sha256": "^0.11.0",
|
|
34
35
|
"js-yaml": "^4.1.0"
|
|
35
36
|
}
|
|
36
37
|
}
|