diff --git a/lib/v2/bilibili/dynamic.js b/lib/v2/bilibili/dynamic.js index e151c8b06..343f1ab33 100644 --- a/lib/v2/bilibili/dynamic.js +++ b/lib/v2/bilibili/dynamic.js @@ -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'), '
').replace(new RegExp('\n', 'g'), '
'); + data_content = data_content.replace(/\r\n/g, '
').replace(/\n/g, '
'); 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'), `${item.text}` ); }); @@ -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 `
视频地址:${url}`; } if (data.image_urls) { url = `https://www.bilibili.com/read/cv${data.id}`; + directLink && (link = url); return `
专栏地址:${url}`; } if (data.upper) { url = `https://www.bilibili.com/audio/au${data.id}`; + directLink && (link = url); return `
音频地址:${url}`; } if (data.roomid) { url = `https://live.bilibili.com/${data.roomid}`; + directLink && (link = url); return `
直播间地址:${url}`; } if (data.sketch) { url = data.sketch.target_url; + directLink && (link = url); return `
活动地址:${url}`; } if (data.url) { url = data.url; + directLink && (link = url); return `
地址:${url}`; } return ''; diff --git a/website/docs/routes/social-media.md b/website/docs/routes/social-media.md index 7c2fa0f5c..9561a72da 100644 --- a/website/docs/routes/social-media.md +++ b/website/docs/routes/social-media.md @@ -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`