diff options
author | 2022-09-06 12:42:55 +0200 | |
---|---|---|
committer | 2022-09-06 12:42:55 +0200 | |
commit | a872ddebe67c7b76cbb78667224b393a847834ac (patch) | |
tree | 28b7d0081ee12ab9928eff0aecd6b55d32d8228d /internal/processing/admin | |
parent | [bugfix] Catch json syntax errors in the frontend + display a more helpful me... (diff) | |
download | gotosocial-a872ddebe67c7b76cbb78667224b393a847834ac.tar.xz |
[feature] Custom emoji updates (serve emoji via s2s api, tune db models) (#805)
* migrate emojis
* add get emoji to s2s (federation) API
* add new emoji db + cache functions
* add shortcodeDomain lookup for emojis
* check existing emojis w/cache, not w/constraints
* go fmt
* add putEmoji func
* use new db emoji funcs instead of where
* remove emojistringstotags func
* add unique constraint back in
* fix up broken migration
* update index
Diffstat (limited to 'internal/processing/admin')
-rw-r--r-- | internal/processing/admin/emoji.go | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/internal/processing/admin/emoji.go b/internal/processing/admin/emoji.go index 36657a6aa..ffb369493 100644 --- a/internal/processing/admin/emoji.go +++ b/internal/processing/admin/emoji.go @@ -20,7 +20,6 @@ package admin import ( "context" - "errors" "fmt" "io" @@ -37,9 +36,13 @@ func (p *processor) EmojiCreate(ctx context.Context, account *gtsmodel.Account, return nil, gtserror.NewErrorUnauthorized(fmt.Errorf("user %s not an admin", user.ID), "user is not an admin") } - data := func(innerCtx context.Context) (io.Reader, int, error) { - f, err := form.Image.Open() - return f, int(form.Image.Size), err + maybeExisting, err := p.db.GetEmojiByShortcodeDomain(ctx, form.Shortcode, "") + if maybeExisting != nil { + return nil, gtserror.NewErrorConflict(fmt.Errorf("emoji with shortcode %s already exists", form.Shortcode), fmt.Sprintf("emoji with shortcode %s already exists", form.Shortcode)) + } + + if err != nil && err != db.ErrNoEntries { + return nil, gtserror.NewErrorInternalError(fmt.Errorf("error checking existence of emoji with shortcode %s: %s", form.Shortcode, err)) } emojiID, err := id.NewRandomULID() @@ -49,6 +52,11 @@ func (p *processor) EmojiCreate(ctx context.Context, account *gtsmodel.Account, emojiURI := uris.GenerateURIForEmoji(emojiID) + data := func(innerCtx context.Context) (io.Reader, int, error) { + f, err := form.Image.Open() + return f, int(form.Image.Size), err + } + processingEmoji, err := p.mediaManager.ProcessEmoji(ctx, data, nil, form.Shortcode, emojiID, emojiURI, nil) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("error processing emoji: %s", err), "error processing emoji") @@ -56,10 +64,6 @@ func (p *processor) EmojiCreate(ctx context.Context, account *gtsmodel.Account, emoji, err := processingEmoji.LoadEmoji(ctx) if err != nil { - var alreadyExistsError *db.ErrAlreadyExists - if errors.As(err, &alreadyExistsError) { - return nil, gtserror.NewErrorConflict(fmt.Errorf("emoji with shortcode %s already exists", form.Shortcode), fmt.Sprintf("emoji with shortcode %s already exists", form.Shortcode)) - } return nil, gtserror.NewErrorInternalError(fmt.Errorf("error loading emoji: %s", err), "error loading emoji") } |