Skip to content

Commit aa704fb

Browse files
committed
fix(handles): fixed an issue where markdown files were automatically parsed into html when using the proxy
1 parent 630cf30 commit aa704fb

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

server/handles/down.go

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package handles
22

33
import (
4-
"bytes"
54
"fmt"
65
"io"
76
stdpath "path"
8-
"strconv"
97
"strings"
108

119
"github.com/alist-org/alist/v3/internal/conf"
@@ -17,9 +15,7 @@ import (
1715
"github.com/alist-org/alist/v3/pkg/utils"
1816
"github.com/alist-org/alist/v3/server/common"
1917
"github.com/gin-gonic/gin"
20-
"github.com/microcosm-cc/bluemonday"
2118
log "github.com/sirupsen/logrus"
22-
"github.com/yuin/goldmark"
2319
)
2420

2521
func Down(c *gin.Context) {
@@ -130,34 +126,9 @@ func localProxy(c *gin.Context, link *model.Link, file model.Obj, proxyRange boo
130126
}
131127
Writer := &common.WrittenResponseWriter{ResponseWriter: c.Writer}
132128

133-
//优先处理md文件
134-
if utils.Ext(file.GetName()) == "md" && setting.GetBool(conf.FilterReadMeScripts) {
135-
buf := bytes.NewBuffer(make([]byte, 0, file.GetSize()))
136-
w := &common.InterceptResponseWriter{ResponseWriter: Writer, Writer: buf}
137-
err = common.Proxy(w, c.Request, link, file)
138-
if err == nil && buf.Len() > 0 {
139-
if c.Writer.Status() < 200 || c.Writer.Status() > 300 {
140-
c.Writer.Write(buf.Bytes())
141-
return
142-
}
143-
144-
var html bytes.Buffer
145-
if err = goldmark.Convert(buf.Bytes(), &html); err != nil {
146-
err = fmt.Errorf("markdown conversion failed: %w", err)
147-
} else {
148-
buf.Reset()
149-
err = bluemonday.UGCPolicy().SanitizeReaderToWriter(&html, buf)
150-
if err == nil {
151-
Writer.Header().Set("Content-Length", strconv.FormatInt(int64(buf.Len()), 10))
152-
Writer.Header().Set("Content-Type", "text/html; charset=utf-8")
153-
_, err = utils.CopyWithBuffer(Writer, buf)
154-
}
155-
}
156-
}
157-
} else {
158-
err = common.Proxy(Writer, c.Request, link, file)
159-
}
160-
if err == nil {
129+
// 删除了优先处理md文件的部分,这会导致下载出的markdown文件是被解析过的
130+
// Removed the part that prioritizes md files, which causes the downloaded markdown file parsed to HTML.
131+
if err = common.Proxy(Writer, c.Request, link, file); err == nil {
161132
return
162133
}
163134
if Writer.IsWritten() {

0 commit comments

Comments
 (0)