koishi-plugin-wordpress-notifier 2.0.2 → 2.0.4

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 CHANGED
@@ -45,8 +45,13 @@ plugins:
45
45
  targets:
46
46
  - '2801323326' # 推送目标(群号或 QQ 号)
47
47
  enableAutoPush: true # 是否启用自动推送
48
+ enableUpdatePush: false # 是否启用文章更新推送
49
+ enableUserPush: false # 是否启用新用户注册推送
48
50
  mentionAll: false # 是否 @全体成员
49
51
  maxArticles: 5 # 每次最多推送的文章数量
52
+ # 可选:WordPress API 认证配置(用于访问受保护的端点,如 users 端点)
53
+ # username: 'your-wordpress-username'
54
+ # password: 'your-wordpress-password'
50
55
  ```
51
56
 
52
57
  ### 配置参数说明
@@ -61,6 +66,8 @@ plugins:
61
66
  | `enableUserPush` | boolean | false | 是否启用新用户注册推送 |
62
67
  | `mentionAll` | boolean | false | 是否在推送时 @全体成员 |
63
68
  | `maxArticles` | number | 5 | 每次最多推送的文章数量 |
69
+ | `username` | string | 可选 | WordPress 用户名(用于 Basic 基础认证,访问受保护的 API 端点,如 users 端点) |
70
+ | `password` | string | 可选 | WordPress 密码(用于 Basic 基础认证,访问受保护的 API 端点,如 users 端点) |
64
71
 
65
72
  ## 使用命令
66
73
 
@@ -265,6 +272,22 @@ npm install
265
272
 
266
273
  ## 版本历史
267
274
 
275
+ ### 2.0.4 (2026-01-25)
276
+
277
+ - ✅ 修复插件配置页面无法添加WordPress账号和密码的问题
278
+ - ✅ 在Schema配置中添加了username和password字段,支持在插件配置页面设置
279
+ - ✅ 支持Basic基础认证,请求头携带认证信息
280
+ - 🔧 优化了配置页面的用户体验
281
+ - 🔧 更新了文档,说明如何在配置页面添加认证信息
282
+
283
+ ### 2.0.3 (2026-01-25)
284
+
285
+ - ✨ 新增 WordPress API 认证支持
286
+ - ✅ 支持配置 username 和 password 访问受保护的 API 端点
287
+ - ✅ 特别是解决了 users 端点需要认证才能访问的问题
288
+ - 🔧 更新了配置文档,添加了认证配置说明和示例
289
+ - 🔧 优化了 HTTP 请求逻辑,支持基本认证
290
+
268
291
  ### 2.0.2 (2026-01-25)
269
292
 
270
293
  - 🐛 修复每次重载时重新推送的问题
package/lib/index.d.ts CHANGED
@@ -18,6 +18,8 @@ export interface Config {
18
18
  enableUserPush: boolean;
19
19
  mentionAll: boolean;
20
20
  maxArticles: number;
21
+ username?: string;
22
+ password?: string;
21
23
  }
22
24
  export interface WordPressPost {
23
25
  id: number;
package/lib/index.js CHANGED
@@ -13,7 +13,9 @@ exports.Config = koishi_1.Schema.object({
13
13
  enableUpdatePush: koishi_1.Schema.boolean().default(false).description('是否启用文章更新推送'),
14
14
  enableUserPush: koishi_1.Schema.boolean().default(false).description('是否启用新用户注册推送'),
15
15
  mentionAll: koishi_1.Schema.boolean().default(false).description('是否 @全体成员'),
16
- maxArticles: koishi_1.Schema.number().default(5).description('每次最多推送的文章数量')
16
+ maxArticles: koishi_1.Schema.number().default(5).description('每次最多推送的文章数量'),
17
+ username: koishi_1.Schema.string().default('').description('WordPress 用户名(用于 Basic 认证,访问受保护的 API 端点)'),
18
+ password: koishi_1.Schema.string().default('').description('WordPress 密码(用于 Basic 认证,访问受保护的 API 端点)')
17
19
  });
18
20
  function apply(ctx, config) {
19
21
  ctx.logger.info('WordPress 推送插件已加载');
@@ -59,7 +61,15 @@ function apply(ctx, config) {
59
61
  try {
60
62
  const url = `${config.wordpressUrl}/wp-json/wp/v2/posts?per_page=${config.maxArticles}&orderby=date&order=desc`;
61
63
  ctx.logger.info(`正在获取文章: ${url}`);
62
- const response = await ctx.http.get(url);
64
+ // 准备请求配置,添加认证头(如果配置了用户名和密码)
65
+ const requestConfig = {};
66
+ if (config.username && config.password) {
67
+ const auth = Buffer.from(`${config.username}:${config.password}`).toString('base64');
68
+ requestConfig.headers = {
69
+ Authorization: `Basic ${auth}`
70
+ };
71
+ }
72
+ const response = await ctx.http.get(url, requestConfig);
63
73
  ctx.logger.info(`成功获取 ${response.length} 篇文章`);
64
74
  return response;
65
75
  }
@@ -72,13 +82,21 @@ function apply(ctx, config) {
72
82
  try {
73
83
  const url = `${config.wordpressUrl}/wp-json/wp/v2/users?per_page=${config.maxArticles}&orderby=registered_date&order=desc`;
74
84
  ctx.logger.info(`正在获取用户: ${url}`);
75
- const response = await ctx.http.get(url);
85
+ // 准备请求配置,添加认证头(如果配置了用户名和密码)
86
+ const requestConfig = {};
87
+ if (config.username && config.password) {
88
+ const auth = Buffer.from(`${config.username}:${config.password}`).toString('base64');
89
+ requestConfig.headers = {
90
+ Authorization: `Basic ${auth}`
91
+ };
92
+ }
93
+ const response = await ctx.http.get(url, requestConfig);
76
94
  ctx.logger.info(`成功获取 ${response.length} 位用户`);
77
95
  return response;
78
96
  }
79
97
  catch (error) {
80
98
  ctx.logger.error(`获取 WordPress 用户失败: ${error}`);
81
- ctx.logger.error(`WordPress REST API 的 users 端点可能需要认证才能访问,当前版本暂不支持认证配置`);
99
+ ctx.logger.error(`WordPress REST API 的 users 端点需要认证才能访问,请在插件配置中添加 WordPress 用户名和密码`);
82
100
  // 返回空数组,确保插件继续运行
83
101
  return [];
84
102
  }
@@ -87,7 +105,15 @@ function apply(ctx, config) {
87
105
  try {
88
106
  const url = `${config.wordpressUrl}/wp-json/wp/v2/posts?per_page=${config.maxArticles}&orderby=modified&order=desc`;
89
107
  ctx.logger.info(`正在获取更新文章: ${url}`);
90
- const response = await ctx.http.get(url);
108
+ // 准备请求配置,添加认证头(如果配置了用户名和密码)
109
+ const requestConfig = {};
110
+ if (config.username && config.password) {
111
+ const auth = Buffer.from(`${config.username}:${config.password}`).toString('base64');
112
+ requestConfig.headers = {
113
+ Authorization: `Basic ${auth}`
114
+ };
115
+ }
116
+ const response = await ctx.http.get(url, requestConfig);
91
117
  ctx.logger.info(`成功获取 ${response.length} 篇更新文章`);
92
118
  return response;
93
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-wordpress-notifier",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "WordPress 文章自动推送到 QQ",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",