Use bundled images instead of old webroot files

This commit is contained in:
Gabe Kangas
2022-06-20 21:43:53 -07:00
parent d3a5ebd4be
commit 18a184eeb7
168 changed files with 164 additions and 260 deletions

View File

@@ -2,12 +2,8 @@ package middleware
import (
"net/http"
"os"
"path/filepath"
"strconv"
"github.com/amalfra/etag"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/utils"
)
@@ -22,25 +18,6 @@ func setCacheSeconds(seconds int, w http.ResponseWriter) {
w.Header().Set("Cache-Control", "public, max-age="+secondsStr)
}
// ProcessEtags gets and sets ETags for caching purposes.
func ProcessEtags(w http.ResponseWriter, r *http.Request) int {
info, err := os.Stat(filepath.Join(config.WebRoot, r.URL.Path))
if err != nil {
return 0
}
localContentEtag := etag.Generate(info.ModTime().String(), true)
if remoteEtagHeader := r.Header.Get("If-None-Match"); remoteEtagHeader != "" {
if remoteEtagHeader == localContentEtag {
return http.StatusNotModified
}
}
w.Header().Set("Etag", localContentEtag)
return 0
}
// SetCachingHeaders will set the cache control header of a response.
func SetCachingHeaders(w http.ResponseWriter, r *http.Request) {
setCacheSeconds(utils.GetCacheDurationSecondsForPath(r.URL.Path), w)