Skip to content

Commit a5ba6a0

Browse files
authored
refactor(settings)!: move FilterReadMeScripts to frontend (#2346)
* refactor(settings)!: move FilterReadMeScripts to frontend Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> * chore: run go mod tidy Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> --------- Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent 331f575 commit a5ba6a0

4 files changed

Lines changed: 2 additions & 36 deletions

File tree

‎go.mod‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ require (
168168
github.com/sorairolake/lzip-go v0.3.5 // indirect
169169
github.com/taruti/bytepool v0.0.0-20160310082835-5e3a9ea56543 // indirect
170170
github.com/ulikunitz/xz v0.5.12 // indirect
171-
github.com/yuin/goldmark v1.7.13
172171
go4.org v0.0.0-20260112195520-a5071408f32f
173172
resty.dev/v3 v3.0.0-beta.2 // indirect
174173
)

‎go.sum‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,6 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJu
668668
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
669669
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
670670
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
671-
github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA=
672-
github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
673671
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
674672
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
675673
github.com/zzzhr1990/go-common-entity v0.0.0-20250202070650-1a200048f0d3 h1:PSRwrE5QBufPnOjdgIkRs5KBV1Avq3SY8oksj2Z+k3o=

‎internal/bootstrap/data/setting.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func InitialSettings() []model.SettingItem {
153153
{Key: conf.SharePreviewDownloadByDefault, Value: "true", Type: conf.TypeBool, Group: model.PREVIEW},
154154
{Key: conf.SharePreviewArchivesByDefault, Value: "false", Type: conf.TypeBool, Group: model.PREVIEW},
155155
{Key: conf.ReadMeAutoRender, Value: "true", Type: conf.TypeBool, Group: model.PREVIEW},
156-
{Key: conf.FilterReadMeScripts, Value: "true", Type: conf.TypeBool, Group: model.PREVIEW},
156+
{Key: conf.FilterReadMeScripts, Value: "true", Type: conf.TypeBool, Group: model.PREVIEW}, // frontend
157157
{Key: conf.NonEFSZipEncoding, Value: "IBM437", Type: conf.TypeString, Group: model.PREVIEW},
158158
// global settings
159159
{Key: conf.HideFiles, Value: "/\\/README.md/i", Type: conf.TypeText, Group: model.GLOBAL},

‎server/handles/down.go‎

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

33
import (
4-
"bytes"
54
"errors"
6-
"fmt"
75
stdpath "path"
8-
"strconv"
96

107
"github.com/OpenListTeam/OpenList/v4/internal/conf"
118
"github.com/OpenListTeam/OpenList/v4/internal/driver"
@@ -17,9 +14,7 @@ import (
1714
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
1815
"github.com/OpenListTeam/OpenList/v4/server/common"
1916
"github.com/gin-gonic/gin"
20-
"github.com/microcosm-cc/bluemonday"
2117
log "github.com/sirupsen/logrus"
22-
"github.com/yuin/goldmark"
2318
)
2419

2520
func Down(c *gin.Context) {
@@ -115,33 +110,7 @@ func proxy(c *gin.Context, link *model.Link, file model.Obj, proxyRange bool) {
115110
link = common.ProxyRange(c, link, file.GetSize())
116111
}
117112
Writer := &common.WrittenResponseWriter{ResponseWriter: c.Writer}
118-
raw, _ := strconv.ParseBool(c.DefaultQuery("raw", "false"))
119-
if utils.Ext(file.GetName()) == "md" && setting.GetBool(conf.FilterReadMeScripts) && !raw {
120-
buf := bytes.NewBuffer(make([]byte, 0, file.GetSize()))
121-
w := &common.InterceptResponseWriter{ResponseWriter: Writer, Writer: buf}
122-
err = common.Proxy(w, c.Request, link, file)
123-
if err == nil && buf.Len() > 0 {
124-
if c.Writer.Status() < 200 || c.Writer.Status() > 300 {
125-
c.Writer.Write(buf.Bytes())
126-
return
127-
}
128-
129-
var html bytes.Buffer
130-
if err = goldmark.Convert(buf.Bytes(), &html); err != nil {
131-
err = fmt.Errorf("markdown conversion failed: %w", err)
132-
} else {
133-
buf.Reset()
134-
err = bluemonday.UGCPolicy().SanitizeReaderToWriter(&html, buf)
135-
if err == nil {
136-
Writer.Header().Set("Content-Length", strconv.FormatInt(int64(buf.Len()), 10))
137-
Writer.Header().Set("Content-Type", "text/html; charset=utf-8")
138-
_, err = utils.CopyWithBuffer(Writer, buf)
139-
}
140-
}
141-
}
142-
} else {
143-
err = common.Proxy(Writer, c.Request, link, file)
144-
}
113+
err = common.Proxy(Writer, c.Request, link, file)
145114
if err == nil {
146115
return
147116
}

0 commit comments

Comments
 (0)