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