@pisell/core 1.0.52 → 1.0.53

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.
@@ -416,46 +416,60 @@ var LoggerManager = /*#__PURE__*/function () {
416
416
  while (1) switch (_context5.prev = _context5.next) {
417
417
  case 0:
418
418
  _context5.prev = 0;
419
+ this.addLog({
420
+ type: "info",
421
+ title: "准备将IndexDB中的日志上传到AWS"
422
+ });
419
423
  if (this.db) {
420
- _context5.next = 3;
424
+ _context5.next = 4;
421
425
  break;
422
426
  }
423
427
  return _context5.abrupt("return");
424
- case 3:
425
- _context5.next = 5;
428
+ case 4:
429
+ _context5.next = 6;
426
430
  return (_this$db = this.db) === null || _this$db === void 0 ? void 0 : _this$db.getAll("logs");
427
- case 5:
431
+ case 6:
428
432
  logFile = _context5.sent;
429
433
  if (!(!logFile || (logFile === null || logFile === void 0 ? void 0 : logFile.length) === 0)) {
430
- _context5.next = 8;
434
+ _context5.next = 9;
431
435
  break;
432
436
  }
433
437
  return _context5.abrupt("return");
434
- case 8:
435
- _context5.next = 10;
438
+ case 9:
439
+ _context5.next = 11;
436
440
  return this.createAWSFileName(true);
437
- case 10:
441
+ case 11:
438
442
  awsFileName = _context5.sent;
439
443
  logs = JSON.stringify(logFile, null, 2);
440
- _context5.next = 14;
444
+ _context5.next = 15;
441
445
  return this.app.aws.upload({
442
446
  Bucket: "",
443
447
  Key: awsFileName,
444
448
  Body: logs
445
449
  });
446
- case 14:
450
+ case 15:
447
451
  console.log("-------- 存储日志到AWS 成功");
448
- _context5.next = 17;
452
+ _context5.next = 18;
449
453
  return (_this$db2 = this.db) === null || _this$db2 === void 0 ? void 0 : _this$db2.clear("logs");
450
- case 17:
454
+ case 18:
451
455
  console.log("-------- 清空IndexDB日志成功");
452
- _context5.next = 24;
456
+ _context5.next = 26;
453
457
  break;
454
- case 20:
455
- _context5.prev = 20;
458
+ case 21:
459
+ _context5.prev = 21;
456
460
  _context5.t0 = _context5["catch"](0);
457
461
  console.log("-------- 存储日志到IndexDB 失败", _context5.t0);
458
-
462
+ this.addLog({
463
+ type: "info",
464
+ title: "存储IndexDB日志到AWS失败",
465
+ metadata: {
466
+ error: {
467
+ name: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.name,
468
+ message: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message,
469
+ stack: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.stack
470
+ }
471
+ }
472
+ });
459
473
  // this.sendFeishuNotification({
460
474
  // type: "error",
461
475
  // title: "存储IndexDB日志到AWS失败",
@@ -469,11 +483,11 @@ var LoggerManager = /*#__PURE__*/function () {
469
483
  // });
470
484
  // 重新抛出错误,让外层 catch 能够捕获
471
485
  throw _context5.t0;
472
- case 24:
486
+ case 26:
473
487
  case "end":
474
488
  return _context5.stop();
475
489
  }
476
- }, _callee5, this, [[0, 20]]);
490
+ }, _callee5, this, [[0, 21]]);
477
491
  }));
478
492
  function uploadIndexDBLog() {
479
493
  return _uploadIndexDBLog.apply(this, arguments);
@@ -558,63 +572,95 @@ var LoggerManager = /*#__PURE__*/function () {
558
572
  return _context7.abrupt("return");
559
573
  case 2:
560
574
  _context7.prev = 2;
561
- _context7.next = 5;
575
+ this.addLog({
576
+ type: "info",
577
+ title: "准备清理旧日志,开始获取所有日志文件"
578
+ });
579
+
580
+ // 获取所有日志文件
581
+ _context7.next = 6;
562
582
  return this.getLogFiles();
563
- case 5:
583
+ case 6:
564
584
  logFiles = _context7.sent;
585
+ this.addLog({
586
+ type: "info",
587
+ title: "获取旧日志成功",
588
+ metadata: {
589
+ logFilesCount: logFiles === null || logFiles === void 0 ? void 0 : logFiles.length
590
+ }
591
+ });
592
+
565
593
  // 计算保留日志的截止日期
566
594
  cutoffDate = dayjs().subtract(this.retentionDays, "day").format("YYYY-MM-DD"); // 筛选出需要删除的日志文件
567
- filesToDelete = logFiles.filter(function (file) {
595
+ filesToDelete = (logFiles || []).filter(function (file) {
568
596
  return file.date < cutoffDate;
569
597
  });
570
598
  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
599
 
572
600
  // 删除旧日志文件
573
601
  _iterator = _createForOfIteratorHelper(filesToDelete);
574
- _context7.prev = 10;
602
+ _context7.prev = 12;
575
603
  _iterator.s();
576
- case 12:
604
+ case 14:
577
605
  if ((_step = _iterator.n()).done) {
578
- _context7.next = 19;
606
+ _context7.next = 21;
579
607
  break;
580
608
  }
581
609
  file = _step.value;
582
- _context7.next = 16;
610
+ _context7.next = 18;
583
611
  return this.db.delete("logs", file.fileName);
584
- case 16:
612
+ case 18:
585
613
  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
614
  case 19:
590
- _context7.next = 24;
615
+ _context7.next = 14;
591
616
  break;
592
617
  case 21:
593
- _context7.prev = 21;
594
- _context7.t0 = _context7["catch"](10);
618
+ _context7.next = 26;
619
+ break;
620
+ case 23:
621
+ _context7.prev = 23;
622
+ _context7.t0 = _context7["catch"](12);
595
623
  _iterator.e(_context7.t0);
596
- case 24:
597
- _context7.prev = 24;
624
+ case 26:
625
+ _context7.prev = 26;
598
626
  _iterator.f();
599
- return _context7.finish(24);
600
- case 27:
627
+ return _context7.finish(26);
628
+ case 29:
601
629
  if (filesToDelete.length > 0) {
602
630
  console.log("-------- \u5171\u6E05\u7406 ".concat(filesToDelete.length, " \u4E2A\u65E7\u65E5\u5FD7\u6587\u4EF6"));
603
631
  }
632
+ this.addLog({
633
+ type: "info",
634
+ title: "清理旧日志成功",
635
+ metadata: {
636
+ filesToDelete: filesToDelete
637
+ }
638
+ });
604
639
 
605
640
  // 清理完成后,将IndexDB中的日志上传到AWS
606
641
  this.uploadIndexDBLog();
607
- _context7.next = 34;
642
+ _context7.next = 38;
608
643
  break;
609
- case 31:
610
- _context7.prev = 31;
644
+ case 34:
645
+ _context7.prev = 34;
611
646
  _context7.t1 = _context7["catch"](2);
647
+ this.addLog({
648
+ type: "error",
649
+ title: "清理旧日志失败!",
650
+ metadata: {
651
+ error: {
652
+ name: _context7.t1 === null || _context7.t1 === void 0 ? void 0 : _context7.t1.name,
653
+ message: _context7.t1 === null || _context7.t1 === void 0 ? void 0 : _context7.t1.message,
654
+ stack: _context7.t1 === null || _context7.t1 === void 0 ? void 0 : _context7.t1.stack
655
+ }
656
+ }
657
+ });
612
658
  console.error("清理旧日志失败:", _context7.t1);
613
- case 34:
659
+ case 38:
614
660
  case "end":
615
661
  return _context7.stop();
616
662
  }
617
- }, _callee7, this, [[2, 31], [10, 21, 24, 27]]);
663
+ }, _callee7, this, [[2, 34], [12, 23, 26, 29]]);
618
664
  }));
619
665
  function cleanupOldLogs() {
620
666
  return _cleanupOldLogs.apply(this, arguments);
@@ -647,9 +693,13 @@ var LoggerManager = /*#__PURE__*/function () {
647
693
  case 8:
648
694
  _context8.prev = 8;
649
695
  _context8.t0 = _context8["catch"](2);
696
+ this.addLog({
697
+ type: "error",
698
+ title: "获取本地日志文件列表失败"
699
+ });
650
700
  console.error("获取日志文件列表失败:", _context8.t0);
651
701
  return _context8.abrupt("return", []);
652
- case 12:
702
+ case 13:
653
703
  case "end":
654
704
  return _context8.stop();
655
705
  }
@@ -776,9 +826,13 @@ var LoggerManager = /*#__PURE__*/function () {
776
826
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
777
827
  while (1) switch (_context11.prev = _context11.next) {
778
828
  case 0:
779
- _context11.next = 2;
829
+ this.addLog({
830
+ type: "info",
831
+ title: "manualCleanup 手动触发清理旧日志"
832
+ });
833
+ _context11.next = 3;
780
834
  return this.cleanupOldLogs();
781
- case 2:
835
+ case 3:
782
836
  case "end":
783
837
  return _context11.stop();
784
838
  }
@@ -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
  };
@@ -272,6 +272,10 @@ var LoggerManager = class {
272
272
  async uploadIndexDBLog() {
273
273
  var _a, _b;
274
274
  try {
275
+ this.addLog({
276
+ type: "info",
277
+ title: "准备将IndexDB中的日志上传到AWS"
278
+ });
275
279
  if (!this.db) {
276
280
  return;
277
281
  }
@@ -287,6 +291,17 @@ var LoggerManager = class {
287
291
  console.log("-------- 清空IndexDB日志成功");
288
292
  } catch (error) {
289
293
  console.log("-------- 存储日志到IndexDB 失败", error);
294
+ this.addLog({
295
+ type: "info",
296
+ title: "存储IndexDB日志到AWS失败",
297
+ metadata: {
298
+ error: {
299
+ name: error == null ? void 0 : error.name,
300
+ message: error == null ? void 0 : error.message,
301
+ stack: error == null ? void 0 : error.stack
302
+ }
303
+ }
304
+ });
290
305
  throw error;
291
306
  }
292
307
  }
@@ -319,9 +334,20 @@ var LoggerManager = class {
319
334
  return;
320
335
  }
321
336
  try {
337
+ this.addLog({
338
+ type: "info",
339
+ title: "准备清理旧日志,开始获取所有日志文件"
340
+ });
322
341
  const logFiles = await this.getLogFiles();
342
+ this.addLog({
343
+ type: "info",
344
+ title: "获取旧日志成功",
345
+ metadata: {
346
+ logFilesCount: logFiles == null ? void 0 : logFiles.length
347
+ }
348
+ });
323
349
  const cutoffDate = (0, import_dayjs.default)().subtract(this.retentionDays, "day").format("YYYY-MM-DD");
324
- const filesToDelete = logFiles.filter((file) => file.date < cutoffDate);
350
+ const filesToDelete = (logFiles || []).filter((file) => file.date < cutoffDate);
325
351
  console.log(`-------- 清理旧日志,保留 ${this.retentionDays} 天内的日志,截止日期: ${cutoffDate}`);
326
352
  for (const file of filesToDelete) {
327
353
  await this.db.delete("logs", file.fileName);
@@ -330,8 +356,26 @@ var LoggerManager = class {
330
356
  if (filesToDelete.length > 0) {
331
357
  console.log(`-------- 共清理 ${filesToDelete.length} 个旧日志文件`);
332
358
  }
359
+ this.addLog({
360
+ type: "info",
361
+ title: "清理旧日志成功",
362
+ metadata: {
363
+ filesToDelete
364
+ }
365
+ });
333
366
  this.uploadIndexDBLog();
334
367
  } catch (error) {
368
+ this.addLog({
369
+ type: "error",
370
+ title: "清理旧日志失败!",
371
+ metadata: {
372
+ error: {
373
+ name: error == null ? void 0 : error.name,
374
+ message: error == null ? void 0 : error.message,
375
+ stack: error == null ? void 0 : error.stack
376
+ }
377
+ }
378
+ });
335
379
  console.error("清理旧日志失败:", error);
336
380
  }
337
381
  }
@@ -346,6 +390,10 @@ var LoggerManager = class {
346
390
  try {
347
391
  return await this.db.getAll("logs");
348
392
  } catch (error) {
393
+ this.addLog({
394
+ type: "error",
395
+ title: "获取本地日志文件列表失败"
396
+ });
349
397
  console.error("获取日志文件列表失败:", error);
350
398
  return [];
351
399
  }
@@ -403,6 +451,10 @@ var LoggerManager = class {
403
451
  * 手动触发清理旧日志
404
452
  */
405
453
  async manualCleanup() {
454
+ this.addLog({
455
+ type: "info",
456
+ title: "manualCleanup 手动触发清理旧日志"
457
+ });
406
458
  await this.cleanupOldLogs();
407
459
  }
408
460
  /**
@@ -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.53",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",