2024-07-01 21:44:37 -07:00
|
|
|
package handlers
|
2020-08-12 21:56:41 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
2022-06-25 23:06:31 -07:00
|
|
|
"os"
|
2020-08-12 21:56:41 -07:00
|
|
|
"strings"
|
|
|
|
|
2020-10-06 01:07:09 +08:00
|
|
|
"github.com/owncast/owncast/config"
|
2022-12-12 17:40:43 +01:00
|
|
|
"github.com/owncast/owncast/core/data"
|
2024-07-01 20:12:08 -07:00
|
|
|
"github.com/owncast/owncast/webserver/router/middleware"
|
2024-07-01 21:44:37 -07:00
|
|
|
webutils "github.com/owncast/owncast/webserver/utils"
|
2020-08-12 21:56:41 -07:00
|
|
|
)
|
|
|
|
|
2022-12-12 17:40:43 +01:00
|
|
|
// GetCustomEmojiList returns a list of emoji via the API.
|
2022-06-20 21:43:53 -07:00
|
|
|
func GetCustomEmojiList(w http.ResponseWriter, r *http.Request) {
|
2022-12-12 17:40:43 +01:00
|
|
|
emojiList := data.GetEmojiList()
|
2023-06-27 15:05:02 -07:00
|
|
|
middleware.SetCachingHeaders(w, r)
|
2021-07-12 00:34:56 +02:00
|
|
|
|
2020-11-14 18:39:53 -08:00
|
|
|
if err := json.NewEncoder(w).Encode(emojiList); err != nil {
|
2024-07-01 21:44:37 -07:00
|
|
|
webutils.InternalErrorHandler(w, err)
|
2020-11-14 18:39:53 -08:00
|
|
|
}
|
2020-08-12 21:56:41 -07:00
|
|
|
}
|
2022-06-20 21:43:53 -07:00
|
|
|
|
|
|
|
// GetCustomEmojiImage returns a single emoji image.
|
|
|
|
func GetCustomEmojiImage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
path := strings.TrimPrefix(r.URL.Path, "/img/emoji/")
|
2022-06-20 22:12:44 -07:00
|
|
|
r.URL.Path = path
|
2022-06-25 23:06:31 -07:00
|
|
|
|
2022-12-12 17:40:43 +01:00
|
|
|
emojiFS := os.DirFS(config.CustomEmojiPath)
|
2023-06-27 15:05:02 -07:00
|
|
|
middleware.SetCachingHeaders(w, r)
|
2022-12-12 17:40:43 +01:00
|
|
|
http.FileServer(http.FS(emojiFS)).ServeHTTP(w, r)
|
2022-06-20 21:43:53 -07:00
|
|
|
}
|