master
lion 8 months ago
parent fc9c22e27f
commit 304bdb993d

@ -370,10 +370,19 @@
if (!content || typeof content !== 'string') { if (!content || typeof content !== 'string') {
return content; return content;
} }
// 替换 ../storage/files/ 开头的路径(先处理相对路径,避免和绝对路径冲突) // 替换 ../storage/files/ 开头的路径(相对路径)
content = content.replace(/(["'=:])(\.\.\/storage\/files\/)([^"'\s<>]+)/g, `$1${this.baseUrl}/storage/files/$3`); content = content.replace(/(["'=])(\.\.\/storage\/files\/)([^"'\s<>]+)/g, `$1${this.baseUrl}/storage/files/$3`);
// 替换 /storage/files/ 开头的路径 // 替换 /storage/files/ 开头的路径(排除http://或https://后的完整URL)
content = content.replace(/(["'=:])(\/storage\/files\/)([^"'\s<>]+)/g, `$1${this.baseUrl}/storage/files/$3`); content = content.replace(/(["'=])(\/storage\/files\/)([^"'\s<>]+)/g, function(match, p1, p2, p3, offset, string) {
// 检查前面是否有http://或https://(最多往前检查30个字符)
var beforeMatch = string.substring(Math.max(0, offset - 30), offset);
// 如果前面有完整的URL协议,说明已经是完整URL,不替换
if (/https?:\/\/[^"'\s<>]*$/.test(beforeMatch)) {
return match;
}
// 否则替换为完整URL
return p1 + this.baseUrl + '/storage/files/' + p3;
}.bind(this));
return content; return content;
}, },
// 跳转微信客服 // 跳转微信客服

Loading…
Cancel
Save