mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-12-06 02:11:56 +00:00
🎈 pref: 新增dy重试兜底策略
This commit is contained in:
parent
479efae0c4
commit
cd69d28c64
@ -36,7 +36,7 @@ import {
|
|||||||
downloadImg,
|
downloadImg,
|
||||||
downloadMp3,
|
downloadMp3,
|
||||||
formatBiliInfo,
|
formatBiliInfo,
|
||||||
getIdVideo,
|
getIdVideo, retryAxiosReq,
|
||||||
secondsToTime,
|
secondsToTime,
|
||||||
testProxy,
|
testProxy,
|
||||||
truncateString
|
truncateString
|
||||||
@ -262,18 +262,12 @@ export class tools extends plugin {
|
|||||||
// const param = resp.data.result[0].paramsencode;
|
// const param = resp.data.result[0].paramsencode;
|
||||||
const resDyApi = `${ dyApi }&X-Bogus=${ xbParam }`;
|
const resDyApi = `${ dyApi }&X-Bogus=${ xbParam }`;
|
||||||
headers['Referer'] = `https://www.douyin.com/video/${ douId }`
|
headers['Referer'] = `https://www.douyin.com/video/${ douId }`
|
||||||
axios
|
const dyResponse = () => axios.get(resDyApi, {
|
||||||
.get(resDyApi, {
|
|
||||||
headers,
|
headers,
|
||||||
})
|
});
|
||||||
.then(async resp => {
|
const data = await retryAxiosReq(dyResponse)
|
||||||
// console.log(resp)
|
// logger.info(data)
|
||||||
if (_.isEmpty(await resp?.data)) {
|
const item = await data.aweme_detail;
|
||||||
e.reply("解析失败,请重试!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// console.log(await resp.data)
|
|
||||||
const item = await resp.data.aweme_detail;
|
|
||||||
e.reply(`识别:抖音, ${ item.desc }`);
|
e.reply(`识别:抖音, ${ item.desc }`);
|
||||||
const urlTypeCode = item.aweme_type;
|
const urlTypeCode = item.aweme_type;
|
||||||
const urlType = douyinTypeMap[urlTypeCode];
|
const urlType = douyinTypeMap[urlTypeCode];
|
||||||
@ -306,7 +300,6 @@ export class tools extends plugin {
|
|||||||
await this.reply(await Bot.makeForwardMsg(no_watermark_image_list));
|
await this.reply(await Bot.makeForwardMsg(no_watermark_image_list));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -353,3 +353,28 @@ export function formatSeconds(seconds) {
|
|||||||
const remainingSeconds = seconds % 60;
|
const remainingSeconds = seconds % 60;
|
||||||
return `${minutes}分${remainingSeconds}秒`;
|
return `${minutes}分${remainingSeconds}秒`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重试 axios 请求
|
||||||
|
* @param requestFunction
|
||||||
|
* @param retries
|
||||||
|
* @param delay
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
export async function retryAxiosReq(requestFunction, retries = 3, delay = 1000) {
|
||||||
|
try {
|
||||||
|
const response = await requestFunction();
|
||||||
|
if (!response.data) {
|
||||||
|
throw new Error('请求空数据');
|
||||||
|
}
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
if (retries > 0) {
|
||||||
|
logger.mark(`[R插件][重试模块]重试中... (${3 - retries + 1}/3) 次`);
|
||||||
|
await new Promise(resolve => setTimeout(resolve, delay));
|
||||||
|
return retryAxiosReq(requestFunction, retries - 1, delay);
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user