From 1a08c0a17b4ac83680ca0d193e9228e7b4cd5416 Mon Sep 17 00:00:00 2001 From: shanmite Date: Mon, 29 Apr 2024 10:15:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=9D=E9=A2=98uid=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=BD=BF=E7=94=A8=E8=80=81=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/searcher.js | 132 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 1 deletion(-) diff --git a/lib/core/searcher.js b/lib/core/searcher.js index 59eb969..88fa1a7 100644 --- a/lib/core/searcher.js +++ b/lib/core/searcher.js @@ -157,6 +157,136 @@ function parseDynamicCard(ditem) { return obj } +/** + * @param {object} dynamic_detail_card + * @return {UsefulDynamicInfo} + */ +function oldParseDynamicCard(dynamic_detail_card) { + const { strToJson } = utils; + /**临时储存单个动态中的信息 */ + let obj = {}; + const { desc, card, extension, extend_json = "{}", display = {} } = dynamic_detail_card + , { is_liked = 1, user_profile = {} } = desc + , { info = {} } = user_profile + , cardToJson = strToJson(card) + , extendjsonToJson = strToJson(extend_json) + , { add_on_card_info = [] } = display + , { item } = cardToJson; + const dy_type2chat_type = new Map([[1, 17], [2, 11], [4, 17], [8, 1], [64, 12]]); + /* 转发者的UID */ + obj.uid = desc.uid + /* 转发者的name */ + obj.uname = info.uname || '' + /* 动态是否点过赞 */ + obj.is_liked = is_liked > 0 + /* 动态的ts10 */ + obj.create_time = desc.timestamp + /* 动态类型 */ + obj.type = desc.type + /* 用于发送评论 */ + obj.rid_str = desc.rid_str.length > 12 ? desc.dynamic_id_str : desc.rid_str; + /* 用于发送评论 */ + obj.chat_type = dy_type2chat_type.get(obj.type) || 0; + /* 转发者的动态ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */ + obj.dynamic_id = desc.dynamic_id_str; + /* 定位@信息 */ + obj.ctrl = (extendjsonToJson.ctrl) || []; + /* 预约抽奖信息 */ + if (add_on_card_info.length > 0) { + const [status, oid_str, text] = add_on_card_info + .filter(it => typeof it.reserve_attach_card !== 'undefined' + && typeof it.reserve_attach_card.reserve_lottery !== 'undefined' + && typeof it.reserve_attach_card.reserve_button !== 'undefined') + .map(({ reserve_attach_card }) => [ + reserve_attach_card.reserve_button.status, + reserve_attach_card.oid_str, + reserve_attach_card.reserve_lottery.text])[0] || []; + if (status === 1) { + obj.reserve_id = oid_str; + obj.reserve_lottery_text = text; + } + } + if (extendjsonToJson[""]) { + let r = extendjsonToJson[""].reserve || {}; + let { reserve_id, reserve_lottery } = r; + if (reserve_lottery === 1) { + obj.reserve_id = reserve_id + ""; + obj.reserve_lottery_text = "信息丢失"; + } + } + if (extend_json.match(/"":\{"lottery/)) { + obj.is_charge_lottery = true + } + /* 是否有官方抽奖 */ + obj.hasOfficialLottery = extension && extension.lott && true; + /* 转发者的描述 纯文字内容 图片动态描述 后两个分别是视频动态的描述和视频本身的描述*/ + obj.description = + (item && ((item.content || '') + (item.description || ''))) + || ( + (cardToJson.dynamic || '') + + (cardToJson.desc || '') + + (cardToJson.vest && cardToJson.vest.content || '') + ) + || ''; + /* 转发 */ + if (obj.type === 1) { + const { origin_extension, origin, origin_extend_json = "{}" } = cardToJson + , originToJson = strToJson(origin) + , { add_on_card_info = [] } = display.origin || {} + , originExtendjsonToJson = strToJson(origin_extend_json) + , { user, item } = originToJson; + /* 源动态的ts10 */ + obj.origin_create_time = desc.origin.timestamp; + /* 被转发者的UID */ + obj.origin_uid = desc.origin.uid; + /* 源动态类型 */ + obj.origin_type = desc.orig_type + /* 被转发者的rid(用于发评论) */ + obj.origin_rid_str = desc.origin.rid_str.length > 12 ? desc.origin.dynamic_id_str : desc.origin.rid_str; + /* 用于发送评论 */ + obj.origin_chat_type = dy_type2chat_type.get(obj.origin_type) || 0 + /* 被转发者的动态的ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */ + obj.origin_dynamic_id = desc.orig_dy_id_str; + /* 预约抽奖信息 */ + if (add_on_card_info.length > 0) { + const [status, oid_str, text] = add_on_card_info + .filter(it => typeof it.reserve_attach_card !== 'undefined' + && typeof it.reserve_attach_card.reserve_lottery !== 'undefined' + && typeof it.reserve_attach_card.reserve_button !== 'undefined') + .map(({ reserve_attach_card }) => [ + reserve_attach_card.reserve_button.status, + reserve_attach_card.oid_str, + reserve_attach_card.reserve_lottery.text])[0] || []; + if (status === 1) { + obj.origin_reserve_id = oid_str; + obj.origin_reserve_lottery_text = text; + } + } + if (originExtendjsonToJson[""]) { + let r = originExtendjsonToJson[""].reserve || {}; + let { reserve_id, reserve_lottery } = r; + if (reserve_lottery === 1) { + obj.origin_reserve_id = reserve_id + ""; + obj.origin_reserve_lottery_text = "信息丢失"; + } + } + if (origin_extend_json.match(/"":\{"lottery/)) { + obj.origin_is_charge_lottery = true + } + /* 是否有官方抽奖 */ + obj.origin_hasOfficialLottery = origin_extension && origin_extension.lott; + /* 被转发者的name */ + obj.origin_uname = (user && (user.name || user.uname)) || ''; + /* 被转发者的描述 */ + obj.origin_description = + (item && (item.content || '' + item.description || '')) + || (originToJson.dynamic || '' + originToJson.desc || '') + || ''; + } + + return obj +} + /** * 处理来自个人动态或话题页面的一组动态数据 * @param {String} res @@ -197,7 +327,7 @@ function modifyDynamicRes(res) { */ array = next.has_more === 0 ? [] - : cards.map(parseDynamicCard) + : cards.map(oldParseDynamicCard) log.info('处理动态数据', `动态数据读取完毕(${cards.length})(${next.has_more})`);