koishi-plugin-share-links-analysis 0.1.3 → 0.1.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/lib/index.js CHANGED
@@ -76,12 +76,6 @@ function apply(ctx, config) {
76
76
  ctx.on('ready', async () => {
77
77
  logger.info('插件已启动,执行一次初始的小红书 Cookie 刷新...');
78
78
  await (0, xiaohongshu_1.refreshXhsCookie)(ctx, config);
79
- // 设置一个定时器,每隔 12 小时刷新一次 Cookie
80
- // 24 * 60 * 60 * 1000 = 24小时
81
- // 12 * 60 * 60 * 1000 = 12小时
82
- ctx.setInterval(async () => {
83
- await (0, xiaohongshu_1.refreshXhsCookie)(ctx, config);
84
- }, 24 * 60 * 60 * 1000);
85
79
  });
86
80
  ctx.middleware(async (session, next) => {
87
81
  if (!session.content || !session.channelId)
@@ -9,6 +9,7 @@ export declare function match(content: string): Link[];
9
9
  /**
10
10
  * 使用 Puppeteer 刷新小红书 Cookie 并存入数据库
11
11
  * @param ctx - Koishi Context
12
+ * @param config
12
13
  */
13
14
  export declare function refreshXhsCookie(ctx: Context, config: PluginConfig): Promise<boolean>;
14
15
  /**
@@ -26,6 +26,7 @@ function match(content) {
26
26
  /**
27
27
  * 使用 Puppeteer 刷新小红书 Cookie 并存入数据库
28
28
  * @param ctx - Koishi Context
29
+ * @param config
29
30
  */
30
31
  async function refreshXhsCookie(ctx, config) {
31
32
  const logger = ctx.logger('share-links-analysis:xiaohongshu');
@@ -51,7 +52,7 @@ async function refreshXhsCookie(ctx, config) {
51
52
  }
52
53
  const initialCookies = await page.cookies();
53
54
  logger.info(`步骤 1 完成, 获取到 ${initialCookies.length} 个初始 Cookie。`);
54
- // --- 步骤 2: 访问 /explore 页面,触发反爬虫验证,获取安全 Cookie (如 acw_tc) ---
55
+ // --- 步骤 2: 访问 /explore 页面,触发反爬虫验证,获取安全 Cookie ---
55
56
  logger.info('步骤 2/2: 访问 /explore 页面以触发并获取安全 Cookie...');
56
57
  try {
57
58
  await page.goto('https://www.xiaohongshu.com/explore', {
@@ -68,16 +69,18 @@ async function refreshXhsCookie(ctx, config) {
68
69
  return false;
69
70
  }
70
71
  const hasWebSession = finalCookies.some((c) => c.name === 'web_session');
71
- const hasAcwTc = finalCookies.some((c) => c.name === 'acw_tc');
72
72
  const hasABRequestId = finalCookies.some((c) => c.name === 'abRequestId');
73
73
  logger.info(`步骤 2 完成, 共获取到 ${finalCookies.length} 个最终 Cookie。`);
74
74
  logger.info(`- 是否包含 'web_session': ${hasWebSession ? '是' : '否'}`);
75
- logger.info(`- 是否包含 'acw_tc': ${hasAcwTc ? '是' : '否'}`);
76
75
  logger.info(`- 是否包含 'abRequestId': ${hasABRequestId ? '是' : '否'}`);
77
- if (!hasWebSession || !hasAcwTc || !hasABRequestId) {
78
- logger.warn('关键 Cookie 缺失,本次刷新可能不完整。仍将尝试保存。');
76
+ if (!hasWebSession || !hasABRequestId) {
77
+ logger.warn('关键 Cookie 缺失,本次刷新可能不完整。将放弃刷新。');
78
+ return false;
79
79
  }
80
- const cookieString = finalCookies.map((c) => `${c.name}=${c.value}`).join('; ');
80
+ // 在这里过滤掉 acw_tc
81
+ const filteredCookies = finalCookies.filter((c) => c.name !== 'acw_tc');
82
+ // 使用过滤后的 cookie 数组来生成字符串
83
+ const cookieString = filteredCookies.map((c) => `${c.name}=${c.value}`).join('; ');
81
84
  await ctx.database.upsert('sla_cookie_cache', [{ platform: platformId, cookie: cookieString }]);
82
85
  logger.info('成功执行两步刷新策略并缓存了小红书 Cookie!');
83
86
  return true;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "koishi-plugin-share-links-analysis",
3
3
  "description": "自用插件",
4
4
  "license": "MIT",
5
- "version": "0.1.3",
5
+ "version": "0.1.4",
6
6
  "main": "lib/index.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "files": [