diff --git a/config/constants.go b/config/constants.go index 5a5d57f22..d851f75a1 100644 --- a/config/constants.go +++ b/config/constants.go @@ -4,12 +4,12 @@ import "path/filepath" const ( // StaticVersionNumber is the version of Owncast that is used when it's not overwritten via build-time settings. - StaticVersionNumber = "0.0.12" // Shown when you build from develop + StaticVersionNumber = "0.1.0" // Shown when you build from develop // FfmpegSuggestedVersion is the version of ffmpeg we suggest. FfmpegSuggestedVersion = "v4.1.5" // Requires the v // DataDirectory is the directory we save data to. DataDirectory = "data" - // EmojiDir is relative to the webroot. + // EmojiDir is relative to the static directory. EmojiDir = "/img/emoji" ) @@ -19,4 +19,7 @@ var ( // HLSStoragePath is the directory HLS video is written to. HLSStoragePath = filepath.Join(DataDirectory, "hls") + + // CustomEmojiPath is the optional emoji override directory. + CustomEmojiPath = filepath.Join(DataDirectory, "emoji") ) diff --git a/controllers/emoji.go b/controllers/emoji.go index a7de3023f..bb0e9f04b 100644 --- a/controllers/emoji.go +++ b/controllers/emoji.go @@ -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) } diff --git a/router/router.go b/router/router.go index 0c4f0998e..20a5b157f 100644 --- a/router/router.go +++ b/router/router.go @@ -37,7 +37,7 @@ func Start() error { http.HandleFunc("/logo", controllers.GetLogo) // Return a single emoji image. - http.HandleFunc("/img/emoji/", middleware.RequireAdminAuth(controllers.GetCustomEmojiImage)) + http.HandleFunc("/img/emoji/", controllers.GetCustomEmojiImage) // return the logo