MM-54640 Add API to get multiple emojis by name at once (#24651)
* MM-54640 Add API to get multiple emojis by name at once * Fix status code when too many names are requested * Address feedback * Update unit tests * Fix styling * Fix more styling * Fix mismatched i18n id
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
77cc356d46
Коммит
3d0fd16666
@@ -17,11 +17,13 @@ import (
|
||||
|
||||
const (
|
||||
EmojiMaxAutocompleteItems = 100
|
||||
GetEmojisByNamesMax = 200
|
||||
)
|
||||
|
||||
func (api *API) InitEmoji() {
|
||||
api.BaseRoutes.Emojis.Handle("", api.APISessionRequired(createEmoji)).Methods("POST")
|
||||
api.BaseRoutes.Emojis.Handle("", api.APISessionRequired(getEmojiList)).Methods("GET")
|
||||
api.BaseRoutes.Emojis.Handle("/names", api.APISessionRequired(getEmojisByNames)).Methods("POST")
|
||||
api.BaseRoutes.Emojis.Handle("/search", api.APISessionRequired(searchEmojis)).Methods("POST")
|
||||
api.BaseRoutes.Emojis.Handle("/autocomplete", api.APISessionRequired(autocompleteEmojis)).Methods("GET")
|
||||
api.BaseRoutes.Emoji.Handle("", api.APISessionRequired(deleteEmoji)).Methods("DELETE")
|
||||
@@ -221,6 +223,11 @@ func getEmojiByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !*c.App.Config().ServiceSettings.EnableCustomEmoji {
|
||||
c.Err = model.NewAppError("getEmojiByName", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
emoji, err := c.App.GetEmojiByName(c.AppContext, c.Params.EmojiName)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
@@ -232,6 +239,36 @@ func getEmojiByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func getEmojisByNames(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
names := model.ArrayFromJSON(r.Body)
|
||||
if len(names) == 0 {
|
||||
c.SetInvalidParam("names")
|
||||
return
|
||||
}
|
||||
|
||||
if !*c.App.Config().ServiceSettings.EnableCustomEmoji {
|
||||
c.Err = model.NewAppError("getEmojisByNames", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
if len(names) > GetEmojisByNamesMax {
|
||||
c.Err = model.NewAppError("getEmojisByNames", "api.emoji.get_multiple_by_name_too_many.request_error", map[string]any{
|
||||
"MaxNames": GetEmojisByNamesMax,
|
||||
}, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
emojis, err := c.App.GetMultipleEmojiByName(c.AppContext, names)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(emojis); err != nil {
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func getEmojiImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireEmojiId()
|
||||
if c.Err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user