feat: 清理动态加入错误重试(#140)

fixed: #140
This commit is contained in:
shanmite 2022-06-24 11:07:48 +08:00
parent 329c5e506f
commit 2742dcbd4f
3 changed files with 12 additions and 7 deletions

View File

@ -1,4 +1,4 @@
const { log, delay, infiniteNumber } = require("./utils");
const { log, delay, infiniteNumber, retryfn } = require("./utils");
const bili = require("./net/bili");
const { Searcher } = require("./core/searcher");
const global_var = require('./data/global_var');
@ -46,7 +46,7 @@ async function clear() {
for (const [index, uid] of uid_list.entries()) {
log.info('清理关注', `(${index}) (${uid})`)
/* 取消关注 */
if (await bili.cancelAttention(uid)) {
if (await retryfn(3, [false], () => bili.cancelAttention(uid))) {
log.info('清理关注', '成功')
} else {
log.error('清理关注', '失败')
@ -65,7 +65,11 @@ async function clear() {
for (const page of infiniteNumber()) {
log.info('清理动态', `开始读取第${page + 1}`);
const { allModifyDynamicResArray, offset } = await Searcher.checkAllDynamic(MY_UID, 1, search_wait, next_offset);
const { allModifyDynamicResArray = [], offset = '0' } = await retryfn(
3,
[null],
() => Searcher.checkAllDynamic(MY_UID, 1, search_wait, next_offset)
);
next_offset = offset;
for (const [index, dyinfo] of allModifyDynamicResArray.entries()) {
log.info('清理动态', `${page + 1}页中的第${index + 1}个动态`)
@ -82,7 +86,7 @@ async function clear() {
if (dynamic_id
&& clear_remove_dynamic
&& !(new RegExp(dynamic_id).test(clear_white_list))) {
success = await bili.rmDynamic(dynamic_id)
success = await retryfn(3, [false], () => bili.rmDynamic(dynamic_id))
}
/* 取消关注 */
@ -91,7 +95,7 @@ async function clear() {
&& clear_remove_attention
&& before_separate.indexOf(origin_uid) === -1
&& uid_list.indexOf(origin_uid) > -1) {
success = await bili.cancelAttention(origin_uid);
success = await retryfn(3, [false], () => bili.cancelAttention(origin_uid))
}
if (!success) {

View File

@ -176,7 +176,7 @@ class Searcher {
* @param {number} pages 读取页数
* @param {number} time 时延
* @param {string} [offset] 默认'0'
* @returns {Promise<{allModifyDynamicResArray: UsefulDynamicInfo[], offset: string}>} 获取前 `pages*12` 个动态信息
* @returns {Promise<{allModifyDynamicResArray: UsefulDynamicInfo[], offset: string} | null>} 获取前 `pages*12` 个动态信息
*/
static async checkAllDynamic(hostuid, pages, time = 0, offset = '0') {
log.info('检查所有动态', `准备读取${pages}页动态`);
@ -205,7 +205,7 @@ class Searcher {
mDRdata = modifyDynamicRes(OneDynamicInfo);
if (mDRdata === null) {
break;
return null
}
const

View File

@ -64,6 +64,7 @@ const utils = {
* @param {number} max_times
* @param {Array<T>} unexpected
* @param {() => Promise<T>} fn
* @return {Promise<T | null>}
*/
async retryfn(max_times, unexpected, fn) {
let ret = null;