koishi-plugin-wordpress-notifier 2.0.5 → 2.0.6

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
@@ -50,9 +50,9 @@ plugins:
50
50
  mentionAll: false # 是否 @全体成员
51
51
  maxArticles: 5 # 每次最多推送的文章数量
52
52
  # 可选:WordPress API 认证配置
53
- # 推荐使用应用程序密码(Application Password),更安全
53
+ # 使用应用程序密码,更安全
54
54
  # username: 'your-wordpress-username'
55
- # password: 'your-application-password' # 可以是普通密码或应用程序密码
55
+ # applicationPassword: 'your-application-password' # 例如:hGR2 sPFu Yncl xHc4 AvJq cUtB
56
56
  ```
57
57
 
58
58
  ### 如何获取WordPress应用程序密码
@@ -65,7 +65,7 @@ plugins:
65
65
  6. 复制生成的应用程序密码(例如:`hGR2 sPFu Yncl xHc4 AvJq cUtB`)
66
66
  7. 在插件配置中使用此密码,**无需删除空格**,插件会自动处理
67
67
 
68
- 应用程序密码是WordPress生成的安全密码,适合API访问,比普通密码更安全,可以随时撤销,不会影响您的主密码。
68
+ 应用程序密码是WordPress生成的安全密码,适合API访问,比普通密码更安全,可以随时撤销,不会影响您的主密码。插件已不再支持普通密码,必须使用应用程序密码。
69
69
 
70
70
  ### 配置参数说明
71
71
 
@@ -79,8 +79,8 @@ plugins:
79
79
  | `enableUserPush` | boolean | false | 是否启用新用户注册推送 |
80
80
  | `mentionAll` | boolean | false | 是否在推送时 @全体成员 |
81
81
  | `maxArticles` | number | 5 | 每次最多推送的文章数量 |
82
- | `username` | string | 可选 | WordPress 用户名(用于 Basic 基础认证) |
83
- | `password` | string | 可选 | WordPress 密码或应用程序密码(用于 Basic 基础认证,推荐使用应用程序密码,更安全) |
82
+ | `username` | string | 可选 | WordPress 用户名(用于 Basic 基础认证,与应用程序密码配合使用) |
83
+ | `applicationPassword` | string | 可选 | WordPress 应用程序密码(用于 Basic 基础认证,例如:hGR2sPFuYnclxHc4AvJqcUtB) |
84
84
 
85
85
  ## 使用命令
86
86
 
@@ -285,6 +285,15 @@ npm install
285
285
 
286
286
  ## 版本历史
287
287
 
288
+ ### 2.0.6 (2026-01-25)
289
+
290
+ - ✅ 不再采用WordPress普通密码,改用应用程序密码
291
+ - ✅ 配置页面添加应用程序密码字段,移除普通密码字段
292
+ - ✅ 优化认证逻辑,专门处理应用程序密码
293
+ - ✅ 支持自动处理带有空格的应用程序密码
294
+ - 🔧 更新了文档,详细说明如何使用应用程序密码
295
+ - 🔧 提高了API访问的安全性
296
+
288
297
  ### 2.0.5 (2026-01-25)
289
298
 
290
299
  - ✅ 支持WordPress应用程序密码(Application Password)
package/lib/index.d.ts CHANGED
@@ -19,7 +19,7 @@ export interface Config {
19
19
  mentionAll: boolean;
20
20
  maxArticles: number;
21
21
  username?: string;
22
- password?: string;
22
+ applicationPassword?: string;
23
23
  }
24
24
  export interface WordPressPost {
25
25
  id: number;
package/lib/index.js CHANGED
@@ -14,8 +14,8 @@ exports.Config = koishi_1.Schema.object({
14
14
  enableUserPush: koishi_1.Schema.boolean().default(false).description('是否启用新用户注册推送'),
15
15
  mentionAll: koishi_1.Schema.boolean().default(false).description('是否 @全体成员'),
16
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
+ username: koishi_1.Schema.string().default('').description('WordPress 用户名(用于 Basic 认证,与应用程序密码配合使用)'),
18
+ applicationPassword: koishi_1.Schema.string().default('').description('WordPress 应用程序密码(用于 Basic 认证,例如:hGR2sPFuYnclxHc4AvJqcUtB)')
19
19
  });
20
20
  function apply(ctx, config) {
21
21
  ctx.logger.info('WordPress 推送插件已加载');
@@ -61,12 +61,12 @@ function apply(ctx, config) {
61
61
  try {
62
62
  const url = `${config.wordpressUrl}/wp-json/wp/v2/posts?per_page=${config.maxArticles}&orderby=date&order=desc`;
63
63
  ctx.logger.info(`正在获取文章: ${url}`);
64
- // 准备请求配置,添加认证头(如果配置了用户名和密码)
64
+ // 准备请求配置,添加认证头(如果配置了用户名和应用程序密码)
65
65
  const requestConfig = {};
66
- if (config.username && config.password) {
66
+ if (config.username && config.applicationPassword) {
67
67
  // 处理WordPress应用程序密码,移除空格(WordPress生成的应用密码格式为:hGR2 sPFu Yncl xHc4 AvJq cUtB)
68
68
  const username = config.username;
69
- const password = config.password.replace(/\s+/g, ''); // 移除所有空格
69
+ const password = config.applicationPassword.replace(/\s+/g, ''); // 移除所有空格
70
70
  const auth = Buffer.from(`${username}:${password}`).toString('base64');
71
71
  requestConfig.headers = {
72
72
  Authorization: `Basic ${auth}`
@@ -85,12 +85,12 @@ function apply(ctx, config) {
85
85
  try {
86
86
  const url = `${config.wordpressUrl}/wp-json/wp/v2/users?per_page=${config.maxArticles}&orderby=registered_date&order=desc`;
87
87
  ctx.logger.info(`正在获取用户: ${url}`);
88
- // 准备请求配置,添加认证头(如果配置了用户名和密码)
88
+ // 准备请求配置,添加认证头(如果配置了用户名和应用程序密码)
89
89
  const requestConfig = {};
90
- if (config.username && config.password) {
90
+ if (config.username && config.applicationPassword) {
91
91
  // 处理WordPress应用程序密码,移除空格(WordPress生成的应用密码格式为:hGR2 sPFu Yncl xHc4 AvJq cUtB)
92
92
  const username = config.username;
93
- const password = config.password.replace(/\s+/g, ''); // 移除所有空格
93
+ const password = config.applicationPassword.replace(/\s+/g, ''); // 移除所有空格
94
94
  const auth = Buffer.from(`${username}:${password}`).toString('base64');
95
95
  requestConfig.headers = {
96
96
  Authorization: `Basic ${auth}`
@@ -102,7 +102,7 @@ function apply(ctx, config) {
102
102
  }
103
103
  catch (error) {
104
104
  ctx.logger.error(`获取 WordPress 用户失败: ${error}`);
105
- ctx.logger.error(`WordPress REST API 的 users 端点需要认证才能访问,请在插件配置中添加 WordPress 用户名和密码`);
105
+ ctx.logger.error(`WordPress REST API 的 users 端点需要认证才能访问,请在插件配置中添加 WordPress 用户名和应用程序密码`);
106
106
  // 返回空数组,确保插件继续运行
107
107
  return [];
108
108
  }
@@ -111,10 +111,13 @@ function apply(ctx, config) {
111
111
  try {
112
112
  const url = `${config.wordpressUrl}/wp-json/wp/v2/posts?per_page=${config.maxArticles}&orderby=modified&order=desc`;
113
113
  ctx.logger.info(`正在获取更新文章: ${url}`);
114
- // 准备请求配置,添加认证头(如果配置了用户名和密码)
114
+ // 准备请求配置,添加认证头(如果配置了用户名和应用程序密码)
115
115
  const requestConfig = {};
116
- if (config.username && config.password) {
117
- const auth = Buffer.from(`${config.username}:${config.password}`).toString('base64');
116
+ if (config.username && config.applicationPassword) {
117
+ // 处理WordPress应用程序密码,移除空格(WordPress生成的应用密码格式为:hGR2 sPFu Yncl xHc4 AvJq cUtB)
118
+ const username = config.username;
119
+ const password = config.applicationPassword.replace(/\s+/g, ''); // 移除所有空格
120
+ const auth = Buffer.from(`${username}:${password}`).toString('base64');
118
121
  requestConfig.headers = {
119
122
  Authorization: `Basic ${auth}`
120
123
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-wordpress-notifier",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "WordPress 文章自动推送到 QQ",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",