🐞 fix: 修复部分用户使用 TikTok 解析问题

This commit is contained in:
zhiyu1998 2024-07-12 13:28:57 +08:00
parent de424d6a13
commit 9a545f66a9
2 changed files with 7 additions and 5 deletions

View File

@ -342,7 +342,7 @@ export class tools extends plugin {
return false;
}
// 处理链接
let url = await processTikTokUrl(e.msg.trim(), isOversea);
let url = await processTikTokUrl(e.msg.trim(), isOversea, this.myProxy);
// 去除多余参数
const parsedUrl = new URL(url);
parsedUrl.search = '';

View File

@ -4,9 +4,10 @@ import HttpProxyAgent from "https-proxy-agent";
* Tiktok专属解析链接的Fetch
* @param url 地址
* @param isOversea 是否是海外
* @param proxy 梯子
*/
const fetchTiktokUrl = async (url, isOversea) => {
const proxyAgent = isOversea ? '' : new HttpProxyAgent(this.myProxy);
const fetchTiktokUrl = async (url, isOversea, proxy) => {
const proxyAgent = isOversea ? '' : new HttpProxyAgent(proxy);
// 处理特殊情况 & 非特殊情况的header
const headers = url.includes("vm.tiktok") || url.includes("tiktok.com/t")
? { "User-Agent": "facebookexternalhit/1.1" }
@ -25,8 +26,9 @@ const fetchTiktokUrl = async (url, isOversea) => {
* 处理Tiktok链接
* @param url 用户发送的链接可能存在一些问题需要正则匹配处理
* @param isOversea 是否是海外
* @param proxy 梯子
*/
export const processTikTokUrl = async (url, isOversea) => {
export const processTikTokUrl = async (url, isOversea, proxy) => {
// 合并正则表达式
// const urlShortRex = /(http:|https:)\/\/vt.tiktok.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
// const urlShortRex2 = /(http:|https:)\/\/vm.tiktok.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
@ -35,7 +37,7 @@ export const processTikTokUrl = async (url, isOversea) => {
const match = tikTokRegex.exec(url);
if (match) {// 如果URL匹配任何TikTok相关的模式则进行处理
url = await fetchTiktokUrl(match[0], isOversea);
url = await fetchTiktokUrl(match[0], isOversea, proxy);
}
// 这里可以处理其他逻辑例如更新URL、记录日志等