Use static servers for serving embedded web assets

This commit is contained in:
Gabe Kangas
2022-06-20 22:12:44 -07:00
parent 18a184eeb7
commit 9c477e16a2
4 changed files with 10 additions and 90 deletions

View File

@@ -10,10 +10,11 @@ import (
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/models"
"github.com/owncast/owncast/static"
"github.com/owncast/owncast/utils"
log "github.com/sirupsen/logrus"
)
var emojiStaticServer = http.FileServer(http.FS(static.GetEmoji()))
// getCustomEmojiList returns a list of custom emoji either from the cache or from the emoji directory.
func getCustomEmojiList() []models.CustomEmoji {
bundledEmoji := static.GetEmoji()
@@ -45,17 +46,7 @@ func GetCustomEmojiList(w http.ResponseWriter, r *http.Request) {
// GetCustomEmojiImage returns a single emoji image.
func GetCustomEmojiImage(w http.ResponseWriter, r *http.Request) {
bundledEmoji := static.GetEmoji()
path := strings.TrimPrefix(r.URL.Path, "/img/emoji/")
b, err := fs.ReadFile(bundledEmoji, path)
if err != nil {
log.Errorln(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
contentType := "image/jpeg"
cacheTime := utils.GetCacheDurationSecondsForPath(path)
writeBytesAsImage(b, contentType, w, cacheTime)
r.URL.Path = path
emojiStaticServer.ServeHTTP(w, r)
}