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; }