[APIV4] GET /emoji/{emoji_id}/image for apiV4 (#6141)
* implement GET /emoji/{emoji_id}/image for apiV4
* update per request
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
55bbf15fc7
Коммит
f758f9ff3a
23
app/emoji.go
23
app/emoji.go
@@ -6,7 +6,6 @@ package app
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
"image/color/palette"
|
||||
"image/draw"
|
||||
"image/gif"
|
||||
_ "image/jpeg"
|
||||
@@ -20,6 +19,7 @@ import (
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"image/color/palette"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -148,6 +148,27 @@ func GetEmoji(emojiId string) (*model.Emoji, *model.AppError) {
|
||||
}
|
||||
}
|
||||
|
||||
func GetEmojiImage(emojiId string) (imageByte []byte, imageType string, err *model.AppError) {
|
||||
if result := <-Srv.Store.Emoji().Get(emojiId, true); result.Err != nil {
|
||||
return nil, "", result.Err
|
||||
} else {
|
||||
var img []byte
|
||||
|
||||
if data, err := ReadFile(getEmojiImagePath(emojiId)); err != nil {
|
||||
return nil, "", model.NewAppError("getEmojiImage", "api.emoji.get_image.read.app_error", nil, err.Error(), http.StatusNotFound)
|
||||
} else {
|
||||
img = data
|
||||
}
|
||||
|
||||
_, imageType, err := image.DecodeConfig(bytes.NewReader(img))
|
||||
if err != nil {
|
||||
return nil, "", model.NewAppError("getEmojiImage", "api.emoji.get_image.decode.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return img, imageType, nil
|
||||
}
|
||||
}
|
||||
|
||||
func resizeEmojiGif(gifImg *gif.GIF) *gif.GIF {
|
||||
// Create a new RGBA image to hold the incremental frames.
|
||||
firstFrame := gifImg.Image[0].Bounds()
|
||||
|
||||
Ссылка в новой задаче
Block a user