mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
✨ feat(tools.js, constant.js): 添加对 GitHub 链接的总结功能 && 提升总结健壮性
This commit is contained in:
parent
99eb0ea7a3
commit
40f059bcc9
@ -202,7 +202,7 @@ export class tools extends plugin {
|
|||||||
fnc: "freyr"
|
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"
|
fnc: "linkShareSummary"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -158,7 +158,8 @@ export const SUMMARY_CONTENT_ESTIMATOR_PATTERNS = [
|
|||||||
{ reg: /(?:https?:\/\/)?sspai.com\/[a-zA-Z\d._?%&+\-=\/#]*/, name: '少数派' },
|
{ reg: /(?:https?:\/\/)?sspai.com\/[a-zA-Z\d._?%&+\-=\/#]*/, name: '少数派' },
|
||||||
{ reg: /(?:https?:\/\/)?www\.bilibili\.com\/read\/[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\.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";
|
const BILI_CDN_TEMPLATE = "upos-sz-mirror{}.bilivideo.com";
|
||||||
|
@ -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<Response>}
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计给定文本中的中文字数
|
* 统计给定文本中的中文字数
|
||||||
*
|
*
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { retryFetch } from "./common.js";
|
||||||
import { PearAPI_CRAWLER, PearAPI_DEEPSEEK } from "../constants/tools.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<string>}
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
export async function llmRead(summaryLink) {
|
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;
|
return (await llmCrawler.json())?.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user