Add SVG studio image support, and studio image caching (#418)

* Support SVGs for studio images and add ETAGs
* Add SVG to studio image input
* Update content sniffing
This commit is contained in:
InfiniteTF
2020-04-03 00:11:48 +02:00
committed by GitHub
parent aee9df966b
commit 0f622c84f4
4 changed files with 25 additions and 2 deletions

View File

@@ -2,10 +2,13 @@ package api
import (
"context"
"crypto/md5"
"fmt"
"github.com/go-chi/chi"
"github.com/stashapp/stash/pkg/models"
"net/http"
"strconv"
"strings"
)
type studioRoutes struct{}
@@ -23,6 +26,21 @@ func (rs studioRoutes) Routes() chi.Router {
func (rs studioRoutes) Image(w http.ResponseWriter, r *http.Request) {
studio := r.Context().Value(studioKey).(*models.Studio)
etag := fmt.Sprintf("%x", md5.Sum(studio.Image))
if match := r.Header.Get("If-None-Match"); match != "" {
if strings.Contains(match, etag) {
w.WriteHeader(http.StatusNotModified)
return
}
}
contentType := http.DetectContentType(studio.Image)
if contentType == "text/xml; charset=utf-8" || contentType == "text/plain; charset=utf-8" {
contentType = "image/svg+xml"
}
w.Header().Set("Content-Type", contentType)
w.Header().Add("Etag", etag)
_, _ = w.Write(studio.Image)
}