fix(route): fix `/bilibili/user/dynamic` author undefined (#13250)
* fix(route): /bilibili/user/dynamic author is undefined * fix(route): fix regular expression warning * feat(route): add directLink
This commit is contained in:
parent
fb93d3ee9f
commit
e8523c0768
|
|
@ -73,8 +73,7 @@ module.exports = async (ctx) => {
|
|||
const disableEmbed = fallback(undefined, queryToBoolean(routeParams.disableEmbed), false);
|
||||
const displayArticle = ctx.query.mode === 'fulltext';
|
||||
const useAvid = fallback(undefined, queryToBoolean(routeParams.useAvid), false);
|
||||
|
||||
const [author, face] = await cache.getUsernameAndFaceFromUID(ctx, uid);
|
||||
const directLink = fallback(undefined, queryToBoolean(routeParams.directLink), false);
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
|
|
@ -85,6 +84,13 @@ module.exports = async (ctx) => {
|
|||
transformResponse: [(data) => data],
|
||||
});
|
||||
const cards = JSONbig.parse(response.body).data.cards;
|
||||
|
||||
const usernameAndFace = await cache.getUsernameAndFaceFromUID(ctx, uid);
|
||||
const author = usernameAndFace[0] ?? cards[0]?.desc?.user_profile?.info.uname;
|
||||
const face = usernameAndFace[1] ?? cards[0]?.desc?.user_profile?.info?.face;
|
||||
ctx.cache.set(`bili-username-from-uid-${uid}`, author);
|
||||
ctx.cache.set(`bili-userface-from-uid-${uid}`, face);
|
||||
|
||||
const items = await Promise.all(
|
||||
cards.map(async (item) => {
|
||||
const getTitle = (data) => (data ? data.title || data.description || data.content || (data.vest && data.vest.content) || '' : '');
|
||||
|
|
@ -160,12 +166,12 @@ module.exports = async (ctx) => {
|
|||
// emoji
|
||||
let data_content = getDes(data);
|
||||
// 换行处理
|
||||
data_content = data_content.replace(new RegExp('\r\n', 'g'), '<br>').replace(new RegExp('\n', 'g'), '<br>');
|
||||
data_content = data_content.replace(/\r\n/g, '<br>').replace(/\n/g, '<br>');
|
||||
if (item.display.emoji_info && showEmoji) {
|
||||
const emoji = item.display.emoji_info.emoji_details;
|
||||
emoji.forEach((item) => {
|
||||
data_content = data_content.replace(
|
||||
new RegExp(`\\${item.text}`.replace(new RegExp('\\?', 'g'), '\\?'), 'g'),
|
||||
new RegExp(`\\${item.text}`.replace(/\\?/g, '\\?'), 'g'),
|
||||
`<img alt="${item.text}" src="${item.url}"style="margin: -1px 1px 0px; display: inline-block; width: 20px; height: 20px; vertical-align: text-bottom;" title="" referrerpolicy="no-referrer">`
|
||||
);
|
||||
});
|
||||
|
|
@ -178,26 +184,32 @@ module.exports = async (ctx) => {
|
|||
if (data.aid) {
|
||||
const id = useAvid ? `av${data.aid}` : item?.desc?.bvid || item?.desc?.origin?.bvid;
|
||||
url = `https://www.bilibili.com/video/${id}`;
|
||||
directLink && (link = url);
|
||||
return `<br>视频地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
if (data.image_urls) {
|
||||
url = `https://www.bilibili.com/read/cv${data.id}`;
|
||||
directLink && (link = url);
|
||||
return `<br>专栏地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
if (data.upper) {
|
||||
url = `https://www.bilibili.com/audio/au${data.id}`;
|
||||
directLink && (link = url);
|
||||
return `<br>音频地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
if (data.roomid) {
|
||||
url = `https://live.bilibili.com/${data.roomid}`;
|
||||
directLink && (link = url);
|
||||
return `<br>直播间地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
if (data.sketch) {
|
||||
url = data.sketch.target_url;
|
||||
directLink && (link = url);
|
||||
return `<br>活动地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
if (data.url) {
|
||||
url = data.url;
|
||||
directLink && (link = url);
|
||||
return `<br>地址:<a href=${url}>${url}</a>`;
|
||||
}
|
||||
return '';
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
|
|||
| showEmoji | 显示或隐藏表情图片 | 0/1/true/false | false |
|
||||
| disableEmbed | 关闭内嵌视频 | 0/1/true/false | false |
|
||||
| useAvid | 视频链接使用AV号(默认为BV号) | 0/1/true/false | false |
|
||||
| directLink | 使用内容直链 | 0/1/true/false | false |
|
||||
|
||||
用例:`/bilibili/user/dynamic/2267573/showEmoji=1&disableEmbed=1&useAvid=1`
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue