fix(route): change weibo user api (#8095)
There isn't container id in old one with some user Signed-off-by: SettingDust <settingdust@gmail.com>
This commit is contained in:
parent
09dffad27b
commit
de2cfed36f
|
|
@ -2,6 +2,7 @@ const querystring = require('querystring');
|
|||
const got = require('@/utils/got');
|
||||
const weiboUtils = require('./utils');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { fallback, queryToBoolean } = require('@/utils/readable-social');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
|
|
@ -16,26 +17,25 @@ module.exports = async (ctx) => {
|
|||
}
|
||||
}
|
||||
|
||||
const containerResponse = await got({
|
||||
const { data: containerData } = await got({
|
||||
method: 'get',
|
||||
url: `https://m.weibo.cn/api/container/getIndex?type=uid&value=${uid}`,
|
||||
url: `https://m.weibo.cn/profile/info?uid=${uid}`,
|
||||
headers: {
|
||||
Referer: 'https://m.weibo.cn/',
|
||||
},
|
||||
});
|
||||
const name = containerResponse.data.data.userInfo.screen_name;
|
||||
const description = containerResponse.data.data.userInfo.description;
|
||||
const profileImageUrl = containerResponse.data.data.userInfo.profile_image_url;
|
||||
const containerid = containerResponse.data.data.tabsInfo.tabs[1].containerid;
|
||||
const name = containerData.data.user.screen_name;
|
||||
const description = containerData.data.user.description;
|
||||
const profileImageUrl = containerData.data.user.profile_image_url;
|
||||
const containerid = containerData.data.more.match(/\d+/)[0];
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://m.weibo.cn/api/container/getIndex?type=uid&value=${uid}&containerid=${containerid}`,
|
||||
url: `https://m.weibo.cn/api/container/getIndex?containerid=${containerid}`,
|
||||
headers: {
|
||||
Referer: `https://m.weibo.cn/u/${uid}`,
|
||||
'MWeibo-Pwa': 1,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -43,26 +43,17 @@ module.exports = async (ctx) => {
|
|||
response.data.data.cards
|
||||
.filter((item) => item.mblog)
|
||||
.map(async (item) => {
|
||||
let data = {};
|
||||
const key = 'weibo:user:' + item.mblog.bid;
|
||||
const value = await ctx.cache.get(key);
|
||||
if (value) {
|
||||
data = JSON.parse(value);
|
||||
} else {
|
||||
// 可以判断出是否是长微博,如果不是那么不调下边的接口获取完整全文也行,但是拿不到准确的created_at,而是“几小时前”这种
|
||||
// 索性就都再调接口获取详细data了,这个接口只返回json所以性能消耗不大。另外做了缓存处理
|
||||
data = await weiboUtils.getShowData(uid, item.mblog.bid);
|
||||
ctx.cache.set(key, JSON.stringify(data));
|
||||
}
|
||||
const data = await ctx.cache.tryGet(key, () => weiboUtils.getShowData(uid, item.mblog.bid));
|
||||
|
||||
// 是否通过api拿到了data
|
||||
const isDataOK = data !== undefined && data.text;
|
||||
if (isDataOK) {
|
||||
if (data && data.text) {
|
||||
item.mblog.text = data.text;
|
||||
item.mblog.created_at = data.created_at;
|
||||
item.mblog.created_at = parseDate(data.created_at);
|
||||
if (item.mblog.retweeted_status && data.retweeted_status) {
|
||||
item.mblog.retweeted_status.created_at = data.retweeted_status.created_at;
|
||||
}
|
||||
} else {
|
||||
item.mblog.created_at = timezone(item.mblog.created_at, +8);
|
||||
}
|
||||
// 转发的长微博处理
|
||||
const retweet = item.mblog.retweeted_status;
|
||||
|
|
@ -78,21 +69,20 @@ module.exports = async (ctx) => {
|
|||
let description = formatExtended.description;
|
||||
const formattedTitle = formatExtended.title;
|
||||
const title = formattedTitle;
|
||||
const pubDate = isDataOK ? new Date(data.created_at) : timezone(item.mblog.created_at, +8);
|
||||
const pubDate = item.mblog.created_at;
|
||||
|
||||
// 视频的处理
|
||||
if (displayVideo === '1') {
|
||||
description = weiboUtils.formatVideo(description, item.mblog);
|
||||
}
|
||||
|
||||
const it = {
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
link,
|
||||
pubDate,
|
||||
author: item.mblog.user.screen_name,
|
||||
};
|
||||
return Promise.resolve(it);
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue