emoji.go 829 B

1234567891011121314151617181920212223242526272829303132
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "os"
  6. "strings"
  7. "github.com/owncast/owncast/config"
  8. "github.com/owncast/owncast/core/data"
  9. "github.com/owncast/owncast/router/middleware"
  10. )
  11. // GetCustomEmojiList returns a list of emoji via the API.
  12. func GetCustomEmojiList(w http.ResponseWriter, r *http.Request) {
  13. emojiList := data.GetEmojiList()
  14. middleware.SetCachingHeaders(w, r)
  15. if err := json.NewEncoder(w).Encode(emojiList); err != nil {
  16. InternalErrorHandler(w, err)
  17. }
  18. }
  19. // GetCustomEmojiImage returns a single emoji image.
  20. func GetCustomEmojiImage(w http.ResponseWriter, r *http.Request) {
  21. path := strings.TrimPrefix(r.URL.Path, "/img/emoji/")
  22. r.URL.Path = path
  23. emojiFS := os.DirFS(config.CustomEmojiPath)
  24. middleware.SetCachingHeaders(w, r)
  25. http.FileServer(http.FS(emojiFS)).ServeHTTP(w, r)
  26. }