From 40f059bcc9f74cd8418d27b613e62cd6519ed73b Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Mon, 4 Aug 2025 10:08:57 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(tools.js,=20constant.js):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9=20GitHub=20=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E7=9A=84=E6=80=BB=E7=BB=93=E5=8A=9F=E8=83=BD=20&&=20=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E6=80=BB=E7=BB=93=E5=81=A5=E5=A3=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 2 +- constants/constant.js | 3 ++- utils/common.js | 26 ++++++++++++++++++++++++++ utils/llm-util.js | 3 ++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index c527fca..2b33985 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -202,7 +202,7 @@ export class tools extends plugin { fnc: "freyr" }, { - reg: "(^#总结一下(http|https):\/\/.*|mp.weixin.qq.com|arxiv.org|sspai.com|chinadaily.com.cn|zhihu.com)", + reg: "(^#总结一下\s*(http|https):\/\/.*|mp.weixin.qq.com|arxiv.org|sspai.com|chinadaily.com.cn|zhihu.com|github.com)", fnc: "linkShareSummary" }, { diff --git a/constants/constant.js b/constants/constant.js index 72dbc91..09fb314 100644 --- a/constants/constant.js +++ b/constants/constant.js @@ -158,7 +158,8 @@ export const SUMMARY_CONTENT_ESTIMATOR_PATTERNS = [ { reg: /(?:https?:\/\/)?sspai.com\/[a-zA-Z\d._?%&+\-=\/#]*/, name: '少数派' }, { reg: /(?:https?:\/\/)?www\.bilibili\.com\/read\/[A-Za-z\d._?%&+\-=\/#]*/, name: '哔哩哔哩专栏' }, { reg: /(?:https?:\/\/)?www\.zhihu\.com\/question\/[A-Za-z\d._?%&+\-=\/#]*/, name: '知乎问题' }, - { reg: /(?:https?:\/\/)?(www\.)chinadaily.com.cn\/a\/[a-zA-Z0-9\d._?%&+\-=\/#]*/, name: 'ChinaDaily' } + { reg: /(?:https?:\/\/)?(www\.)chinadaily.com.cn\/a\/[a-zA-Z0-9\d._?%&+\-=\/#]*/, name: 'ChinaDaily' }, + { reg: /(?:https?:\/\/)?(www\.)?github.com\/[a-zA-Z0-9\d._?%&+\-=\/#]*/, name: 'Github' } ]; const BILI_CDN_TEMPLATE = "upos-sz-mirror{}.bilivideo.com"; diff --git a/utils/common.js b/utils/common.js index 85e936e..146e56f 100644 --- a/utils/common.js +++ b/utils/common.js @@ -350,6 +350,32 @@ export async function retryAxiosReq(requestFunction, retries = 3, delay = 1000) } } +/** + * 重试 fetch 请求 + * @param {string} url 请求的URL + * @param {object} [options] 传递给fetch的选项 + * @param {number} [retries=3] 重试次数 + * @param {number} [delay=1000] 重试之间的延迟(毫秒) + * @returns {Promise} + */ +export async function retryFetch(url, options, retries = 3, delay = 1000) { + try { + const response = await fetch(url, options); + if (!response.ok) { + throw new Error(`请求失败,状态码: ${response.status}`); + } + return response; + } catch (error) { + if (retries > 0) { + logger.mark(`[R插件][重试模块] 请求失败: ${error.message},重试中... (${3 - retries + 1}/3) 次`); + await new Promise(resolve => setTimeout(resolve, delay)); + return retryFetch(url, options, retries - 1, delay); + } else { + throw error; + } + } +} + /** * 统计给定文本中的中文字数 * diff --git a/utils/llm-util.js b/utils/llm-util.js index ef6094c..bab0d53 100644 --- a/utils/llm-util.js +++ b/utils/llm-util.js @@ -1,3 +1,4 @@ +import { retryFetch } from "./common.js"; import { PearAPI_CRAWLER, PearAPI_DEEPSEEK } from "../constants/tools.js"; /** @@ -6,7 +7,7 @@ import { PearAPI_CRAWLER, PearAPI_DEEPSEEK } from "../constants/tools.js"; * @returns {Promise} */ export async function llmRead(summaryLink) { - const llmCrawler = await fetch(PearAPI_CRAWLER.replace("{}", summaryLink)); + const llmCrawler = await retryFetch(PearAPI_CRAWLER.replace("{}", summaryLink)); return (await llmCrawler.json())?.data; }