Browse Source

Fix: web书架读书章节内容存在多张图片时代理图片url中的bookUrl参数未encodeURIComponent导致的图片无法访问
感谢:@PanicNotPanic、@Panic°
Co-authored-by: 17683954109@163.com <17683954109@163.com>

HapeLee 1 year ago
parent
commit
701f2826b3
1 changed files with 6 additions and 0 deletions
  1. 6 0
      modules/web/src/views/BookChapter.vue

+ 6 - 0
modules/web/src/views/BookChapter.vue

@@ -305,6 +305,12 @@ const getContent = (index: number, reloadChapter = true, chapterPos = 0) => {
         if (res.data.isSuccess) {
           const data = res.data.data
           const content = data.split(/\n+/)
+          const urlEncodedBookUrl = encodeURIComponent(bookUrl)
+          for (let i = 0; i < content.length; i++) {
+            if (!/^\s*<img[^>]*src[^>]+>$/.test(content[i])) {
+              content[i] = content[i].replace(new RegExp('img src="', 'g'), `img src="/image?url=${urlEncodedBookUrl}&path=`);
+            }
+          }
           chapterData.value.push({ index, content, title })
           if (reloadChapter) toChapterPos(chapterPos)
         } else {