@anyul/koishi-plugin-rss 5.3.2 → 5.3.10

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.
Files changed (59) hide show
  1. package/lib/commands/index.js +1 -3
  2. package/lib/commands/subscription-create.d.ts +2 -0
  3. package/lib/commands/subscription-create.js +2 -2
  4. package/lib/commands/subscription-edit.d.ts +2 -0
  5. package/lib/commands/subscription-edit.js +8 -12
  6. package/lib/commands/subscription-management.d.ts +2 -0
  7. package/lib/commands/subscription-management.js +10 -12
  8. package/lib/commands/utils.d.ts +0 -5
  9. package/lib/commands/utils.js +0 -16
  10. package/lib/commands/web-monitor.d.ts +2 -0
  11. package/lib/commands/web-monitor.js +2 -2
  12. package/lib/config.js +4 -10
  13. package/lib/core/feeder-arg.js +3 -38
  14. package/lib/core/feeder-runtime.js +0 -5
  15. package/lib/core/feeder.js +53 -12
  16. package/lib/core/item-processor-runtime.d.ts +4 -2
  17. package/lib/core/item-processor-runtime.js +4 -12
  18. package/lib/core/notification-queue-sender.js +0 -5
  19. package/lib/core/notification-queue-store.d.ts +7 -0
  20. package/lib/core/notification-queue-store.js +28 -6
  21. package/lib/core/notification-queue.d.ts +10 -0
  22. package/lib/core/notification-queue.js +18 -7
  23. package/lib/core/parser.js +5 -5
  24. package/lib/core/renderer.js +7 -7
  25. package/lib/core/search-format.d.ts +1 -1
  26. package/lib/core/search-format.js +1 -1
  27. package/lib/core/subscription-store.d.ts +44 -0
  28. package/lib/core/subscription-store.js +60 -0
  29. package/lib/core/telegram-video-restore.js +3 -8
  30. package/lib/index.d.ts +1 -4
  31. package/lib/index.js +20 -15
  32. package/lib/tsconfig.tsbuildinfo +1 -1
  33. package/lib/types.d.ts +51 -32
  34. package/lib/utils/common.d.ts +6 -0
  35. package/lib/utils/common.js +20 -30
  36. package/lib/utils/error-handler.d.ts +49 -0
  37. package/lib/utils/error-handler.js +111 -1
  38. package/lib/utils/fetcher.js +12 -38
  39. package/lib/utils/legacy-config.js +9 -3
  40. package/lib/utils/logger.d.ts +6 -0
  41. package/lib/utils/logger.js +82 -14
  42. package/lib/utils/media.js +21 -21
  43. package/lib/utils/message-cache.d.ts +8 -0
  44. package/lib/utils/message-cache.js +12 -0
  45. package/lib/utils/proxy.d.ts +37 -0
  46. package/lib/utils/proxy.js +60 -0
  47. package/package.json +16 -3
  48. package/lib/commands/error-handler.d.ts +0 -53
  49. package/lib/commands/error-handler.js +0 -120
  50. package/lib/commands/rss-subscribe.d.ts +0 -11
  51. package/lib/commands/rss-subscribe.js +0 -323
  52. package/lib/core/feeder-old.d.ts +0 -15
  53. package/lib/core/feeder-old.js +0 -403
  54. package/lib/utils/error-tracker.d.ts +0 -127
  55. package/lib/utils/error-tracker.js +0 -352
  56. package/lib/utils/metrics.d.ts +0 -184
  57. package/lib/utils/metrics.js +0 -401
  58. package/lib/utils/structured-logger.d.ts +0 -135
  59. package/lib/utils/structured-logger.js +0 -248
@@ -1,352 +0,0 @@
1
- "use strict";
2
- /**
3
- * 错误追踪系统
4
- * 集成 Sentry 进行错误监控和报告
5
- *
6
- * 注意:需要安装 @sentry/node 才能使用此功能
7
- * npm install @sentry/node
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.ErrorTracker = void 0;
11
- exports.initErrorTracker = initErrorTracker;
12
- exports.getErrorTracker = getErrorTracker;
13
- exports.trackError = trackError;
14
- exports.trackMessage = trackMessage;
15
- exports.addBreadcrumb = addBreadcrumb;
16
- exports.setTag = setTag;
17
- exports.setContext = setContext;
18
- exports.setUser = setUser;
19
- exports.TracePerformance = TracePerformance;
20
- exports.wrapAsyncFunction = wrapAsyncFunction;
21
- exports.withErrorTracking = withErrorTracking;
22
- const error_handler_1 = require("./error-handler");
23
- const logger_1 = require("./logger");
24
- // 动态导入 Sentry,避免未安装时编译失败
25
- let Sentry = null;
26
- let sentryDependencyWarningShown = false;
27
- try {
28
- // eslint-disable-next-line @typescript-eslint/no-var-requires
29
- Sentry = require('@sentry/node');
30
- }
31
- catch {
32
- Sentry = null;
33
- }
34
- function warnMissingSentryDependency() {
35
- if (sentryDependencyWarningShown)
36
- return;
37
- sentryDependencyWarningShown = true;
38
- logger_1.logger.warn('[error-tracker] Sentry not installed. Error tracking will be disabled.');
39
- logger_1.logger.warn('[error-tracker] To enable error tracking, install: npm install @sentry/node');
40
- }
41
- function logSentryInitError(error) {
42
- const errorMessage = error instanceof Error ? error.message : String(error);
43
- logger_1.logger.error(`[error-tracker] Failed to initialize Sentry: ${errorMessage}`);
44
- }
45
- /**
46
- * 错误追踪器类
47
- */
48
- class ErrorTracker {
49
- config;
50
- initialized = false;
51
- constructor(config) {
52
- this.config = config;
53
- }
54
- /**
55
- * 初始化 Sentry
56
- */
57
- init() {
58
- if (!this.config.enabled || !this.config.dsn) {
59
- return;
60
- }
61
- if (!Sentry) {
62
- warnMissingSentryDependency();
63
- return;
64
- }
65
- try {
66
- Sentry.init({
67
- dsn: this.config.dsn,
68
- environment: this.config.environment || 'production',
69
- release: this.config.release || '5.0.0-beta',
70
- tracesSampleRate: this.config.tracesSampleRate || 0.1,
71
- profilesSampleRate: this.config.profilesSampleRate || 0.1,
72
- // 集成之前已有的错误处理器
73
- beforeSend(event, hint) {
74
- // 可以在这里修改或过滤事件
75
- return event;
76
- },
77
- // 集成性能监控
78
- integrations: [
79
- // 添加默认集成
80
- ...(Sentry.defaultIntegrations || []),
81
- ],
82
- // 设置面包屑
83
- beforeBreadcrumb(breadcrumb, hint) {
84
- // 可以在这里过滤或修改面包屑
85
- return breadcrumb;
86
- }
87
- });
88
- this.initialized = true;
89
- }
90
- catch (error) {
91
- logSentryInitError(error);
92
- }
93
- }
94
- /**
95
- * 捕获异常
96
- */
97
- captureException(error, context) {
98
- if (!this.initialized || !Sentry) {
99
- return;
100
- }
101
- Sentry.withScope((scope) => {
102
- // 添加上下文
103
- if (context) {
104
- scope.setContext('custom_context', context);
105
- scope.setUser({
106
- id: context.userId,
107
- platform: context.platform
108
- });
109
- scope.setTag('guild_id', context.guildId);
110
- scope.setTag('rss_id', context.rssId);
111
- scope.setTag('url', context.url);
112
- scope.setTag('command', context.command);
113
- }
114
- // 发送错误
115
- Sentry.captureException(error);
116
- });
117
- }
118
- /**
119
- * 捕获消息
120
- */
121
- captureMessage(message, level = 'info', context) {
122
- if (!this.initialized || !Sentry) {
123
- return;
124
- }
125
- Sentry.withScope((scope) => {
126
- // 添加上下文
127
- if (context) {
128
- scope.setContext('custom_context', context);
129
- scope.setUser({
130
- id: context.userId,
131
- platform: context.platform
132
- });
133
- scope.setTag('guild_id', context.guildId);
134
- scope.setTag('rss_id', context.rssId);
135
- scope.setTag('url', context.url);
136
- scope.setTag('command', context.command);
137
- }
138
- // 发送消息
139
- Sentry.captureMessage(message, level);
140
- });
141
- }
142
- /**
143
- * 添加面包屑
144
- */
145
- addBreadcrumb(message, category = 'custom', level = 'info', data) {
146
- if (!this.initialized || !Sentry) {
147
- return;
148
- }
149
- Sentry.addBreadcrumb({
150
- message,
151
- category,
152
- level,
153
- data
154
- });
155
- }
156
- /**
157
- * 设置用户
158
- */
159
- setUser(user) {
160
- if (!this.initialized || !Sentry) {
161
- return;
162
- }
163
- Sentry.setUser(user);
164
- }
165
- /**
166
- * 设置标签
167
- */
168
- setTag(key, value) {
169
- if (!this.initialized || !Sentry) {
170
- return;
171
- }
172
- Sentry.setTag(key, value);
173
- }
174
- /**
175
- * 设置上下文
176
- */
177
- setContext(key, context) {
178
- if (!this.initialized || !Sentry) {
179
- return;
180
- }
181
- Sentry.setContext(key, context);
182
- }
183
- /**
184
- * 开始性能追踪
185
- */
186
- startTransaction(name, op) {
187
- if (!this.initialized || !Sentry) {
188
- return undefined;
189
- }
190
- return Sentry.startInactiveSpan({
191
- name,
192
- op
193
- });
194
- }
195
- /**
196
- * 检查是否已初始化
197
- */
198
- isInitialized() {
199
- return this.initialized;
200
- }
201
- }
202
- exports.ErrorTracker = ErrorTracker;
203
- // 全局错误追踪器实例
204
- let globalErrorTracker = null;
205
- /**
206
- * 初始化全局错误追踪器
207
- */
208
- function initErrorTracker(config) {
209
- if (!globalErrorTracker || !globalErrorTracker.isInitialized()) {
210
- globalErrorTracker = new ErrorTracker(config);
211
- globalErrorTracker.init();
212
- }
213
- return globalErrorTracker;
214
- }
215
- /**
216
- * 获取全局错误追踪器
217
- */
218
- function getErrorTracker() {
219
- return globalErrorTracker;
220
- }
221
- /**
222
- * 便捷方法:捕获异常
223
- */
224
- function trackError(error, context) {
225
- if (globalErrorTracker) {
226
- globalErrorTracker.captureException(error, context);
227
- }
228
- }
229
- /**
230
- * 便捷方法:捕获消息
231
- */
232
- function trackMessage(message, level, context) {
233
- if (globalErrorTracker) {
234
- globalErrorTracker.captureMessage(message, level, context);
235
- }
236
- }
237
- /**
238
- * 便捷方法:添加面包屑
239
- */
240
- function addBreadcrumb(message, category, level, data) {
241
- if (globalErrorTracker) {
242
- globalErrorTracker.addBreadcrumb(message, category, level, data);
243
- }
244
- }
245
- /**
246
- * 便捷方法:设置标签
247
- */
248
- function setTag(key, value) {
249
- if (globalErrorTracker) {
250
- globalErrorTracker.setTag(key, value);
251
- }
252
- }
253
- /**
254
- * 便捷方法:设置上下文
255
- */
256
- function setContext(key, context) {
257
- if (globalErrorTracker) {
258
- globalErrorTracker.setContext(key, context);
259
- }
260
- }
261
- /**
262
- * 便捷方法:设置用户
263
- */
264
- function setUser(user) {
265
- if (globalErrorTracker) {
266
- globalErrorTracker.setUser(user);
267
- }
268
- }
269
- /**
270
- * 性能追踪装饰器
271
- */
272
- function TracePerformance(name, op) {
273
- return function (target, propertyKey, descriptor) {
274
- const originalMethod = descriptor.value;
275
- descriptor.value = async function (...args) {
276
- const transactionName = name || `${target.constructor.name}.${propertyKey}`;
277
- const transactionOp = op || 'function';
278
- let span;
279
- if (globalErrorTracker && globalErrorTracker.isInitialized()) {
280
- span = globalErrorTracker.startTransaction(transactionName, transactionOp);
281
- }
282
- try {
283
- const result = await originalMethod.apply(this, args);
284
- if (span) {
285
- span.end();
286
- }
287
- return result;
288
- }
289
- catch (error) {
290
- if (span) {
291
- span.setStatus({
292
- code: 2, // Internal error
293
- message: error instanceof Error ? error.message : 'Unknown error'
294
- });
295
- span.end();
296
- }
297
- throw error;
298
- }
299
- };
300
- return descriptor;
301
- };
302
- }
303
- /**
304
- * 包装异步函数以追踪性能
305
- */
306
- function wrapAsyncFunction(fn, name, op = 'function') {
307
- return (async (...args) => {
308
- let span;
309
- if (globalErrorTracker && globalErrorTracker.isInitialized()) {
310
- span = globalErrorTracker.startTransaction(name, op);
311
- }
312
- try {
313
- const result = await fn(...args);
314
- if (span) {
315
- span.end();
316
- }
317
- return result;
318
- }
319
- catch (error) {
320
- if (span) {
321
- span.setStatus({
322
- code: 2,
323
- message: error instanceof Error ? error.message : 'Unknown error'
324
- });
325
- span.end();
326
- }
327
- throw error;
328
- }
329
- });
330
- }
331
- /**
332
- * 错误处理包装器
333
- */
334
- function withErrorTracking(fn, context, errorMessage) {
335
- return ((...args) => {
336
- try {
337
- const result = fn(...args);
338
- // 处理 Promise
339
- if (result instanceof Promise) {
340
- return result.catch((error) => {
341
- trackError((0, error_handler_1.normalizeError)(error, errorMessage || 'Unknown error'), context);
342
- throw error;
343
- });
344
- }
345
- return result;
346
- }
347
- catch (error) {
348
- trackError((0, error_handler_1.normalizeError)(error, errorMessage || 'Unknown error'), context);
349
- throw error;
350
- }
351
- });
352
- }
@@ -1,184 +0,0 @@
1
- /**
2
- * 性能监控指标系统
3
- * 收集和报告应用程序性能指标
4
- */
5
- /**
6
- * 指标类型
7
- */
8
- export declare enum MetricType {
9
- COUNTER = "counter",// 计数器(只增不减)
10
- GAUGE = "gauge",// 仪表盘(可增可减)
11
- HISTOGRAM = "histogram",// 直方图(分布统计)
12
- SUMMARY = "summary"
13
- }
14
- /**
15
- * 指标数据点
16
- */
17
- interface MetricDataPoint {
18
- value: number;
19
- timestamp: number;
20
- labels?: Record<string, string>;
21
- }
22
- /**
23
- * 指标接口
24
- */
25
- export interface Metric {
26
- name: string;
27
- type: MetricType;
28
- description: string;
29
- data: MetricDataPoint[];
30
- }
31
- /**
32
- * 直方图指标
33
- */
34
- export declare class Histogram {
35
- name: string;
36
- description: string;
37
- private buckets;
38
- private data;
39
- private sum;
40
- private count;
41
- constructor(name: string, description: string, buckets?: number[]);
42
- /**
43
- * 观察一个值
44
- */
45
- observe(value: number, labels?: Record<string, string>): void;
46
- /**
47
- * 获取统计信息
48
- */
49
- getStats(): {
50
- count: number;
51
- sum: number;
52
- avg: number;
53
- buckets: Record<string, number>;
54
- };
55
- /**
56
- * 重置
57
- */
58
- reset(): void;
59
- }
60
- /**
61
- * 计数器指标
62
- */
63
- export declare class Counter {
64
- name: string;
65
- description: string;
66
- private value;
67
- constructor(name: string, description: string);
68
- /**
69
- * 增加计数
70
- */
71
- inc(delta?: number, labels?: Record<string, string>): void;
72
- /**
73
- * 获取当前值
74
- */
75
- get(): number;
76
- /**
77
- * 重置
78
- */
79
- reset(): void;
80
- }
81
- /**
82
- * 仪表盘指标
83
- */
84
- export declare class Gauge {
85
- name: string;
86
- description: string;
87
- private value;
88
- constructor(name: string, description: string);
89
- /**
90
- * 设置值
91
- */
92
- set(value: number, labels?: Record<string, string>): void;
93
- /**
94
- * 增加
95
- */
96
- inc(delta?: number, labels?: Record<string, string>): void;
97
- /**
98
- * 减少
99
- */
100
- dec(delta?: number, labels?: Record<string, string>): void;
101
- /**
102
- * 获取当前值
103
- */
104
- get(): number;
105
- /**
106
- * 重置
107
- */
108
- reset(): void;
109
- }
110
- /**
111
- * 性能指标收集器
112
- */
113
- export declare class MetricsCollector {
114
- private metrics;
115
- /**
116
- * 创建或获取计数器
117
- */
118
- getCounter(name: string, description: string): Counter;
119
- /**
120
- * 创建或获取仪表盘
121
- */
122
- getGauge(name: string, description: string): Gauge;
123
- /**
124
- * 创建或获取直方图
125
- */
126
- getHistogram(name: string, description: string, buckets?: number[]): Histogram;
127
- /**
128
- * 获取所有指标
129
- */
130
- getAllMetrics(): Map<string, Counter | Gauge | Histogram>;
131
- /**
132
- * 重置所有指标
133
- */
134
- resetAll(): void;
135
- /**
136
- * 生成指标报告
137
- */
138
- generateReport(): string;
139
- }
140
- /**
141
- * 初始化全局指标收集器
142
- */
143
- export declare function initMetrics(): MetricsCollector;
144
- /**
145
- * 获取全局指标收集器
146
- */
147
- export declare function getMetricsCollector(): MetricsCollector | null;
148
- /**
149
- * 便捷函数:增加计数器
150
- */
151
- export declare function incCounter(name: string, delta?: number): void;
152
- /**
153
- * 便捷函数:设置仪表盘
154
- */
155
- export declare function setGauge(name: string, value: number): void;
156
- /**
157
- * 便捷函数:观察直方图
158
- */
159
- export declare function observeHistogram(name: string, value: number): void;
160
- /**
161
- * 便捷函数:记录 RSS 获取成功
162
- */
163
- export declare function recordRssFetch(duration: number): void;
164
- /**
165
- * 便捷函数:记录 RSS 获取失败
166
- */
167
- export declare function recordRssFetchError(): void;
168
- /**
169
- * 便捷函数:记录 AI 摘要成功
170
- */
171
- export declare function recordAiSummary(duration: number, cached: boolean): void;
172
- /**
173
- * 便捷函数:记录 AI 摘要失败
174
- */
175
- export declare function recordAiSummaryError(): void;
176
- /**
177
- * 便捷函数:记录消息发送
178
- */
179
- export declare function recordMessageSend(success: boolean): void;
180
- /**
181
- * 更新内存使用指标
182
- */
183
- export declare function updateMemoryUsage(): void;
184
- export {};