mirror of
https://github.com/owncast/owncast.git
synced 2025-11-02 11:56:57 +08:00
Feature: emoji editor (#2411)
* Custom emoji editor: implement backend This reuses the logo upload code * Implement emoji edit admin interface Again reuse base64 logic from the logo upload * Allow toggling between uploaded and default emojis * Add route that always serves uploaded emojis This is needed for the admin emoji interface, as otherwise the emojis will 404 if custom emojis are disabled * Fix linter warnings * Remove custom/uploaded emoji logic * Reset timer after emoji deletion * Setup: copy built-in emojis to emoji directory
This commit is contained in:
@ -2,50 +2,17 @@ package controllers
|
||||
|
||||
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"
|
||||
"github.com/owncast/owncast/core/data"
|
||||
)
|
||||
|
||||
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 {
|
||||
var emojiFS fs.FS
|
||||
if useCustomEmojiDirectory {
|
||||
emojiFS = os.DirFS(config.CustomEmojiPath)
|
||||
} else {
|
||||
emojiFS = static.GetEmoji()
|
||||
}
|
||||
|
||||
emojiResponse := make([]models.CustomEmoji, 0)
|
||||
|
||||
files, err := fs.Glob(emojiFS, "*")
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return emojiResponse
|
||||
}
|
||||
|
||||
for _, name := range files {
|
||||
emojiPath := filepath.Join(config.EmojiDir, name)
|
||||
singleEmoji := models.CustomEmoji{Name: name, URL: emojiPath}
|
||||
emojiResponse = append(emojiResponse, singleEmoji)
|
||||
}
|
||||
|
||||
return emojiResponse
|
||||
}
|
||||
|
||||
// GetCustomEmojiList returns a list of custom emoji via the API.
|
||||
// GetCustomEmojiList returns a list of emoji via the API.
|
||||
func GetCustomEmojiList(w http.ResponseWriter, r *http.Request) {
|
||||
emojiList := getCustomEmojiList()
|
||||
emojiList := data.GetEmojiList()
|
||||
|
||||
if err := json.NewEncoder(w).Encode(emojiList); err != nil {
|
||||
InternalErrorHandler(w, err)
|
||||
@ -57,13 +24,6 @@ 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)
|
||||
emojiFS := os.DirFS(config.CustomEmojiPath)
|
||||
http.FileServer(http.FS(emojiFS)).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user