[feature] Fetch + display custom emoji in statuses from remote instances (#807)

* start implementing remote emoji fetcher

* update status where pk

* aaa

* tidy up a little

* check size limits for emojis

* thank you linter, i love you <3

* update swagger docs

* add emoji dereference test

* make emoji max sizes configurable

* normalize db.ErrAlreadyExists
This commit is contained in:
tobi
2022-09-12 13:03:23 +02:00
committed by GitHub
parent 31639c9b80
commit 268f252e0d
28 changed files with 424 additions and 48 deletions

View File

@ -26,6 +26,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/validate"
@ -56,7 +57,9 @@ import (
// required: true
// - name: image
// in: formData
// description: A png or gif image of the emoji. Animated pngs work too!
// description: |-
// A png or gif image of the emoji. Animated pngs work too!
// To ensure compatibility with other fedi implementations, emoji size limit is 50kb by default.
// type: file
// required: true
//
@ -126,5 +129,10 @@ func validateCreateEmoji(form *model.EmojiCreateRequest) error {
return errors.New("no emoji given")
}
maxSize := config.GetMediaEmojiLocalMaxSize()
if form.Image.Size > int64(maxSize) {
return fmt.Errorf("emoji image too large: image is %dKB but size limit for custom emojis is %dKB", form.Image.Size/1024, maxSize/1024)
}
return validate.EmojiShortcode(form.Shortcode)
}