File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,9 +2,10 @@ package render
22
33import (
44 "bbs-go/pkg/urls"
5- "github.com/microcosm-cc/bluemonday"
65 "strings"
76
7+ "github.com/microcosm-cc/bluemonday"
8+
89 "github.com/PuerkitoBio/goquery"
910 "github.com/mlogclub/simple"
1011
@@ -56,6 +57,12 @@ func handleHtmlContent(htmlContent string) string {
5657 doc .Find ("img" ).Each (func (i int , selection * goquery.Selection ) {
5758 src := selection .AttrOr ("src" , "" )
5859
60+ // 处理第三方图片
61+ if strings .Contains (src , "qpic.cn" ) {
62+ src = simple .ParseUrl ("/api/img/proxy" ).AddQuery ("url" , src ).BuildStr ()
63+ // selection.SetAttr("src", src)
64+ }
65+
5966 // 处理图片样式
6067 src = HandleOssImageStyleDetail (src )
6168
Original file line number Diff line number Diff line change 77 "strings"
88 "syscall"
99
10+ "github.com/go-resty/resty/v2"
1011 "github.com/iris-contrib/middleware/cors"
1112 "github.com/kataras/iris/v12"
1213 "github.com/kataras/iris/v12/middleware/logger"
@@ -93,6 +94,17 @@ func Router() {
9394 m .Party ("/operate-log" ).Handle (new (admin.OperateLogController ))
9495 })
9596
97+ app .Get ("/api/img/proxy" , func (i iris.Context ) {
98+ url := i .FormValue ("url" )
99+ resp , err := resty .New ().R ().Get (url )
100+ i .Header ("Content-Type" , "image/jpg" )
101+ if err == nil {
102+ _ , _ = i .Write (resp .Body ())
103+ } else {
104+ logrus .Error (err )
105+ }
106+ })
107+
96108 server := & http.Server {Addr : ":" + config .Instance .Port }
97109 handleSignal (server )
98110 err := app .Run (iris .Server (server ), iris .WithConfiguration (iris.Configuration {
You can’t perform that action at this time.
0 commit comments