From a7b9e90fab3d8bd615a851f876493d13224dede3 Mon Sep 17 00:00:00 2001 From: Nova Kwok Date: Fri, 21 Jul 2023 15:35:30 +0800 Subject: [PATCH] Add SVG support for proxy mode (#258) * Add SVG support * Bump version --- config/config.go | 2 +- go.mod | 1 + go.sum | 2 ++ helper/helper.go | 7 +++++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index aed1b96..8872184 100644 --- a/config/config.go +++ b/config/config.go @@ -58,7 +58,7 @@ var ( ProxyMode bool Prefetch bool Config jsonFile - Version = "0.9.7" + Version = "0.9.8" WriteLock = cache.New(5*time.Minute, 10*time.Minute) ) diff --git a/go.mod b/go.mod index 095d841..036e519 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/andybalholm/brotli v1.0.5 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/uuid v1.3.0 // indirect + github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c // indirect github.com/klauspost/compress v1.16.3 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect diff --git a/go.sum b/go.sum index 3c303ac..a8fb305 100644 --- a/go.sum +++ b/go.sum @@ -15,6 +15,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= +github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c h1:fEE5/5VNnYUoBOj2I9TP8Jc+a7lge3QWn9DKE7NCwfc= +github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c/go.mod h1:ObS/W+h8RYb1Y7fYivughjxojTmIu5iAIjSrSLCLeqE= github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= github.com/klauspost/compress v1.16.3 h1:XuJt9zzcnaz6a16/OU53ZjWp/v7/42WcR5t2a0PcNQY= github.com/klauspost/compress v1.16.3/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= diff --git a/helper/helper.go b/helper/helper.go index 32cddc7..5d81c1d 100644 --- a/helper/helper.go +++ b/helper/helper.go @@ -14,9 +14,16 @@ import ( "github.com/cespare/xxhash" "github.com/valyala/fasthttp" + svg "github.com/h2non/go-is-svg" log "github.com/sirupsen/logrus" ) +var _ = filetype.AddMatcher(filetype.NewType("svg", "image/svg+xml"), svgMatcher) + +func svgMatcher(buf []byte) bool { + return svg.Is(buf) +} + func GetFileContentType(filename string) string { if strings.HasSuffix(filename, ".webp") { return "image/webp"