@pisell/core 1.0.7 → 1.0.8

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,4 +1,4 @@
1
- import { ReconnectOptions } from './types';
1
+ import { ReconnectOptions } from "./types";
2
2
  /**
3
3
  * Socket重连管理器
4
4
  * 处理断线重连逻辑
@@ -154,7 +154,7 @@ export var ReconnectManager = /*#__PURE__*/function () {
154
154
  case 6:
155
155
  _context.prev = 6;
156
156
  _context.t0 = _context["catch"](0);
157
- this.onFail(_context.t0 instanceof Error ? _context.t0 : new Error('Reconnect failed'));
157
+ this.onFail(_context.t0 instanceof Error ? _context.t0 : new Error("Reconnect failed"));
158
158
  return _context.abrupt("return", false);
159
159
  case 10:
160
160
  case "end":
@@ -25,8 +25,9 @@ export declare class Socket {
25
25
  connect(): Promise<void>;
26
26
  /**
27
27
  * 关闭WebSocket连接
28
+ * @param isManual 是否手动关闭
28
29
  */
29
- disconnect(): void;
30
+ disconnect(isManual?: boolean): void;
30
31
  /**
31
32
  * 发送消息到服务器
32
33
  * @param event 事件名称
@@ -16,6 +16,7 @@ import { SocketEvents } from "./events";
16
16
  import { HeartbeatManager } from "./heartbeat";
17
17
  import { ReconnectManager } from "./reconnect";
18
18
  import { SocketMonitor } from "./monitor";
19
+ import { getApp } from "../app";
19
20
 
20
21
  /**
21
22
  * Socket主类
@@ -45,7 +46,9 @@ export var Socket = /*#__PURE__*/function () {
45
46
 
46
47
  // 如果配置了自动连接,则立即连接
47
48
  if (this.options.autoConnect) {
48
- this.connect();
49
+ this.connect().catch(function (error) {
50
+ console.warn("Socket connection failed:", error);
51
+ });
49
52
  }
50
53
  }
51
54
 
@@ -57,18 +60,29 @@ export var Socket = /*#__PURE__*/function () {
57
60
  value: (function () {
58
61
  var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
59
62
  var _this = this;
63
+ var app, isConnected;
60
64
  return _regeneratorRuntime().wrap(function _callee$(_context) {
61
65
  while (1) switch (_context.prev = _context.next) {
62
66
  case 0:
63
- if (!(this.isConnected() || this.status === SocketStatus.CONNECTING)) {
64
- _context.next = 2;
67
+ app = getApp();
68
+ isConnected = this.isConnected();
69
+ if (!(isConnected || this.status === SocketStatus.CONNECTING)) {
70
+ _context.next = 5;
65
71
  break;
66
72
  }
73
+ app.logger.addLog({
74
+ type: "info",
75
+ title: "socket已连接或连接中",
76
+ metadata: {
77
+ isConnected: isConnected,
78
+ status: this.status
79
+ }
80
+ });
67
81
  return _context.abrupt("return");
68
- case 2:
82
+ case 5:
69
83
  // 设置状态为连接中
70
84
  this.setStatus(SocketStatus.CONNECTING);
71
- _context.prev = 3;
85
+ _context.prev = 6;
72
86
  // 创建WebSocket连接
73
87
  this.ws = new WebSocket(this.url, this.options.protocols);
74
88
 
@@ -76,7 +90,7 @@ export var Socket = /*#__PURE__*/function () {
76
90
  this.setupWebSocketListeners();
77
91
 
78
92
  // 等待连接打开
79
- _context.next = 8;
93
+ _context.next = 11;
80
94
  return new Promise(function (resolve, reject) {
81
95
  // 连接超时
82
96
  var timeoutId = setTimeout(function () {
@@ -101,7 +115,7 @@ export var Socket = /*#__PURE__*/function () {
101
115
  once: true
102
116
  });
103
117
  });
104
- case 8:
118
+ case 11:
105
119
  // 初始化心跳检测
106
120
  if (this.options.heartbeat) {
107
121
  this.initHeartbeat();
@@ -111,19 +125,19 @@ export var Socket = /*#__PURE__*/function () {
111
125
  if (this.options.reconnection) {
112
126
  this.initReconnect();
113
127
  }
114
- _context.next = 16;
128
+ _context.next = 19;
115
129
  break;
116
- case 12:
117
- _context.prev = 12;
118
- _context.t0 = _context["catch"](3);
130
+ case 15:
131
+ _context.prev = 15;
132
+ _context.t0 = _context["catch"](6);
119
133
  // 连接失败,执行重连(如果启用)
120
134
  this.handleConnectionFailure(_context.t0);
121
135
  throw _context.t0;
122
- case 16:
136
+ case 19:
123
137
  case "end":
124
138
  return _context.stop();
125
139
  }
126
- }, _callee, this, [[3, 12]]);
140
+ }, _callee, this, [[6, 15]]);
127
141
  }));
128
142
  function connect() {
129
143
  return _connect.apply(this, arguments);
@@ -132,11 +146,13 @@ export var Socket = /*#__PURE__*/function () {
132
146
  }()
133
147
  /**
134
148
  * 关闭WebSocket连接
149
+ * @param isManual 是否手动关闭
135
150
  */
136
151
  )
137
152
  }, {
138
153
  key: "disconnect",
139
154
  value: function disconnect() {
155
+ var isManual = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
140
156
  if (!this.ws || this.status === SocketStatus.CLOSED || this.status === SocketStatus.CLOSING) {
141
157
  return;
142
158
  }
@@ -166,7 +182,9 @@ export var Socket = /*#__PURE__*/function () {
166
182
  this.ws = null;
167
183
 
168
184
  // 触发断开连接事件
169
- this.emit(SocketEvents.DISCONNECT);
185
+ this.emit(SocketEvents.DISCONNECT, {
186
+ isManual: isManual
187
+ });
170
188
  }
171
189
 
172
190
  /**
@@ -473,7 +491,7 @@ export var Socket = /*#__PURE__*/function () {
473
491
  attempts: this.options.reconnectionAttempts,
474
492
  delay: this.options.reconnectionDelay,
475
493
  delayMax: this.options.reconnectionDelayMax,
476
- jitter: true
494
+ jitter: false
477
495
  };
478
496
 
479
497
  // 创建重连管理器
@@ -575,7 +593,7 @@ export var Socket = /*#__PURE__*/function () {
575
593
  key: "destroy",
576
594
  value: function destroy() {
577
595
  // 断开连接
578
- this.disconnect();
596
+ this.disconnect(true);
579
597
 
580
598
  // 停止监控
581
599
  if (this.monitor) {
@@ -45,7 +45,6 @@ export interface SocketMessage<T = any> {
45
45
  data?: T;
46
46
  /** 消息ID */
47
47
  id?: string;
48
- event?: any;
49
48
  }
50
49
  /**
51
50
  * 心跳配置选项
@@ -5,6 +5,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
5
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
7
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ // 优先级
9
+ // 失效期
10
+ // 主动清理
8
11
  export var Storage = /*#__PURE__*/_createClass(function Storage(app, options) {
9
12
  var _this = this;
10
13
  _classCallCheck(this, Storage);
@@ -10,6 +10,7 @@ export declare class TasksManager {
10
10
  tasks: TasksModule;
11
11
  };
12
12
  watchTaskCallback: (taskModule: TasksModule) => void;
13
+ private timerIds;
13
14
  constructor(app: App);
14
15
  static getInstance(app?: App): TasksManager;
15
16
  addTaskFunction<T>(name: string, fun: T): void;
@@ -31,6 +32,11 @@ export declare class TasksManager {
31
32
  * @Date: 2024-09-26 13:53
32
33
  */
33
34
  private runTask;
35
+ /**
36
+ * @title: 清除任务定时器
37
+ * @param {NodeJS.Timeout} timerId
38
+ */
39
+ private clearTaskTimer;
34
40
  /**
35
41
  * @title: 启动轮询
36
42
  * @description: 根据轮询间隔定期执行任务
package/es/tasks/index.js CHANGED
@@ -31,6 +31,7 @@ export var TasksManager = /*#__PURE__*/function () {
31
31
  _defineProperty(this, "db", void 0);
32
32
  _defineProperty(this, "useTasks", useTasks);
33
33
  _defineProperty(this, "watchTaskCallback", function () {});
34
+ _defineProperty(this, "timerIds", []);
34
35
  // 将任务队列状态同步到 local
35
36
  _defineProperty(this, "saveTaskQueueToLocal", /*#__PURE__*/function () {
36
37
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(state) {
@@ -170,27 +171,26 @@ export var TasksManager = /*#__PURE__*/function () {
170
171
  case 16:
171
172
  afterActionRes = _context3.sent;
172
173
  case 17:
173
- _context3.next = 24;
174
+ _context3.next = 23;
174
175
  break;
175
176
  case 19:
176
177
  _context3.prev = 19;
177
178
  _context3.t0 = _context3["catch"](4);
178
179
  _this.app.logger.addLog({
179
- type: "error",
180
+ type: "info",
180
181
  title: "\u4EFB\u52A1\u6267\u884C\u5931\u8D25-".concat(task.id),
181
182
  metadata: {
182
183
  error: _context3.t0,
183
184
  taskPayload: task === null || task === void 0 ? void 0 : task.payload
184
185
  }
185
186
  });
186
- console.log("任务执行失败", _context3.t0);
187
187
  actionRes = {
188
188
  status: "failure"
189
189
  };
190
- case 24:
190
+ case 23:
191
191
  console.log("Tasks--->", "\u4EFB\u52A1\u6267\u884C\u6210\u529F: ".concat(task.id));
192
192
  return _context3.abrupt("return", actionRes);
193
- case 26:
193
+ case 25:
194
194
  case "end":
195
195
  return _context3.stop();
196
196
  }
@@ -200,6 +200,40 @@ export var TasksManager = /*#__PURE__*/function () {
200
200
  return _ref3.apply(this, arguments);
201
201
  };
202
202
  }());
203
+ /**
204
+ * @title: 清除任务定时器
205
+ * @param {NodeJS.Timeout} timerId
206
+ */
207
+ _defineProperty(this, "clearTaskTimer", function (params) {
208
+ var timerId = params.timerId,
209
+ taskId = params.taskId;
210
+ var _timerIds = [];
211
+ var needClearTimerIds = [];
212
+ _this.timerIds.forEach(function (id) {
213
+ var taskIdRult = taskId ? (id === null || id === void 0 ? void 0 : id.taskId) === taskId : true;
214
+ var timerIdRult = timerId ? (id === null || id === void 0 ? void 0 : id.timerId) === timerId : true;
215
+ if (taskIdRult && timerIdRult) {
216
+ needClearTimerIds.push(id);
217
+ } else {
218
+ _timerIds.push(id);
219
+ }
220
+ });
221
+ if (needClearTimerIds.length) {
222
+ var _iterator2 = _createForOfIteratorHelper(needClearTimerIds),
223
+ _step2;
224
+ try {
225
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
226
+ var id = _step2.value;
227
+ clearTimeout(id.timerId);
228
+ }
229
+ } catch (err) {
230
+ _iterator2.e(err);
231
+ } finally {
232
+ _iterator2.f();
233
+ }
234
+ }
235
+ _this.timerIds = _toConsumableArray(_timerIds || []);
236
+ });
203
237
  /**
204
238
  * @title: 启动轮询
205
239
  * @description: 根据轮询间隔定期执行任务
@@ -246,7 +280,9 @@ export var TasksManager = /*#__PURE__*/function () {
246
280
  case 12:
247
281
  _context4.prev = 12;
248
282
  _context4.t0 = _context4["catch"](0);
249
- clearTimeout(timerId);
283
+ _this.clearTaskTimer({
284
+ timerId: timerId
285
+ });
250
286
  console.error("轮询任务异常", _context4.t0);
251
287
  case 16:
252
288
  case "end":
@@ -254,6 +290,10 @@ export var TasksManager = /*#__PURE__*/function () {
254
290
  }
255
291
  }, _callee4, null, [[0, 12]]);
256
292
  })), task.polling.interval);
293
+ _this.timerIds.push({
294
+ taskId: task.id,
295
+ timerId: timerId
296
+ });
257
297
  });
258
298
  /**
259
299
  * @title: 创建任务数据
@@ -306,6 +346,7 @@ export var TasksManager = /*#__PURE__*/function () {
306
346
  this.taskFunctions = new Map();
307
347
  this.tasks = {};
308
348
  this.db = app.dbManager;
349
+ this.timerIds = [];
309
350
  }
310
351
 
311
352
  // 单例模式
@@ -386,7 +427,7 @@ export var TasksManager = /*#__PURE__*/function () {
386
427
  */
387
428
  function () {
388
429
  var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(payload) {
389
- var queueId, module, callback, taskQueueStatus, taskQueue, errorTaskIds, _this$getTaskQueue, tasksToExecute, _iterator2, _step2, task, _yield$this$runTask, status, _task$pollingResult2, _other;
430
+ var queueId, module, callback, taskQueueStatus, taskQueue, errorTaskIds, _this$getTaskQueue, tasksToExecute, _iterator3, _step3, task, _yield$this$runTask, status, _task$pollingResult2, _other;
390
431
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
391
432
  while (1) switch (_context6.prev = _context6.next) {
392
433
  case 0:
@@ -408,15 +449,15 @@ export var TasksManager = /*#__PURE__*/function () {
408
449
  return (task === null || task === void 0 ? void 0 : task.status) === "pending" || (task === null || task === void 0 ? void 0 : task.status) === "failure";
409
450
  });
410
451
  console.log("Tasks--->", "需要执行的任务", tasksToExecute);
411
- _iterator2 = _createForOfIteratorHelper(tasksToExecute);
452
+ _iterator3 = _createForOfIteratorHelper(tasksToExecute);
412
453
  _context6.prev = 9;
413
- _iterator2.s();
454
+ _iterator3.s();
414
455
  case 11:
415
- if ((_step2 = _iterator2.n()).done) {
456
+ if ((_step3 = _iterator3.n()).done) {
416
457
  _context6.next = 38;
417
458
  break;
418
459
  }
419
- task = _step2.value;
460
+ task = _step3.value;
420
461
  _context6.prev = 13;
421
462
  if (!(task.retries !== undefined && task.maxRetries !== undefined && task.retries < task.maxRetries)) {
422
463
  _context6.next = 29;
@@ -499,10 +540,10 @@ export var TasksManager = /*#__PURE__*/function () {
499
540
  case 40:
500
541
  _context6.prev = 40;
501
542
  _context6.t1 = _context6["catch"](9);
502
- _iterator2.e(_context6.t1);
543
+ _iterator3.e(_context6.t1);
503
544
  case 43:
504
545
  _context6.prev = 43;
505
- _iterator2.f();
546
+ _iterator3.f();
506
547
  return _context6.finish(43);
507
548
  case 46:
508
549
  taskQueueStatus = (_this$getTaskQueue = this.getTaskQueue(payload)) !== null && _this$getTaskQueue !== void 0 && _this$getTaskQueue.some(function (task) {
@@ -558,14 +599,17 @@ export var TasksManager = /*#__PURE__*/function () {
558
599
  }, {
559
600
  key: "deleteTask",
560
601
  value: function deleteTask(payload) {
561
- var _this$tasks;
602
+ var _this$tasks,
603
+ _this3 = this;
562
604
  var queueId = payload.queueId,
563
605
  module = payload.module,
564
606
  taskId = payload.taskId;
565
607
  this.tasks[module][queueId].tasks = (_this$tasks = this.tasks) === null || _this$tasks === void 0 || (_this$tasks = _this$tasks[module]) === null || _this$tasks === void 0 || (_this$tasks = _this$tasks[queueId]) === null || _this$tasks === void 0 || (_this$tasks = _this$tasks.tasks) === null || _this$tasks === void 0 ? void 0 : _this$tasks.filter(function (task) {
566
608
  var _task$pollingResult3;
567
609
  if ((_task$pollingResult3 = task.pollingResult) !== null && _task$pollingResult3 !== void 0 && _task$pollingResult3.timerId) {
568
- clearTimeout(task.pollingResult.timerId);
610
+ _this3.clearTaskTimer({
611
+ timerId: task.pollingResult.timerId
612
+ });
569
613
  }
570
614
  return task.id !== taskId;
571
615
  });
@@ -597,7 +641,7 @@ export var TasksManager = /*#__PURE__*/function () {
597
641
  value: function addTask(payload) {
598
642
  var _this$tasks$module2,
599
643
  _tasks$map,
600
- _this3 = this;
644
+ _this4 = this;
601
645
  var queueId = payload.queueId,
602
646
  module = payload.module,
603
647
  tasks = payload.tasks;
@@ -608,7 +652,7 @@ export var TasksManager = /*#__PURE__*/function () {
608
652
 
609
653
  // 创建新任务
610
654
  var newTasks = tasks === null || tasks === void 0 || (_tasks$map = tasks.map) === null || _tasks$map === void 0 ? void 0 : _tasks$map.call(tasks, function (d) {
611
- return _this3.createTaskData(_objectSpread(_objectSpread({}, d), {}, {
655
+ return _this4.createTaskData(_objectSpread(_objectSpread({}, d), {}, {
612
656
  queueId: queueId,
613
657
  module: module
614
658
  }));
@@ -688,20 +732,19 @@ export var TasksManager = /*#__PURE__*/function () {
688
732
  }, {
689
733
  key: "clearAllTaskTimer",
690
734
  value: function clearAllTaskTimer(tasks) {
691
- var _iterator3 = _createForOfIteratorHelper(tasks || []),
692
- _step3;
735
+ var _iterator4 = _createForOfIteratorHelper(tasks || []),
736
+ _step4;
693
737
  try {
694
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
695
- var _task$pollingResult4;
696
- var task = _step3.value;
697
- if ((_task$pollingResult4 = task.pollingResult) !== null && _task$pollingResult4 !== void 0 && _task$pollingResult4.timerId) {
698
- clearTimeout(task.pollingResult.timerId);
699
- }
738
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
739
+ var task = _step4.value;
740
+ this.clearTaskTimer({
741
+ taskId: task.id
742
+ });
700
743
  }
701
744
  } catch (err) {
702
- _iterator3.e(err);
745
+ _iterator4.e(err);
703
746
  } finally {
704
- _iterator3.f();
747
+ _iterator4.f();
705
748
  }
706
749
  }
707
750
 
@@ -723,6 +766,21 @@ export var TasksManager = /*#__PURE__*/function () {
723
766
  value: function clearAllTasks() {
724
767
  this.tasks = {};
725
768
  this.saveTaskQueueToLocal(this.tasks);
769
+ if (this.timerIds.length) {
770
+ var _iterator5 = _createForOfIteratorHelper(this.timerIds),
771
+ _step5;
772
+ try {
773
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
774
+ var timerId = _step5.value;
775
+ clearTimeout(timerId);
776
+ }
777
+ } catch (err) {
778
+ _iterator5.e(err);
779
+ } finally {
780
+ _iterator5.f();
781
+ }
782
+ this.timerIds = [];
783
+ }
726
784
  console.log("Tasks--->", "清空全部任务");
727
785
  }
728
786
  }, {
package/lib/app/app.d.ts CHANGED
@@ -8,6 +8,8 @@ import { MenuManager } from '../menuManager';
8
8
  import LoggerManager, { LoggerOptions } from '../logger';
9
9
  import { TasksManager } from '../tasks';
10
10
  import IndexDBManager, { DBOptions } from '../indexDB';
11
+ import CMD from "../cmd";
12
+ import AWS from "../aws";
11
13
  declare global {
12
14
  interface Window {
13
15
  app: App;
@@ -61,6 +63,8 @@ declare class App {
61
63
  };
62
64
  logger: LoggerManager;
63
65
  pubsub: import("../pubsub").PubSub;
66
+ cmd: CMD;
67
+ aws: AWS;
64
68
  tasksManager: TasksManager;
65
69
  dbManager: IndexDBManager | null;
66
70
  constants: {
package/lib/app/app.js CHANGED
@@ -49,6 +49,8 @@ var import_tasks = require("../tasks");
49
49
  var import_indexDB = __toESM(require("../indexDB"));
50
50
  var import_pubsub = __toESM(require("../pubsub"));
51
51
  var import_const = require("./const");
52
+ var import_cmd = __toESM(require("../cmd"));
53
+ var import_aws = __toESM(require("../aws"));
52
54
  var App = class _App {
53
55
  // 实例
54
56
  static instance;
@@ -84,6 +86,10 @@ var App = class _App {
84
86
  logger;
85
87
  // 发布订阅
86
88
  pubsub = import_pubsub.default;
89
+ // cmd
90
+ cmd;
91
+ // aws
92
+ aws;
87
93
  // 任务管理
88
94
  tasksManager;
89
95
  dbManager = null;
@@ -105,6 +111,8 @@ var App = class _App {
105
111
  }
106
112
  this.logger = new import_logger.default(this, options == null ? void 0 : options.logger);
107
113
  this.tasksManager = new import_tasks.TasksManager(this);
114
+ this.cmd = new import_cmd.default(this, options == null ? void 0 : options.cmd);
115
+ this.aws = new import_aws.default(this, options == null ? void 0 : options.aws);
108
116
  if (options == null ? void 0 : options.constants) {
109
117
  this.constants = options.constants || {};
110
118
  }
@@ -0,0 +1,16 @@
1
+ import { S3ClientConfig, PutObjectCommandInput } from '@aws-sdk/client-s3';
2
+ import App from '../app';
3
+ export interface AWSOptions extends S3ClientConfig {
4
+ s3Config: S3ClientConfig;
5
+ bucketName?: string;
6
+ }
7
+ export interface UploadParams extends PutObjectCommandInput {
8
+ }
9
+ declare class AWS {
10
+ private s3Client?;
11
+ private app;
12
+ private config?;
13
+ constructor(app: App, options?: AWSOptions);
14
+ upload(params: UploadParams): Promise<any>;
15
+ }
16
+ export default AWS;
@@ -0,0 +1,67 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/aws/index.ts
20
+ var aws_exports = {};
21
+ __export(aws_exports, {
22
+ default: () => aws_default
23
+ });
24
+ module.exports = __toCommonJS(aws_exports);
25
+ var import_client_s3 = require("@aws-sdk/client-s3");
26
+ var defaultUploadParams = {
27
+ Bucket: "",
28
+ Key: "",
29
+ ContentType: "application/json",
30
+ ContentDisposition: "inline",
31
+ ACL: "public-read"
32
+ // 设置ACL权限为公共读取
33
+ };
34
+ var AWS = class {
35
+ s3Client;
36
+ app;
37
+ config;
38
+ constructor(app, options) {
39
+ this.app = app;
40
+ if (options) {
41
+ const clientConfig = {
42
+ ...options.s3Config
43
+ };
44
+ this.s3Client = new import_client_s3.S3Client(clientConfig);
45
+ this.config = options;
46
+ }
47
+ }
48
+ async upload(params) {
49
+ var _a, _b;
50
+ try {
51
+ const _params = {
52
+ ...defaultUploadParams,
53
+ ...params,
54
+ Bucket: params.Bucket || ((_a = this.config) == null ? void 0 : _a.bucketName)
55
+ };
56
+ console.log(`上传参数`, _params);
57
+ const command = new import_client_s3.PutObjectCommand(_params);
58
+ const response = await ((_b = this.s3Client) == null ? void 0 : _b.send(command));
59
+ console.log(`上传成功`);
60
+ return response;
61
+ } catch (err) {
62
+ console.error(`上传失败`, err);
63
+ throw err;
64
+ }
65
+ }
66
+ };
67
+ var aws_default = AWS;
@@ -0,0 +1,11 @@
1
+ export declare enum CMDCoreEnum {
2
+ CMD_CONNECT,
3
+ CMD_DISCONNECT,
4
+ CMD_RECONNECT,
5
+ CMD_MESSAGE,
6
+ CMD_ERROR
7
+ }
8
+ declare const _default: {
9
+ CMDCoreEnum: typeof CMDCoreEnum;
10
+ };
11
+ export default _default;
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/cmd/const.ts
20
+ var const_exports = {};
21
+ __export(const_exports, {
22
+ CMDCoreEnum: () => CMDCoreEnum,
23
+ default: () => const_default
24
+ });
25
+ module.exports = __toCommonJS(const_exports);
26
+ var prefix = "cmd";
27
+ var CMDCoreEnum = ((CMDCoreEnum2) => {
28
+ CMDCoreEnum2["CMD_CONNECT"] = `${prefix}.connect`;
29
+ CMDCoreEnum2["CMD_DISCONNECT"] = `${prefix}.disconnect`;
30
+ CMDCoreEnum2["CMD_RECONNECT"] = `${prefix}.reconnect`;
31
+ CMDCoreEnum2["CMD_MESSAGE"] = `${prefix}.message`;
32
+ CMDCoreEnum2["CMD_ERROR"] = `${prefix}.error`;
33
+ return CMDCoreEnum2;
34
+ })(CMDCoreEnum || {});
35
+ var const_default = { CMDCoreEnum };
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ CMDCoreEnum
39
+ });
@@ -0,0 +1,13 @@
1
+ import App from "../app";
2
+ import { CMDCoreEnum } from "./const";
3
+ export interface CMDOptions {
4
+ socketUrl?: string;
5
+ }
6
+ declare class CMD {
7
+ private app;
8
+ private options?;
9
+ constructor(app: App, options?: CMDOptions);
10
+ init(): void;
11
+ }
12
+ export { CMDCoreEnum };
13
+ export default CMD;