summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
authorLibravatar tsmethurst <tobi.smethurst@protonmail.com>2022-01-08 17:17:01 +0100
committerLibravatar tsmethurst <tobi.smethurst@protonmail.com>2022-01-08 17:17:01 +0100
commitf61c3ddcf72ff689b9d253546c58d499b6fe6ac8 (patch)
treeb418d5a833f0e3b92b255e73efa98007eb8127ac /internal/processing
parentfurther refinements (diff)
downloadgotosocial-f61c3ddcf72ff689b9d253546c58d499b6fe6ac8.tar.xz
compiling now
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/account/update.go47
-rw-r--r--internal/processing/admin/emoji.go13
-rw-r--r--internal/processing/media/create.go11
3 files changed, 38 insertions, 33 deletions
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index 8de6c83f0..6e74a0ccd 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -33,7 +33,6 @@ import (
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/text"
"github.com/superseriousbusiness/gotosocial/internal/util"
@@ -140,31 +139,40 @@ func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHead
var err error
maxImageSize := viper.GetInt(config.Keys.MediaImageMaxSize)
if int(avatar.Size) > maxImageSize {
- err = fmt.Errorf("avatar with size %d exceeded max image size of %d bytes", avatar.Size, maxImageSize)
+ err = fmt.Errorf("UpdateAvatar: avatar with size %d exceeded max image size of %d bytes", avatar.Size, maxImageSize)
return nil, err
}
f, err := avatar.Open()
if err != nil {
- return nil, fmt.Errorf("could not read provided avatar: %s", err)
+ return nil, fmt.Errorf("UpdateAvatar: could not read provided avatar: %s", err)
}
// extract the bytes
buf := new(bytes.Buffer)
size, err := io.Copy(buf, f)
if err != nil {
- return nil, fmt.Errorf("could not read provided avatar: %s", err)
+ return nil, fmt.Errorf("UpdateAvatar: could not read provided avatar: %s", err)
}
if size == 0 {
- return nil, errors.New("could not read provided avatar: size 0 bytes")
+ return nil, errors.New("UpdateAvatar: could not read provided avatar: size 0 bytes")
+ }
+
+ // we're done with the FileHeader now
+ if err := f.Close(); err != nil {
+ return nil, fmt.Errorf("UpdateAvatar: error closing multipart fileheader: %s", err)
}
// do the setting
- avatarInfo, err := p.mediaManager.ProcessHeaderOrAvatar(ctx, buf.Bytes(), accountID, media.TypeAvatar, "")
+ media, err := p.mediaManager.ProcessMedia(ctx, buf.Bytes(), accountID, "")
if err != nil {
- return nil, fmt.Errorf("error processing avatar: %s", err)
+ return nil, fmt.Errorf("UpdateAvatar: error processing avatar: %s", err)
+ }
+
+ if err := media.SetAsAvatar(ctx); err != nil {
+ return nil, fmt.Errorf("UpdateAvatar: error setting media as avatar: %s", err)
}
- return avatarInfo, f.Close()
+ return media.LoadAttachment(ctx)
}
// UpdateHeader does the dirty work of checking the header part of an account update form,
@@ -174,31 +182,40 @@ func (p *processor) UpdateHeader(ctx context.Context, header *multipart.FileHead
var err error
maxImageSize := viper.GetInt(config.Keys.MediaImageMaxSize)
if int(header.Size) > maxImageSize {
- err = fmt.Errorf("header with size %d exceeded max image size of %d bytes", header.Size, maxImageSize)
+ err = fmt.Errorf("UpdateHeader: header with size %d exceeded max image size of %d bytes", header.Size, maxImageSize)
return nil, err
}
f, err := header.Open()
if err != nil {
- return nil, fmt.Errorf("could not read provided header: %s", err)
+ return nil, fmt.Errorf("UpdateHeader: could not read provided header: %s", err)
}
// extract the bytes
buf := new(bytes.Buffer)
size, err := io.Copy(buf, f)
if err != nil {
- return nil, fmt.Errorf("could not read provided header: %s", err)
+ return nil, fmt.Errorf("UpdateHeader: could not read provided header: %s", err)
}
if size == 0 {
- return nil, errors.New("could not read provided header: size 0 bytes")
+ return nil, errors.New("UpdateHeader: could not read provided header: size 0 bytes")
+ }
+
+ // we're done with the FileHeader now
+ if err := f.Close(); err != nil {
+ return nil, fmt.Errorf("UpdateHeader: error closing multipart fileheader: %s", err)
}
// do the setting
- headerInfo, err := p.mediaManager.ProcessHeaderOrAvatar(ctx, buf.Bytes(), accountID, media.TypeHeader, "")
+ media, err := p.mediaManager.ProcessMedia(ctx, buf.Bytes(), accountID, "")
if err != nil {
- return nil, fmt.Errorf("error processing header: %s", err)
+ return nil, fmt.Errorf("UpdateHeader: error processing header: %s", err)
+ }
+
+ if err := media.SetAsHeader(ctx); err != nil {
+ return nil, fmt.Errorf("UpdateHeader: error setting media as header: %s", err)
}
- return headerInfo, f.Close()
+ return media.LoadAttachment(ctx)
}
func (p *processor) processNote(ctx context.Context, note string, accountID string) (string, error) {
diff --git a/internal/processing/admin/emoji.go b/internal/processing/admin/emoji.go
index 5620374b8..6fb2ca8c5 100644
--- a/internal/processing/admin/emoji.go
+++ b/internal/processing/admin/emoji.go
@@ -27,7 +27,6 @@ import (
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/id"
)
func (p *processor) EmojiCreate(ctx context.Context, account *gtsmodel.Account, user *gtsmodel.User, form *apimodel.EmojiCreateRequest) (*apimodel.Emoji, error) {
@@ -49,26 +48,20 @@ func (p *processor) EmojiCreate(ctx context.Context, account *gtsmodel.Account,
return nil, errors.New("could not read provided emoji: size 0 bytes")
}
- // allow the mediaManager to work its magic of processing the emoji bytes, and putting them in whatever storage backend we're using
- emoji, err := p.mediaManager.ProcessLocalEmoji(ctx, buf.Bytes(), form.Shortcode)
+ media, err := p.mediaManager.ProcessEmoji(ctx, buf.Bytes(), account.ID, "")
if err != nil {
- return nil, fmt.Errorf("error reading emoji: %s", err)
+ return nil, err
}
- emojiID, err := id.NewULID()
+ emoji, err := media.LoadEmoji(ctx)
if err != nil {
return nil, err
}
- emoji.ID = emojiID
apiEmoji, err := p.tc.EmojiToAPIEmoji(ctx, emoji)
if err != nil {
return nil, fmt.Errorf("error converting emoji to apitype: %s", err)
}
- if err := p.db.Put(ctx, emoji); err != nil {
- return nil, fmt.Errorf("database error while processing emoji: %s", err)
- }
-
return &apiEmoji, nil
}
diff --git a/internal/processing/media/create.go b/internal/processing/media/create.go
index 357278e64..d1840196a 100644
--- a/internal/processing/media/create.go
+++ b/internal/processing/media/create.go
@@ -44,13 +44,13 @@ func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, form
return nil, errors.New("could not read provided attachment: size 0 bytes")
}
- // process the media and load it immediately
- media, err := p.mediaManager.ProcessMedia(ctx, buf.Bytes(), account.ID)
+ // process the media attachment and load it immediately
+ media, err := p.mediaManager.ProcessMedia(ctx, buf.Bytes(), account.ID, "")
if err != nil {
return nil, err
}
- attachment, err := media.Load(ctx)
+ attachment, err := media.LoadAttachment(ctx)
if err != nil {
return nil, err
}
@@ -62,10 +62,5 @@ func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, form
return nil, fmt.Errorf("error parsing media attachment to frontend type: %s", err)
}
- // now we can confidently put the attachment in the database
- if err := p.db.Put(ctx, attachment); err != nil {
- return nil, fmt.Errorf("error storing media attachment in db: %s", err)
- }
-
return &apiAttachment, nil
}