mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
fix: 修复通过uid监视转发抽奖动态 (#449)
Some checks failed
Build and push Docker images / docker (push) Has been cancelled
Mirror and run GitLab CI / build (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, linux) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, macos) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, win) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (alpine) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linux) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linuxstatic) (push) Has been cancelled
Some checks failed
Build and push Docker images / docker (push) Has been cancelled
Mirror and run GitLab CI / build (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, linux) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, macos) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, win) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (alpine) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linux) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linuxstatic) (push) Has been cancelled
Fixed #447 * fix:oldparseDynamicCard已经无法获取是否抽奖 使用新版api * 当 offset 为 '0'(初始页)时,传入 offset 会报错 * 小修
This commit is contained in:
parent
5447c9ae69
commit
533606839f
@ -62,6 +62,12 @@ function parseDynamicCard(data) {
|
||||
if (data?.card?.desc?.uid) {
|
||||
return oldParseDynamicCard(data?.card);
|
||||
}
|
||||
|
||||
// 如果是多个 items,返回一个数组
|
||||
if (Array.isArray(data?.items)) {
|
||||
return data.items.map(item => parseDynamicCard({ item }));
|
||||
}
|
||||
|
||||
let ditem = data?.item;
|
||||
/**临时储存单个动态中的信息 */
|
||||
let obj = {};
|
||||
@ -352,16 +358,18 @@ function oldParseDynamicCard(dynamic_detail_card) {
|
||||
function modifyDynamicRes(res) {
|
||||
let
|
||||
{ data, code } = utils.strToJson(res),
|
||||
{ cards, has_more, offset } = data || {};
|
||||
{ items, has_more, offset } = data || {};
|
||||
|
||||
if (code !== 0) {
|
||||
log.error('处理动态数据', '获取动态数据出错,可能是访问太频繁 \n' + res);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (cards == null || !cards || !cards.length) {
|
||||
/**
|
||||
* !cards已经能涵盖cards == null,你在想什么?
|
||||
*/
|
||||
if (!items || !items.length) {
|
||||
log.warn('处理动态数据', '未找到任何动态信息');
|
||||
cards = [];
|
||||
items = [];
|
||||
}
|
||||
|
||||
if (typeof has_more === 'undefined'
|
||||
@ -376,18 +384,16 @@ function modifyDynamicRes(res) {
|
||||
*/
|
||||
next = {
|
||||
has_more,
|
||||
next_offset: typeof offset === 'string'
|
||||
? offset
|
||||
: /(?<=next_offset":)[0-9]+/.exec(res)[0]
|
||||
next_offset: offset
|
||||
},
|
||||
/**
|
||||
* 储存获取到的一组动态中的信息
|
||||
*/
|
||||
array = next.has_more === 0
|
||||
? []
|
||||
: cards.map(oldParseDynamicCard);
|
||||
: items.map(item => parseDynamicCard({ item }));
|
||||
|
||||
log.info('处理动态数据', `动态数据读取完毕(${cards.length})(${next.has_more})`);
|
||||
log.info('处理动态数据', `动态数据读取完毕(${items.length})(${next.has_more})`);
|
||||
|
||||
return {
|
||||
modifyDynamicResArray: array,
|
||||
@ -408,7 +414,7 @@ class Searcher {
|
||||
* @param {string} [offset] 默认'0'
|
||||
* @returns {Promise<{allModifyDynamicResArray: UsefulDynamicInfo[], offset: string} | null>} 获取前 `pages*12` 个动态信息
|
||||
*/
|
||||
static async checkAllDynamic(hostuid, pages, time = 0, offset = '0') {
|
||||
static async checkAllDynamic(host_mid, pages, time = 0, offset = '0') {
|
||||
log.info('检查所有动态', `准备读取${pages}页动态`);
|
||||
|
||||
const { getOneDynamicInfoByUID } = bili,
|
||||
@ -419,7 +425,7 @@ class Searcher {
|
||||
/**
|
||||
* 储存了特定UID的请求函数
|
||||
*/
|
||||
hadUidGetOneDynamicInfoByUID = curriedGetOneDynamicInfoByUID(hostuid);
|
||||
hadUidGetOneDynamicInfoByUID = curriedGetOneDynamicInfoByUID(host_mid);
|
||||
|
||||
/**
|
||||
* 储存所有经过整理后信息
|
||||
@ -430,9 +436,12 @@ class Searcher {
|
||||
for (let i = 0; i < pages; i++) {
|
||||
log.info('检查所有动态', `正在读取其中第${i + 1}页动态`);
|
||||
|
||||
const
|
||||
OneDynamicInfo = await hadUidGetOneDynamicInfoByUID(offset),
|
||||
mDRdata = modifyDynamicRes(OneDynamicInfo);
|
||||
// 当 offset 为 '0'(初始页)时,传入 offset 会报错
|
||||
const OneDynamicInfo = offset === '0'
|
||||
? await hadUidGetOneDynamicInfoByUID()
|
||||
: await hadUidGetOneDynamicInfoByUID(offset);
|
||||
|
||||
const mDRdata = modifyDynamicRes(OneDynamicInfo);
|
||||
|
||||
if (mDRdata === null) {
|
||||
return null;
|
||||
|
||||
@ -39,4 +39,5 @@ module.exports = Object.freeze({
|
||||
WEB_INTERFACE_NAV_STAT: 'https://api.bilibili.com/x/web-interface/nav/stat',
|
||||
WEB_INTERFACE_SEARCH_TYPE: 'https://api.bilibili.com/x/web-interface/search/type',
|
||||
X_POLYMER_WEB_DYNAMIC_V1_DETAIL: 'https://api.bilibili.com/x/polymer/web-dynamic/v1/detail',
|
||||
X_POLYMER_WEB_DYNAMIC_V1_FEED_SPACE: 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space',
|
||||
});
|
||||
|
||||
@ -455,14 +455,14 @@ const bili_client = {
|
||||
* @param {string} offset_dynamic_id 此动态偏移量 初始为 0
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
getOneDynamicInfoByUID(host_uid, offset_dynamic_id) {
|
||||
getOneDynamicInfoByUID(host_mid, offset) {
|
||||
/* 鉴别工作交由modifyDynamicRes完成 */
|
||||
/* 新版似乎没有 visitor_uid */
|
||||
return get({
|
||||
url: API.DYNAMIC_SVR_SPACE_HISTORY,
|
||||
url: API.X_POLYMER_WEB_DYNAMIC_V1_FEED_SPACE,
|
||||
query: {
|
||||
visitor_uid: GlobalVar.get('myUID'),
|
||||
host_uid,
|
||||
offset_dynamic_id,
|
||||
host_mid,
|
||||
offset,
|
||||
},
|
||||
config: {
|
||||
retry: false
|
||||
|
||||
Loading…
Reference in New Issue
Block a user