@yumerijs/core 1.1.0-alpha.2 → 1.1.0-alpha.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.
@@ -1,195 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Platform = void 0;
4
- const session_1 = require("./session");
5
- /**
6
- * Platform 基类
7
- * 作为平台接入的基础类,提供标准化的接口和通用能力
8
- * 各平台实现类需继承此类并实现所有抽象方法
9
- */
10
- class Platform {
11
- /**
12
- * 构造函数
13
- * @param config 平台配置
14
- */
15
- constructor(config) {
16
- // 平台状态
17
- this.status = 'idle';
18
- // 平台错误信息
19
- this.errorMessage = null;
20
- // 平台配置
21
- this.config = {};
22
- // 平台实例ID
23
- this.instanceId = '';
24
- // 平台事件监听器
25
- this.eventListeners = {};
26
- if (config) {
27
- this.config = { ...config };
28
- }
29
- this.instanceId = this.generateInstanceId();
30
- }
31
- /**
32
- * 生成平台实例ID
33
- * @returns 实例ID字符串
34
- */
35
- generateInstanceId() {
36
- return `${this.getPlatformId()}-${Date.now()}-${Math.floor(Math.random() * 1000)}`;
37
- }
38
- /**
39
- * 重启平台
40
- * @param core Core实例
41
- * @returns 重启结果
42
- */
43
- async restartPlatform(core) {
44
- await this.stopPlatform();
45
- return this.startPlatform(core);
46
- }
47
- /**
48
- * 设置平台配置
49
- * @param key 配置键
50
- * @param value 配置值
51
- */
52
- setConfig(key, value) {
53
- this.config[key] = value;
54
- }
55
- /**
56
- * 获取平台配置
57
- * @param key 配置键
58
- * @param defaultValue 默认值
59
- * @returns 配置值
60
- */
61
- getConfig(key, defaultValue) {
62
- return (this.config[key] !== undefined) ? this.config[key] : defaultValue;
63
- }
64
- /**
65
- * 获取平台实例ID
66
- * @returns 实例ID
67
- */
68
- getInstanceId() {
69
- return this.instanceId;
70
- }
71
- /**
72
- * 获取当前平台状态
73
- * @returns 状态字符串
74
- */
75
- getStatus() {
76
- return this.status;
77
- }
78
- /**
79
- * 获取错误信息
80
- * @returns 错误信息
81
- */
82
- getErrorMessage() {
83
- return this.errorMessage;
84
- }
85
- /**
86
- * 添加平台事件监听器
87
- * @param event 事件名称
88
- * @param listener 监听器函数
89
- */
90
- on(event, listener) {
91
- if (!this.eventListeners[event]) {
92
- this.eventListeners[event] = [];
93
- }
94
- this.eventListeners[event].push(listener);
95
- }
96
- /**
97
- * 移除平台事件监听器
98
- * @param event 事件名称
99
- * @param listener 监听器函数
100
- */
101
- off(event, listener) {
102
- if (!this.eventListeners[event]) {
103
- return;
104
- }
105
- this.eventListeners[event] = this.eventListeners[event].filter(l => l !== listener);
106
- }
107
- /**
108
- * 触发平台事件
109
- * @param event 事件名称
110
- * @param args 事件参数
111
- */
112
- emit(event, ...args) {
113
- if (!this.eventListeners[event]) {
114
- return;
115
- }
116
- for (const listener of this.eventListeners[event]) {
117
- try {
118
- listener(...args);
119
- }
120
- catch (error) {
121
- console.error(`Error in platform event listener for "${event}":`, error);
122
- }
123
- }
124
- }
125
- /**
126
- * 创建会话
127
- * @param ip 客户端IP
128
- * @param cookie Cookie对象
129
- * @param query 查询参数
130
- * @returns 会话对象
131
- */
132
- createSession(ip, cookie, query) {
133
- return new session_1.Session(ip, cookie, this, query);
134
- }
135
- /**
136
- * 处理会话数据
137
- * @param session 会话对象
138
- * @param data 会话数据
139
- * @returns 处理结果
140
- */
141
- processSessionData(session, data) {
142
- // 默认实现,子类可覆盖
143
- return data;
144
- }
145
- /**
146
- * 验证会话
147
- * @param session 会话对象
148
- * @returns 验证结果
149
- */
150
- validateSession(session) {
151
- // 默认实现,子类可覆盖
152
- return true;
153
- }
154
- /**
155
- * 获取平台支持的MIME类型
156
- * @returns MIME类型数组
157
- */
158
- getSupportedMimeTypes() {
159
- // 默认实现,子类可覆盖
160
- return [
161
- 'text/plain',
162
- 'text/html',
163
- 'application/json',
164
- 'application/xml',
165
- 'image/png',
166
- 'image/jpeg',
167
- 'application/pdf'
168
- ];
169
- }
170
- /**
171
- * 获取平台元数据
172
- * @returns 平台元数据
173
- */
174
- getMetadata() {
175
- return {
176
- id: this.getPlatformId(),
177
- name: this.getPlatformName(),
178
- version: this.getPlatformVersionCode(),
179
- status: this.getStatus(),
180
- instanceId: this.getInstanceId(),
181
- supportedMimeTypes: this.getSupportedMimeTypes(),
182
- ...this.getPlatformStatus()
183
- };
184
- }
185
- /**
186
- * 获取平台配置模式
187
- * 子类可以覆盖此方法提供自定义配置模式
188
- * @returns 配置模式对象
189
- */
190
- static getConfigSchema() {
191
- return {};
192
- }
193
- }
194
- exports.Platform = Platform;
195
- //# sourceMappingURL=platform.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/platform.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AAInC;;;;GAIG;AACH,MAAsB,QAAQ;IAY1B;;;OAGG;IACH,YAAY,MAA4B;QAfxC,OAAO;QACG,WAAM,GAA2D,MAAM,CAAC;QAClF,SAAS;QACC,iBAAY,GAAkB,IAAI,CAAC;QAC7C,OAAO;QACG,WAAM,GAAwB,EAAE,CAAC;QAC3C,SAAS;QACC,eAAU,GAAW,EAAE,CAAC;QAClC,UAAU;QACA,mBAAc,GAAoD,EAAE,CAAC;QAO3E,IAAI,MAAM,EAAE,CAAC;YACT,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;QAChC,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAChD,CAAC;IAED;;;OAGG;IACO,kBAAkB;QACxB,OAAO,GAAG,IAAI,CAAC,aAAa,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;IACvF,CAAC;IAuDD;;;;OAIG;IACI,KAAK,CAAC,eAAe,CAAC,IAAW;QACpC,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QA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AChD,GAAG,IAAI,CAAC,iBAAiB,EAAE;SAC9B,CAAC;IACN,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,eAAe;QACzB,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AA5PD,4BA4PC"}
@@ -1,29 +0,0 @@
1
- /**
2
- * @time: 2025/03/26 12:36
3
- * @author: FireGuo
4
- * WindyPear-Team All right reserved
5
- **/
6
- import { Platform } from './platform';
7
- export declare class Session {
8
- ip: string;
9
- cookie: Record<string, string>;
10
- query: Record<string, string> | undefined;
11
- sessionid: string;
12
- data: Record<string, any>;
13
- newCookie: Record<string, string>;
14
- head: Record<string, any>;
15
- status: number;
16
- body: any;
17
- platform: Platform;
18
- properties?: Record<string, any>;
19
- constructor(ip: string, cookie: Record<string, string>, platform: Platform, query?: Record<string, string>);
20
- private generateId;
21
- private md5;
22
- setData(key: string, value: any): void;
23
- deleteData(key: string): void;
24
- clearData(): void;
25
- destroy(): void;
26
- setMime(mimeType: 'png' | 'jpg' | 'jpeg' | 'pdf' | 'plain' | 'html' | 'json' | 'xml' | string): void;
27
- send(data: any): any;
28
- endsession(message: any): any;
29
- }
@@ -1,106 +0,0 @@
1
- "use strict";
2
- /**
3
- * @time: 2025/03/26 12:36
4
- * @author: FireGuo
5
- * WindyPear-Team All right reserved
6
- **/
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Session = void 0;
12
- const crypto_1 = __importDefault(require("crypto"));
13
- class Session {
14
- /*
15
- * @ip: string,用户IP
16
- * @cookie: string,会话cookie
17
- * @query: string,请求字符串
18
- */
19
- constructor(ip, cookie, platform, query) {
20
- this.data = {};
21
- this.newCookie = {};
22
- this.head = {};
23
- this.status = 200;
24
- this.properties = {};
25
- this.ip = ip;
26
- this.cookie = cookie;
27
- this.query = query;
28
- this.platform = platform;
29
- this.head['Content-Type'] = 'text/plain';
30
- if (cookie.sessionid) {
31
- this.sessionid = cookie.sessionid;
32
- }
33
- else {
34
- this.sessionid = this.generateId(this.ip);
35
- this.newCookie.sessionid = this.sessionid;
36
- }
37
- }
38
- // 生成 sessionid
39
- /*
40
- * @ip: string,用户IP
41
- * @option: string,选项
42
- */
43
- generateId(ip, option) {
44
- const sessionId = this.md5(ip + Date.now().toString() + Math.random().toString()); // 添加随机性
45
- return sessionId;
46
- }
47
- // MD5 加密
48
- md5(str) {
49
- const hash = crypto_1.default.createHash('md5');
50
- hash.update(str);
51
- return hash.digest('hex');
52
- }
53
- // 设置会话数据
54
- setData(key, value) {
55
- this.data[key] = value;
56
- }
57
- // 删除会话数据
58
- deleteData(key) {
59
- delete this.data[key];
60
- }
61
- // 清空会话数据
62
- clearData() {
63
- this.data = {};
64
- }
65
- // 销毁会话
66
- destroy() {
67
- this.clearData(); // 清理会话数据
68
- }
69
- setMime(mimeType) {
70
- switch (mimeType) {
71
- case 'png':
72
- this.head['Content-Type'] = 'image/png';
73
- break;
74
- case 'jpg':
75
- case 'jpeg':
76
- this.head['Content-Type'] = 'image/jpeg';
77
- break;
78
- case 'pdf':
79
- this.head['Content-Type'] = 'application/pdf';
80
- break;
81
- case 'plain':
82
- this.head['Content-Type'] = 'text/plain';
83
- break;
84
- case 'html':
85
- this.head['Content-Type'] = 'text/html';
86
- break;
87
- case 'json':
88
- this.head['Content-Type'] = 'application/json';
89
- break;
90
- case 'xml':
91
- this.head['Content-Type'] = 'application/xml';
92
- break;
93
- default:
94
- this.head['Content-Type'] = mimeType;
95
- break;
96
- }
97
- }
98
- send(data) {
99
- return this.platform.sendMessage(this, data);
100
- }
101
- endsession(message) {
102
- return this.platform.terminationSession(this, message);
103
- }
104
- }
105
- exports.Session = Session;
106
- //# sourceMappingURL=session.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":";AAAA;;;;IAII;;;;;;AAEJ,oDAA4B;AAG5B,MAAa,O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