[APIV4] GET /emoji/{emoji_id}/image for apiV4 (#6141)
* implement GET /emoji/{emoji_id}/image for apiV4
* update per request
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
55bbf15fc7
Коммит
f758f9ff3a
@@ -22,6 +22,7 @@ func InitEmoji() {
|
||||
BaseRoutes.Emojis.Handle("", ApiSessionRequired(getEmojiList)).Methods("GET")
|
||||
BaseRoutes.Emoji.Handle("", ApiSessionRequired(deleteEmoji)).Methods("DELETE")
|
||||
BaseRoutes.Emoji.Handle("", ApiSessionRequired(getEmoji)).Methods("GET")
|
||||
BaseRoutes.Emoji.Handle("/image", ApiSessionRequiredTrustRequester(getEmojiImage)).Methods("GET")
|
||||
}
|
||||
|
||||
func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -129,3 +130,30 @@ func getEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(emoji.ToJson()))
|
||||
}
|
||||
}
|
||||
|
||||
func getEmojiImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireEmojiId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !*utils.Cfg.ServiceSettings.EnableCustomEmoji {
|
||||
c.Err = model.NewAppError("getEmojiImage", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
if len(utils.Cfg.FileSettings.DriverName) == 0 {
|
||||
c.Err = model.NewAppError("getEmojiImage", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
image, imageType, err := app.GetEmojiImage(c.Params.EmojiId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "image/"+imageType)
|
||||
w.Header().Set("Cache-Control", "max-age=2592000, public")
|
||||
w.Write(image)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user