owncast/controllers/emoji.go
Gabe Kangas 68ff9ff270
Merge of emoji + autolink + embed + etc (#108)
* Add an emoji picker to chat

* Update to the custom emoji picker and add first pass at using custom emoji in text box

* Add custom emoji endpoint and use it in the app

* Position the emoji picker

* Handle events from the text input

* pair down the number of party parrots

* Size emoji in chat and input

* Add new custom emoji

* Add OMQ stickers as custom emoji

* Show custom category for emoji picker by default

* update omq emojis

* Document basic supported markdown syntax. Closes #95

* Websocket refactor: Pull it out of the UI and support callbacks (#104)

* Websocket refactor: Pull it out of the UI and support listeners

* Changes required for Safari to be happy with modules

* Move to explicit ad-hoc callback registration

* Add an emoji picker to chat

* Update to the custom emoji picker and add first pass at using custom emoji in text box

* Handle events from the text input

* Rebuild autolinking + embed handling for #93

* Re-enable disabling chat

* Document basic supported markdown syntax. Closes #95

* Document basic supported markdown syntax. Closes #95

* Add an emoji picker to chat

* Merge emoji and embeds.

* Merge emoji + embed branches. Rework autolink +embeds. WIP for username
highlighting for #100

* More updates to chat text formatting/embedding/linking

* Fix username autocomplete to work with div instead of form elements

* Post-rebase fixes + tweaks

* Disable text input by setting contentEditable = false

* Remove test that hardcodes pointing to public test server

* Fix re-enable chat with the contentEditable input div

* Style and fix the fake placeholder text in the input div

* Missing file.  Were did it go?

* Set a height for instagram embeds

* Cleanup

Co-authored-by: Ginger Wong <omqmail@gmail.com>
2020-08-12 21:56:41 -07:00

42 lines
1.1 KiB
Go

package controllers
import (
"encoding/json"
"io/ioutil"
"net/http"
"path"
"path/filepath"
"strings"
"github.com/gabek/owncast/models"
log "github.com/sirupsen/logrus"
)
// Make this path configurable if somebody has a valid reason
// to need it to be. The config is getting a bit bloated.
const emojiPath = "/img/emoji" // Relative to webroot
//GetCustomEmoji returns a list of custom emoji via the API
func GetCustomEmoji(w http.ResponseWriter, r *http.Request) {
emojiList := make([]models.CustomEmoji, 0)
fullPath := filepath.Join("webroot", emojiPath)
files, err := ioutil.ReadDir(fullPath)
if err != nil {
log.Errorln(err)
// Throw HTTP 500
return
}
// Memoize this result somewhere? Right now it iterates through the
// filesystem every time the API is hit. Should you need to restart
// the server to add emoji?
for _, f := range files {
name := strings.TrimSuffix(f.Name(), path.Ext(f.Name()))
path := filepath.Join(emojiPath, f.Name())
singleEmoji := models.CustomEmoji{name, path}
emojiList = append(emojiList, singleEmoji)
}
json.NewEncoder(w).Encode(emojiList)
}