From 2742dcbd4f3ddb145e68c4b8f3e5c0e37f738a94 Mon Sep 17 00:00:00 2001 From: shanmite Date: Fri, 24 Jun 2022 11:07:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B8=85=E7=90=86=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E9=94=99=E8=AF=AF=E9=87=8D=E8=AF=95(#140)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixed: #140 --- lib/clear.js | 14 +++++++++----- lib/core/searcher.js | 4 ++-- lib/utils.js | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/clear.js b/lib/clear.js index 3def7a2..6c37deb 100644 --- a/lib/clear.js +++ b/lib/clear.js @@ -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) { diff --git a/lib/core/searcher.js b/lib/core/searcher.js index c4d7e05..0b3af6d 100644 --- a/lib/core/searcher.js +++ b/lib/core/searcher.js @@ -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 diff --git a/lib/utils.js b/lib/utils.js index 25e23fd..cf97451 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -64,6 +64,7 @@ const utils = { * @param {number} max_times * @param {Array} unexpected * @param {() => Promise} fn + * @return {Promise} */ async retryfn(max_times, unexpected, fn) { let ret = null;