diff --git a/main.go b/main.go index 4ce6111..76f8a03 100644 --- a/main.go +++ b/main.go @@ -40,6 +40,10 @@ func setup_router() *fiber.App { server.Use(logger.New()) server.Use(cache.New( cache.Config{ + Next: func(c *fiber.Ctx) bool { + // Disable cache for settings page + return strings.Contains(c.Path(), "/settings") + }, Expiration: 5 * time.Minute, KeyGenerator: func(c *fiber.Ctx) string { diff --git a/models/helpers.go b/models/helpers.go new file mode 100644 index 0000000..7ebcb0c --- /dev/null +++ b/models/helpers.go @@ -0,0 +1,35 @@ +package models + +import ( + "regexp" + "strings" +) + +func ProxyImage(URL string, target string) string { + + if strings.Contains(URL, "s.pximg.net") { + // This subdomain didn't get proxied + return URL + } + + regex := regexp.MustCompile(`.*?pximg\.net`) + proxy := "https://" + target + + return regex.ReplaceAllString(URL, proxy) +} + +func ProxyShortArtworkSlice(artworks []IllustShort, proxy string) []IllustShort { + for i := range artworks { + artworks[i].Thumbnail = ProxyImage(artworks[i].Thumbnail, proxy) + artworks[i].ArtistAvatar = ProxyImage(artworks[i].ArtistAvatar, proxy) + } + + return artworks +} + +func ProxyCommentsSlice(comments []Comment, proxy string) []Comment { + for i := range comments { + comments[i].Avatar = ProxyImage(comments[i].Avatar, proxy) + } + return comments +} diff --git a/template/settings.jet.html b/template/settings.jet.html index c245796..239c2fe 100644 --- a/template/settings.jet.html +++ b/template/settings.jet.html @@ -1,5 +1,8 @@