fix: 两处潜在问题

- 存储专栏获取结果
- 专栏获取为null
This commit is contained in:
shanmite
2021-08-17 18:43:59 +08:00
parent 9842107f52
commit ef822df5bf
3 changed files with 29 additions and 6 deletions
+10 -3
View File
@@ -294,7 +294,9 @@ class Searcher {
log.info('获取动态', `开始获取含关键词${key_words}的专栏信息`);
const cvs = (await bili.searchArticlesByKeyword(key_words)).slice(0, config.article_scan_page);
/**存储所有专栏中的dyid */
let dyinfos = [];
/**遍历专栏s */
for (const cv of cvs) {
const
content = await bili.getOneArticleByCv(cv),
@@ -304,8 +306,12 @@ class Searcher {
weight = dyids_set.length / 2;
let { length } = dyids_set,
_weight = 0;
/**初始权重 */
_weight = 0,
/**单个专栏中的dyid */
_dyinfos = [];
log.info('获取动态', `提取专栏(${cv})中提及的dyid(${length})`)
/**遍历某专栏中的dyids */
for (const dyid of dyids_set) {
const isRelayed = await d_storage.searchDyid(dyid);
if (isRelayed) {
@@ -313,7 +319,7 @@ class Searcher {
}
if (_weight >= weight) {
log.warn('获取动态', `1/2动态曾经转过,该专栏或已查看,故中止`)
dyinfos = []
_dyinfos = []
break
}
if (dyid.length === utils.dyid_length) {
@@ -331,7 +337,7 @@ class Searcher {
await utils.delay(2000)
if (card) {
dyinfos.push(parseDynamicCard(card));
_dyinfos.push(parseDynamicCard(card));
}
} else {
log.info('获取动态', `动态(${dyid})已转发过 (${length--})`)
@@ -340,6 +346,7 @@ class Searcher {
log.warn('获取动态', `动态(${dyid})无效 (${length--})`)
}
}
dyinfos.push(..._dyinfos)
}
const fomatdata = dyinfos.map(o => {
return {
+9 -2
View File
@@ -349,8 +349,15 @@ const bili_client = {
}).then(responseText => {
const res = JSON.parse(responseText);
if (res.code === 0) {
log.info('搜索专栏', '成功 关键词: ' + keyword)
return res.data.result.map(it => it.id)
let cv_arr = []
try {
log.info('搜索专栏', '成功 关键词: ' + keyword)
cv_arr = res.data.result.map(it => it.id)
} catch (error) {
log.error('搜索专栏', '失败 原因:\n' + responseText)
cv_arr = []
}
return cv_arr
} else {
log.error('搜索专栏', '失败 原因:\n' + responseText)
return []