koishi-plugin-wordpress-notifier 2.8.0 → 2.8.1
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.
- package/README.md +15 -0
- package/lib/index.js +82 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -339,6 +339,21 @@ npm install
|
|
|
339
339
|
|
|
340
340
|
## 版本历史
|
|
341
341
|
|
|
342
|
+
### 2.8.1 (2026-02-19)
|
|
343
|
+
|
|
344
|
+
- 🐛 修复 MySQL 主键约束错误 (ER_PRIMARY_CANT_HAVE_NULL)
|
|
345
|
+
|
|
346
|
+
**核心修复**
|
|
347
|
+
- ✅ 增强 `checkAndFixTableStructure` 函数,添加表结构自动修复机制
|
|
348
|
+
- ✅ 当表结构不正确时,自动删除旧表并重新初始化,确保主键约束正确设置
|
|
349
|
+
- ✅ 为 `wordpress_post_updates`、`wordpress_user_registrations` 和 `wordpress_config` 表添加自动修复逻辑
|
|
350
|
+
- ✅ 优化 `loadPersistentConfig` 函数,添加更详细的错误处理,确保即使数据库操作失败也能继续运行
|
|
351
|
+
- ✅ 修改 `updatePostUpdateRecord` 函数,移除错误抛出,确保推送流程不会被数据库操作失败中断
|
|
352
|
+
|
|
353
|
+
**稳定性提升**
|
|
354
|
+
- ✅ 增加数据库操作的容错能力,提高插件在各种环境下的稳定性
|
|
355
|
+
- ✅ 优化错误日志记录,提供更详细的错误信息,便于排查问题
|
|
356
|
+
|
|
342
357
|
### 2.8.0 (2026-02-18)
|
|
343
358
|
|
|
344
359
|
- 🚀 全面优化插件稳定性、性能和功能完整性
|
package/lib/index.js
CHANGED
|
@@ -114,7 +114,12 @@ function apply(ctx, config) {
|
|
|
114
114
|
ctx.logger.info('持久化配置加载完成');
|
|
115
115
|
}
|
|
116
116
|
catch (error) {
|
|
117
|
-
|
|
117
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
118
|
+
ctx.logger.error(`加载持久化配置失败: ${errorMessage}`);
|
|
119
|
+
ctx.logger.error(`错误栈:${error instanceof Error ? error.stack : '无'}`);
|
|
120
|
+
// 发生错误时,不抛出异常,确保插件继续运行
|
|
121
|
+
// 使用默认配置
|
|
122
|
+
ctx.logger.warn('使用默认配置继续运行,持久化配置将在下次保存时重新创建');
|
|
118
123
|
}
|
|
119
124
|
}
|
|
120
125
|
// 保存配置到数据库
|
|
@@ -308,7 +313,27 @@ function apply(ctx, config) {
|
|
|
308
313
|
}
|
|
309
314
|
catch (error) {
|
|
310
315
|
ctx.logger.warn(`wordpress_post_updates 表可能结构不正确,尝试重新初始化...`);
|
|
311
|
-
//
|
|
316
|
+
// 尝试删除旧表并重新初始化
|
|
317
|
+
try {
|
|
318
|
+
ctx.logger.info('尝试删除旧的 wordpress_post_updates 表...');
|
|
319
|
+
await ctx.database.drop('wordpress_post_updates');
|
|
320
|
+
ctx.logger.info('旧表删除成功,重新初始化表结构...');
|
|
321
|
+
// 重新扩展模型
|
|
322
|
+
ctx.model.extend('wordpress_post_updates', {
|
|
323
|
+
id: 'integer',
|
|
324
|
+
postId: 'integer',
|
|
325
|
+
lastModified: 'timestamp',
|
|
326
|
+
pushedAt: 'timestamp'
|
|
327
|
+
}, {
|
|
328
|
+
primary: 'id',
|
|
329
|
+
autoInc: true,
|
|
330
|
+
unique: ['postId']
|
|
331
|
+
});
|
|
332
|
+
ctx.logger.info('wordpress_post_updates 表重新初始化成功');
|
|
333
|
+
}
|
|
334
|
+
catch (dropError) {
|
|
335
|
+
ctx.logger.warn(`删除旧表失败,可能表不存在:${dropError}`);
|
|
336
|
+
}
|
|
312
337
|
}
|
|
313
338
|
try {
|
|
314
339
|
ctx.logger.info('验证 wordpress_user_registrations 表结构...');
|
|
@@ -319,7 +344,57 @@ function apply(ctx, config) {
|
|
|
319
344
|
}
|
|
320
345
|
catch (error) {
|
|
321
346
|
ctx.logger.warn(`wordpress_user_registrations 表可能结构不正确,尝试重新初始化...`);
|
|
322
|
-
//
|
|
347
|
+
// 尝试删除旧表并重新初始化
|
|
348
|
+
try {
|
|
349
|
+
ctx.logger.info('尝试删除旧的 wordpress_user_registrations 表...');
|
|
350
|
+
await ctx.database.drop('wordpress_user_registrations');
|
|
351
|
+
ctx.logger.info('旧表删除成功,重新初始化表结构...');
|
|
352
|
+
// 重新扩展模型
|
|
353
|
+
ctx.model.extend('wordpress_user_registrations', {
|
|
354
|
+
id: 'integer',
|
|
355
|
+
userId: 'integer',
|
|
356
|
+
pushedAt: 'timestamp'
|
|
357
|
+
}, {
|
|
358
|
+
primary: 'id',
|
|
359
|
+
autoInc: true,
|
|
360
|
+
unique: ['userId']
|
|
361
|
+
});
|
|
362
|
+
ctx.logger.info('wordpress_user_registrations 表重新初始化成功');
|
|
363
|
+
}
|
|
364
|
+
catch (dropError) {
|
|
365
|
+
ctx.logger.warn(`删除旧表失败,可能表不存在:${dropError}`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
try {
|
|
369
|
+
ctx.logger.info('验证 wordpress_config 表结构...');
|
|
370
|
+
const testConfig = await ctx.database.get('wordpress_config', {}, {
|
|
371
|
+
limit: 1
|
|
372
|
+
});
|
|
373
|
+
ctx.logger.info(`wordpress_config 表验证成功,现有记录数:${testConfig.length}`);
|
|
374
|
+
}
|
|
375
|
+
catch (error) {
|
|
376
|
+
ctx.logger.warn(`wordpress_config 表可能结构不正确,尝试重新初始化...`);
|
|
377
|
+
// 尝试删除旧表并重新初始化
|
|
378
|
+
try {
|
|
379
|
+
ctx.logger.info('尝试删除旧的 wordpress_config 表...');
|
|
380
|
+
await ctx.database.drop('wordpress_config');
|
|
381
|
+
ctx.logger.info('旧表删除成功,重新初始化表结构...');
|
|
382
|
+
// 重新扩展模型
|
|
383
|
+
ctx.model.extend('wordpress_config', {
|
|
384
|
+
id: 'integer',
|
|
385
|
+
key: 'string',
|
|
386
|
+
value: 'string',
|
|
387
|
+
updatedAt: 'timestamp'
|
|
388
|
+
}, {
|
|
389
|
+
primary: 'id',
|
|
390
|
+
autoInc: true,
|
|
391
|
+
unique: ['key']
|
|
392
|
+
});
|
|
393
|
+
ctx.logger.info('wordpress_config 表重新初始化成功');
|
|
394
|
+
}
|
|
395
|
+
catch (dropError) {
|
|
396
|
+
ctx.logger.warn(`删除旧表失败,可能表不存在:${dropError}`);
|
|
397
|
+
}
|
|
323
398
|
}
|
|
324
399
|
ctx.logger.info('表结构检查和修复完成');
|
|
325
400
|
}
|
|
@@ -523,7 +598,7 @@ function apply(ctx, config) {
|
|
|
523
598
|
await ctx.database.remove('wordpress_post_updates', { postId });
|
|
524
599
|
ctx.logger.info(`已删除旧记录,文章 ID: ${postId}`);
|
|
525
600
|
}
|
|
526
|
-
//
|
|
601
|
+
// 创建新记录,不指定 id 字段,让数据库自动生成
|
|
527
602
|
const newRecord = {
|
|
528
603
|
postId,
|
|
529
604
|
lastModified: modifiedDate,
|
|
@@ -538,7 +613,9 @@ function apply(ctx, config) {
|
|
|
538
613
|
ctx.logger.error(`更新文章更新记录失败,文章 ID: ${postId}`);
|
|
539
614
|
ctx.logger.error(`错误信息: ${errorMessage}`);
|
|
540
615
|
ctx.logger.error(`错误栈: ${error instanceof Error ? error.stack : '无'}`);
|
|
541
|
-
|
|
616
|
+
// 不再抛出错误,确保推送流程继续运行
|
|
617
|
+
// 发生错误时,默认返回,避免阻塞推送流程
|
|
618
|
+
ctx.logger.warn(`更新文章更新记录失败,但推送流程将继续运行,文章 ID: ${postId}`);
|
|
542
619
|
}
|
|
543
620
|
}
|
|
544
621
|
// 1. 新增强清洗函数:针对性解决敏感字符问题
|