@pisell/core 1.0.52 → 1.0.54

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.
@@ -308,18 +308,16 @@ var LoggerManager = /*#__PURE__*/function () {
308
308
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
309
309
  while (1) switch (_context4.prev = _context4.next) {
310
310
  case 0:
311
- // 每次上传日志时,检查下IndexDB是否有日志,如果有则上传到AWS
312
- this.uploadIndexDBLog();
313
311
  if (!(this.logBuffer.length === 0 || !this.db)) {
314
- _context4.next = 3;
312
+ _context4.next = 2;
315
313
  break;
316
314
  }
317
315
  return _context4.abrupt("return");
318
- case 3:
319
- _context4.prev = 3;
320
- _context4.next = 6;
316
+ case 2:
317
+ _context4.prev = 2;
318
+ _context4.next = 5;
321
319
  return this.createAWSFileName(urgent);
322
- case 6:
320
+ case 5:
323
321
  fileName = _context4.sent;
324
322
  console.log("-------- 存储日志到AWS 开始", fileName);
325
323
 
@@ -333,13 +331,13 @@ var LoggerManager = /*#__PURE__*/function () {
333
331
  return item.logId;
334
332
  });
335
333
  logs = JSON.stringify(buffer, null, 2);
336
- _context4.next = 13;
334
+ _context4.next = 12;
337
335
  return this.app.aws.upload({
338
336
  Bucket: "",
339
337
  Key: fileName,
340
338
  Body: logs
341
339
  });
342
- case 13:
340
+ case 12:
343
341
  this.addLog({
344
342
  type: "info",
345
343
  title: "存储日志到AWS 成功",
@@ -356,11 +354,11 @@ var LoggerManager = /*#__PURE__*/function () {
356
354
  this.logBuffer = this.logBuffer.filter(function (item) {
357
355
  return !bufferIds.includes(item.logId);
358
356
  });
359
- _context4.next = 31;
357
+ _context4.next = 30;
360
358
  break;
361
- case 18:
362
- _context4.prev = 18;
363
- _context4.t0 = _context4["catch"](3);
359
+ case 17:
360
+ _context4.prev = 17;
361
+ _context4.t0 = _context4["catch"](2);
364
362
  console.error("存储日志上传AWS失败:", _context4.t0);
365
363
  this.addLog({
366
364
  type: "info",
@@ -375,15 +373,15 @@ var LoggerManager = /*#__PURE__*/function () {
375
373
  });
376
374
 
377
375
  // 将日志存储到IndexDB
378
- _context4.prev = 22;
379
- _context4.next = 25;
376
+ _context4.prev = 21;
377
+ _context4.next = 24;
380
378
  return this.storeLogToIndexDB();
381
- case 25:
382
- _context4.next = 31;
379
+ case 24:
380
+ _context4.next = 30;
383
381
  break;
384
- case 27:
385
- _context4.prev = 27;
386
- _context4.t1 = _context4["catch"](22);
382
+ case 26:
383
+ _context4.prev = 26;
384
+ _context4.t1 = _context4["catch"](21);
387
385
  this.sendFeishuNotification({
388
386
  type: "error",
389
387
  title: "将日志存储到IndexDB失败",
@@ -396,11 +394,11 @@ var LoggerManager = /*#__PURE__*/function () {
396
394
  }
397
395
  });
398
396
  console.error("存储日志到IndexDB也失败:", _context4.t1);
399
- case 31:
397
+ case 30:
400
398
  case "end":
401
399
  return _context4.stop();
402
400
  }
403
- }, _callee4, this, [[3, 18], [22, 27]]);
401
+ }, _callee4, this, [[2, 17], [21, 26]]);
404
402
  }));
405
403
  function storeLog(_x2) {
406
404
  return _storeLog.apply(this, arguments);
@@ -416,46 +414,60 @@ var LoggerManager = /*#__PURE__*/function () {
416
414
  while (1) switch (_context5.prev = _context5.next) {
417
415
  case 0:
418
416
  _context5.prev = 0;
417
+ this.addLog({
418
+ type: "info",
419
+ title: "准备将IndexDB中的日志上传到AWS"
420
+ });
419
421
  if (this.db) {
420
- _context5.next = 3;
422
+ _context5.next = 4;
421
423
  break;
422
424
  }
423
425
  return _context5.abrupt("return");
424
- case 3:
425
- _context5.next = 5;
426
+ case 4:
427
+ _context5.next = 6;
426
428
  return (_this$db = this.db) === null || _this$db === void 0 ? void 0 : _this$db.getAll("logs");
427
- case 5:
429
+ case 6:
428
430
  logFile = _context5.sent;
429
431
  if (!(!logFile || (logFile === null || logFile === void 0 ? void 0 : logFile.length) === 0)) {
430
- _context5.next = 8;
432
+ _context5.next = 9;
431
433
  break;
432
434
  }
433
435
  return _context5.abrupt("return");
434
- case 8:
435
- _context5.next = 10;
436
+ case 9:
437
+ _context5.next = 11;
436
438
  return this.createAWSFileName(true);
437
- case 10:
439
+ case 11:
438
440
  awsFileName = _context5.sent;
439
441
  logs = JSON.stringify(logFile, null, 2);
440
- _context5.next = 14;
442
+ _context5.next = 15;
441
443
  return this.app.aws.upload({
442
444
  Bucket: "",
443
445
  Key: awsFileName,
444
446
  Body: logs
445
447
  });
446
- case 14:
448
+ case 15:
447
449
  console.log("-------- 存储日志到AWS 成功");
448
- _context5.next = 17;
450
+ _context5.next = 18;
449
451
  return (_this$db2 = this.db) === null || _this$db2 === void 0 ? void 0 : _this$db2.clear("logs");
450
- case 17:
452
+ case 18:
451
453
  console.log("-------- 清空IndexDB日志成功");
452
- _context5.next = 24;
454
+ _context5.next = 25;
453
455
  break;
454
- case 20:
455
- _context5.prev = 20;
456
+ case 21:
457
+ _context5.prev = 21;
456
458
  _context5.t0 = _context5["catch"](0);
457
459
  console.log("-------- 存储日志到IndexDB 失败", _context5.t0);
458
-
460
+ this.addLog({
461
+ type: "info",
462
+ title: "存储IndexDB日志到AWS失败",
463
+ metadata: {
464
+ error: {
465
+ name: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.name,
466
+ message: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message,
467
+ stack: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.stack
468
+ }
469
+ }
470
+ });
459
471
  // this.sendFeishuNotification({
460
472
  // type: "error",
461
473
  // title: "存储IndexDB日志到AWS失败",
@@ -468,12 +480,11 @@ var LoggerManager = /*#__PURE__*/function () {
468
480
  // },
469
481
  // });
470
482
  // 重新抛出错误,让外层 catch 能够捕获
471
- throw _context5.t0;
472
- case 24:
483
+ case 25:
473
484
  case "end":
474
485
  return _context5.stop();
475
486
  }
476
- }, _callee5, this, [[0, 20]]);
487
+ }, _callee5, this, [[0, 21]]);
477
488
  }));
478
489
  function uploadIndexDBLog() {
479
490
  return _uploadIndexDBLog.apply(this, arguments);
@@ -558,63 +569,95 @@ var LoggerManager = /*#__PURE__*/function () {
558
569
  return _context7.abrupt("return");
559
570
  case 2:
560
571
  _context7.prev = 2;
561
- _context7.next = 5;
572
+ this.addLog({
573
+ type: "info",
574
+ title: "准备清理旧日志,开始获取所有日志文件"
575
+ });
576
+
577
+ // 获取所有日志文件
578
+ _context7.next = 6;
562
579
  return this.getLogFiles();
563
- case 5:
580
+ case 6:
564
581
  logFiles = _context7.sent;
582
+ this.addLog({
583
+ type: "info",
584
+ title: "获取旧日志成功",
585
+ metadata: {
586
+ logFilesCount: logFiles === null || logFiles === void 0 ? void 0 : logFiles.length
587
+ }
588
+ });
589
+
565
590
  // 计算保留日志的截止日期
566
591
  cutoffDate = dayjs().subtract(this.retentionDays, "day").format("YYYY-MM-DD"); // 筛选出需要删除的日志文件
567
- filesToDelete = logFiles.filter(function (file) {
592
+ filesToDelete = (logFiles || []).filter(function (file) {
568
593
  return file.date < cutoffDate;
569
594
  });
570
595
  console.log("-------- \u6E05\u7406\u65E7\u65E5\u5FD7\uFF0C\u4FDD\u7559 ".concat(this.retentionDays, " \u5929\u5185\u7684\u65E5\u5FD7\uFF0C\u622A\u6B62\u65E5\u671F: ").concat(cutoffDate));
571
596
 
572
597
  // 删除旧日志文件
573
598
  _iterator = _createForOfIteratorHelper(filesToDelete);
574
- _context7.prev = 10;
599
+ _context7.prev = 12;
575
600
  _iterator.s();
576
- case 12:
601
+ case 14:
577
602
  if ((_step = _iterator.n()).done) {
578
- _context7.next = 19;
603
+ _context7.next = 21;
579
604
  break;
580
605
  }
581
606
  file = _step.value;
582
- _context7.next = 16;
607
+ _context7.next = 18;
583
608
  return this.db.delete("logs", file.fileName);
584
- case 16:
609
+ case 18:
585
610
  console.log("-------- \u5220\u9664\u65E7\u65E5\u5FD7\u6587\u4EF6: ".concat(file.fileName, ", \u65E5\u671F: ").concat(file.date));
586
- case 17:
587
- _context7.next = 12;
588
- break;
589
611
  case 19:
590
- _context7.next = 24;
612
+ _context7.next = 14;
591
613
  break;
592
614
  case 21:
593
- _context7.prev = 21;
594
- _context7.t0 = _context7["catch"](10);
615
+ _context7.next = 26;
616
+ break;
617
+ case 23:
618
+ _context7.prev = 23;
619
+ _context7.t0 = _context7["catch"](12);
595
620
  _iterator.e(_context7.t0);
596
- case 24:
597
- _context7.prev = 24;
621
+ case 26:
622
+ _context7.prev = 26;
598
623
  _iterator.f();
599
- return _context7.finish(24);
600
- case 27:
624
+ return _context7.finish(26);
625
+ case 29:
601
626
  if (filesToDelete.length > 0) {
602
627
  console.log("-------- \u5171\u6E05\u7406 ".concat(filesToDelete.length, " \u4E2A\u65E7\u65E5\u5FD7\u6587\u4EF6"));
603
628
  }
629
+ this.addLog({
630
+ type: "info",
631
+ title: "清理旧日志成功",
632
+ metadata: {
633
+ filesToDelete: filesToDelete
634
+ }
635
+ });
604
636
 
605
637
  // 清理完成后,将IndexDB中的日志上传到AWS
606
638
  this.uploadIndexDBLog();
607
- _context7.next = 34;
639
+ _context7.next = 38;
608
640
  break;
609
- case 31:
610
- _context7.prev = 31;
641
+ case 34:
642
+ _context7.prev = 34;
611
643
  _context7.t1 = _context7["catch"](2);
644
+ this.addLog({
645
+ type: "error",
646
+ title: "清理旧日志失败!",
647
+ metadata: {
648
+ error: {
649
+ name: _context7.t1 === null || _context7.t1 === void 0 ? void 0 : _context7.t1.name,
650
+ message: _context7.t1 === null || _context7.t1 === void 0 ? void 0 : _context7.t1.message,
651
+ stack: _context7.t1 === null || _context7.t1 === void 0 ? void 0 : _context7.t1.stack
652
+ }
653
+ }
654
+ });
612
655
  console.error("清理旧日志失败:", _context7.t1);
613
- case 34:
656
+ case 38:
614
657
  case "end":
615
658
  return _context7.stop();
616
659
  }
617
- }, _callee7, this, [[2, 31], [10, 21, 24, 27]]);
660
+ }, _callee7, this, [[2, 34], [12, 23, 26, 29]]);
618
661
  }));
619
662
  function cleanupOldLogs() {
620
663
  return _cleanupOldLogs.apply(this, arguments);
@@ -647,9 +690,13 @@ var LoggerManager = /*#__PURE__*/function () {
647
690
  case 8:
648
691
  _context8.prev = 8;
649
692
  _context8.t0 = _context8["catch"](2);
693
+ this.addLog({
694
+ type: "error",
695
+ title: "获取本地日志文件列表失败"
696
+ });
650
697
  console.error("获取日志文件列表失败:", _context8.t0);
651
698
  return _context8.abrupt("return", []);
652
- case 12:
699
+ case 13:
653
700
  case "end":
654
701
  return _context8.stop();
655
702
  }
@@ -776,9 +823,13 @@ var LoggerManager = /*#__PURE__*/function () {
776
823
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
777
824
  while (1) switch (_context11.prev = _context11.next) {
778
825
  case 0:
779
- _context11.next = 2;
826
+ this.addLog({
827
+ type: "info",
828
+ title: "manualCleanup 手动触发清理旧日志"
829
+ });
830
+ _context11.next = 3;
780
831
  return this.cleanupOldLogs();
781
- case 2:
832
+ case 3:
782
833
  case "end":
783
834
  return _context11.stop();
784
835
  }
@@ -295,12 +295,14 @@ var getIsCache = function getIsCache(config) {
295
295
 
296
296
  // 优先使用云端, 没网使用本地
297
297
  if (cache.mode === RequestModeENUM.REMOTE_LOCAL) {
298
- var _getApp;
299
- // 判断是否有网络, 有网络就使用接口
300
- if ((_getApp = getApp()) !== null && _getApp !== void 0 && (_getApp = _getApp.getPlugin("network")) !== null && _getApp !== void 0 && _getApp.connected) {
301
- return false;
302
- }
303
- return true;
298
+ // 暂时关闭远程本地缓存
299
+ return false;
300
+ // // 判断是否有网络, 有网络就使用接口
301
+ // if (getApp()?.getPlugin("network")?.connected) {
302
+ // return false;
303
+ // }
304
+
305
+ // return true;
304
306
  }
305
307
  return true;
306
308
  };
@@ -211,7 +211,6 @@ var LoggerManager = class {
211
211
  */
212
212
  async storeLog(urgent) {
213
213
  var _a;
214
- this.uploadIndexDBLog();
215
214
  if (this.logBuffer.length === 0 || !this.db) {
216
215
  return;
217
216
  }
@@ -272,6 +271,10 @@ var LoggerManager = class {
272
271
  async uploadIndexDBLog() {
273
272
  var _a, _b;
274
273
  try {
274
+ this.addLog({
275
+ type: "info",
276
+ title: "准备将IndexDB中的日志上传到AWS"
277
+ });
275
278
  if (!this.db) {
276
279
  return;
277
280
  }
@@ -287,7 +290,17 @@ var LoggerManager = class {
287
290
  console.log("-------- 清空IndexDB日志成功");
288
291
  } catch (error) {
289
292
  console.log("-------- 存储日志到IndexDB 失败", error);
290
- throw error;
293
+ this.addLog({
294
+ type: "info",
295
+ title: "存储IndexDB日志到AWS失败",
296
+ metadata: {
297
+ error: {
298
+ name: error == null ? void 0 : error.name,
299
+ message: error == null ? void 0 : error.message,
300
+ stack: error == null ? void 0 : error.stack
301
+ }
302
+ }
303
+ });
291
304
  }
292
305
  }
293
306
  async storeLogToIndexDB() {
@@ -319,9 +332,20 @@ var LoggerManager = class {
319
332
  return;
320
333
  }
321
334
  try {
335
+ this.addLog({
336
+ type: "info",
337
+ title: "准备清理旧日志,开始获取所有日志文件"
338
+ });
322
339
  const logFiles = await this.getLogFiles();
340
+ this.addLog({
341
+ type: "info",
342
+ title: "获取旧日志成功",
343
+ metadata: {
344
+ logFilesCount: logFiles == null ? void 0 : logFiles.length
345
+ }
346
+ });
323
347
  const cutoffDate = (0, import_dayjs.default)().subtract(this.retentionDays, "day").format("YYYY-MM-DD");
324
- const filesToDelete = logFiles.filter((file) => file.date < cutoffDate);
348
+ const filesToDelete = (logFiles || []).filter((file) => file.date < cutoffDate);
325
349
  console.log(`-------- 清理旧日志,保留 ${this.retentionDays} 天内的日志,截止日期: ${cutoffDate}`);
326
350
  for (const file of filesToDelete) {
327
351
  await this.db.delete("logs", file.fileName);
@@ -330,8 +354,26 @@ var LoggerManager = class {
330
354
  if (filesToDelete.length > 0) {
331
355
  console.log(`-------- 共清理 ${filesToDelete.length} 个旧日志文件`);
332
356
  }
357
+ this.addLog({
358
+ type: "info",
359
+ title: "清理旧日志成功",
360
+ metadata: {
361
+ filesToDelete
362
+ }
363
+ });
333
364
  this.uploadIndexDBLog();
334
365
  } catch (error) {
366
+ this.addLog({
367
+ type: "error",
368
+ title: "清理旧日志失败!",
369
+ metadata: {
370
+ error: {
371
+ name: error == null ? void 0 : error.name,
372
+ message: error == null ? void 0 : error.message,
373
+ stack: error == null ? void 0 : error.stack
374
+ }
375
+ }
376
+ });
335
377
  console.error("清理旧日志失败:", error);
336
378
  }
337
379
  }
@@ -346,6 +388,10 @@ var LoggerManager = class {
346
388
  try {
347
389
  return await this.db.getAll("logs");
348
390
  } catch (error) {
391
+ this.addLog({
392
+ type: "error",
393
+ title: "获取本地日志文件列表失败"
394
+ });
349
395
  console.error("获取日志文件列表失败:", error);
350
396
  return [];
351
397
  }
@@ -403,6 +449,10 @@ var LoggerManager = class {
403
449
  * 手动触发清理旧日志
404
450
  */
405
451
  async manualCleanup() {
452
+ this.addLog({
453
+ type: "info",
454
+ title: "manualCleanup 手动触发清理旧日志"
455
+ });
406
456
  await this.cleanupOldLogs();
407
457
  }
408
458
  /**
@@ -135,7 +135,6 @@ var setCacheData = (url, data, res, cache = {
135
135
  setCache(_key, res, cache);
136
136
  };
137
137
  var getIsCache = (config) => {
138
- var _a, _b;
139
138
  if (!(config == null ? void 0 : config.cache) && !(config == null ? void 0 : config.useCache)) {
140
139
  return false;
141
140
  }
@@ -150,10 +149,7 @@ var getIsCache = (config) => {
150
149
  return true;
151
150
  }
152
151
  if (cache.mode === import_type.RequestModeENUM.REMOTE_LOCAL) {
153
- if ((_b = (_a = (0, import_app.getApp)()) == null ? void 0 : _a.getPlugin("network")) == null ? void 0 : _b.connected) {
154
- return false;
155
- }
156
- return true;
152
+ return false;
157
153
  }
158
154
  return true;
159
155
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/core",
3
- "version": "1.0.52",
3
+ "version": "1.0.54",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",