fix(route): bilibili dynamic (#10815)

* fix(route): bilibili dynamic error when emoji contains ?

修复bilibili动态在特定表情下会产生正则表达式错误的问题

* fix(route): bilibili dynamic change line

修复bilibili态内容换行问题

* fix: deepscan warning
This commit is contained in:
ColdThunder11 2022-09-17 21:24:28 +08:00 committed by GitHub
parent c9ccdb410b
commit 18b34fce71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -1,6 +1,7 @@
const got = require('@/utils/got');
const JSONbig = require('json-bigint');
const utils = require('./utils');
const { parseDate } = require('@/utils/parse-date');
/**
@by CaoMeiYouRen 2020-05-05 添加注释
@ -155,11 +156,13 @@ 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>');
if (item.display.emoji_info) {
const emoji = item.display.emoji_info.emoji_details;
emoji.forEach((item) => {
data_content = data_content.replace(
new RegExp(`\\${item.text}`, 'g'),
new RegExp(`\\${item.text}`.replace(new RegExp('\\?', '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">`
);
});
@ -198,7 +201,7 @@ module.exports = async (ctx) => {
const videoHTMLSource = videoHTML ? `<br>${videoHTML}` : '';
return `${description}${originName}<br>${getUrl(data)}${getUrl(origin)}${getIframe(data)}${getIframe(origin)}${imgHTMLSource}${videoHTMLSource}`;
})(),
pubDate: new Date(item.desc.timestamp * 1000),
pubDate: item.desc ? (item.desc.timestamp ? parseDate(item.desc.timestamp, 'X') : null) : null,
link,
};
}),