Support a custom emoji override directory. Closes #1967

This commit is contained in:
Gabe Kangas
2022-06-25 23:06:31 -07:00
parent bb1c934c4b
commit 97db93e0d7
3 changed files with 26 additions and 6 deletions

View File

@@ -4,23 +4,31 @@ import (
"encoding/json"
"io/fs"
"net/http"
"os"
"path/filepath"
"strings"
"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()))
var useCustomEmojiDirectory = utils.DoesFileExists(config.CustomEmojiPath)
// getCustomEmojiList returns a list of custom emoji either from the cache or from the emoji directory.
func getCustomEmojiList() []models.CustomEmoji {
bundledEmoji := static.GetEmoji()
var emojiFS fs.FS
if useCustomEmojiDirectory {
emojiFS = os.DirFS(config.CustomEmojiPath)
} else {
emojiFS = static.GetEmoji()
}
emojiResponse := make([]models.CustomEmoji, 0)
files, err := fs.Glob(bundledEmoji, "*")
files, err := fs.Glob(emojiFS, "*")
if err != nil {
log.Errorln(err)
return emojiResponse
@@ -48,5 +56,14 @@ func GetCustomEmojiList(w http.ResponseWriter, r *http.Request) {
func GetCustomEmojiImage(w http.ResponseWriter, r *http.Request) {
path := strings.TrimPrefix(r.URL.Path, "/img/emoji/")
r.URL.Path = path
var emojiStaticServer http.Handler
if useCustomEmojiDirectory {
emojiFS := os.DirFS(config.CustomEmojiPath)
emojiStaticServer = http.FileServer(http.FS(emojiFS))
} else {
emojiStaticServer = http.FileServer(http.FS(static.GetEmoji()))
}
emojiStaticServer.ServeHTTP(w, r)
}