8.3
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -49,20 +49,22 @@ export function parseHtmlWithVideo(richText) {
|
||||
* @returns {Promise} 转换后的富文本 注意异步处理
|
||||
*/
|
||||
export async function replaceVideoWithImageRender(richText, customCallback) {
|
||||
|
||||
console.log(1);
|
||||
// 正则表达式用于匹配 <video> 标签以及其内部的 <source> 标签
|
||||
const videoRegex = /<video\s+([^>]+)>(.*?)<\/video>/gi;
|
||||
|
||||
console.log(2);
|
||||
// 找到所有的 <video> 标签
|
||||
const matches = [];
|
||||
let match;
|
||||
while ((match = videoRegex.exec(richText)) !== null) {
|
||||
matches.push(match);
|
||||
}
|
||||
|
||||
console.log(3);
|
||||
// 并行处理每个 <video> 标签,生成对应的缩略图
|
||||
const replacements = await Promise.all(
|
||||
|
||||
matches.map(async (match) => {
|
||||
console.log(5);
|
||||
const [fullMatch, attributes, content] = match;
|
||||
|
||||
// 匹配 <source> 标签中的 src 属性
|
||||
@@ -75,28 +77,34 @@ export async function replaceVideoWithImageRender(richText, customCallback) {
|
||||
}
|
||||
|
||||
// 生成视频封面图
|
||||
console.log('5-1')
|
||||
let thumbnailRes
|
||||
if (customCallback) thumbnailRes = await customCallback(videoUrl) // 自定义封面处理
|
||||
if (!thumbnailRes) thumbnailRes = config.video_thumbnail // 无效值则默认封面处理
|
||||
|
||||
//if (customCallback) thumbnailRes = await customCallback(videoUrl)
|
||||
console.log('5-2')
|
||||
// 自定义封面处理
|
||||
//if (!thumbnailRes) thumbnailRes = config.video_thumbnail // 无效值则默认封面处理
|
||||
console.log('5-3')
|
||||
thumbnailRes="https://caseplatform.oss-cn-beijing.aliyuncs.com/prod/static/shipinfengmian.jpg"
|
||||
// 过滤掉不需要的属性,例如 controls
|
||||
const filteredAttributes = attributes
|
||||
.split(/\s+/)
|
||||
.filter(attr => !attr.startsWith('controls'))
|
||||
.join(' ');
|
||||
|
||||
.join(' ').replace('src=','').replace("").replaceAll('width="100%"','').replaceAll('"','').replace(/\s+/g, "");;
|
||||
console.log('5-4')
|
||||
// 构建新的 img 标签,继承 video 的属性(除了 controls)并添加 data-custom 属性
|
||||
const imgTag = `<img ${filteredAttributes} src="${thumbnailRes}" data-custom="url=${videoUrl}" />`;
|
||||
|
||||
const imgTag = `<img src="${thumbnailRes}" data-custom="url=${filteredAttributes}">`;
|
||||
console.log(6);
|
||||
return { fullMatch, imgTag };
|
||||
}));
|
||||
|
||||
console.log(7);
|
||||
// 使用 replacements 替换原始的 <video> 标签
|
||||
let result = richText;
|
||||
for (const { fullMatch, imgTag } of replacements) {
|
||||
console.log(8);
|
||||
result = result.replace(fullMatch, imgTag);
|
||||
}
|
||||
|
||||
console.log("打印结果2")
|
||||
console.log(result)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user