From 130fbd52dd1c01ef79b2699851bc6cecdff5b61d Mon Sep 17 00:00:00 2001 From: VnPower Date: Wed, 14 Feb 2024 10:02:10 +0700 Subject: [PATCH] Fix ranking calendar images #57 --- core/config/session.go | 8 ++++++++ core/webapi/rankingCalendar.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/config/session.go b/core/config/session.go index 6e3ebe9..58d5163 100644 --- a/core/config/session.go +++ b/core/config/session.go @@ -34,6 +34,14 @@ func ProxyImageUrl(c *fiber.Ctx, s string) string { return s } +func ProxyImageUrlNoEscape(c *fiber.Ctx, s string) string { + proxy := GetImageProxy(c) + s = strings.ReplaceAll(s, `https://i.pximg.net`, "https://"+proxy) + // s = strings.ReplaceAll(s, `https:\/\/i.pximg.net`, "/proxy/i.pximg.net") + s = strings.ReplaceAll(s, `https://s.pximg.net`, "/proxy/s.pximg.net") + return s +} + func GetImageProxy(c *fiber.Ctx) string { sess, err := Store.Get(c) if err != nil { diff --git a/core/webapi/rankingCalendar.go b/core/webapi/rankingCalendar.go index 672c46c..4b369d3 100644 --- a/core/webapi/rankingCalendar.go +++ b/core/webapi/rankingCalendar.go @@ -64,7 +64,7 @@ func GetRankingCalendar(c *fiber.Ctx, mode string, year, month int) (template.HT for _, a := range n.Attr { if a.Key == "data-src" { // adds a new link entry when the attribute matches - links = append(links, session.ProxyImageUrl(c, a.Val)) + links = append(links, session.ProxyImageUrlNoEscape(c, a.Val)) } } }