summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
authorLibravatar tsmethurst <tobi.smethurst@protonmail.com>2022-01-16 18:52:55 +0100
committerLibravatar tsmethurst <tobi.smethurst@protonmail.com>2022-01-16 18:52:55 +0100
commit589bb9df0275457b5f9c3790e67517ec1be1745d (patch)
tree8b15a4a457bb7ac1d4b209e5cb930cb4ec315ca8 /internal/processing
parentupdate dependencies (diff)
downloadgotosocial-589bb9df0275457b5f9c3790e67517ec1be1745d.tar.xz
pass reader around instead of []byte
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/account/update.go42
-rw-r--r--internal/processing/admin/emoji.go20
-rw-r--r--internal/processing/media/create.go19
3 files changed, 8 insertions, 73 deletions
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index 7b305dc95..5a0a3e5a1 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -19,9 +19,7 @@
package account
import (
- "bytes"
"context"
- "errors"
"fmt"
"io"
"mime/multipart"
@@ -142,24 +140,8 @@ func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHead
return nil, fmt.Errorf("UpdateAvatar: avatar with size %d exceeded max image size of %d bytes", avatar.Size, maxImageSize)
}
- dataFunc := func(ctx context.Context) ([]byte, error) {
- // pop open the fileheader
- f, err := avatar.Open()
- if err != nil {
- 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("UpdateAvatar: could not read provided avatar: %s", err)
- }
- if size == 0 {
- return nil, errors.New("UpdateAvatar: could not read provided avatar: size 0 bytes")
- }
-
- return buf.Bytes(), f.Close()
+ dataFunc := func(ctx context.Context) (io.Reader, error) {
+ return avatar.Open()
}
isAvatar := true
@@ -184,24 +166,8 @@ func (p *processor) UpdateHeader(ctx context.Context, header *multipart.FileHead
return nil, fmt.Errorf("UpdateHeader: header with size %d exceeded max image size of %d bytes", header.Size, maxImageSize)
}
- dataFunc := func(ctx context.Context) ([]byte, error) {
- // pop open the fileheader
- f, err := header.Open()
- if err != nil {
- 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("UpdateHeader: could not read provided header: %s", err)
- }
- if size == 0 {
- return nil, errors.New("UpdateHeader: could not read provided header: size 0 bytes")
- }
-
- return buf.Bytes(), f.Close()
+ dataFunc := func(ctx context.Context) (io.Reader, error) {
+ return header.Open()
}
isHeader := true
diff --git a/internal/processing/admin/emoji.go b/internal/processing/admin/emoji.go
index fcc17c4be..e0068858b 100644
--- a/internal/processing/admin/emoji.go
+++ b/internal/processing/admin/emoji.go
@@ -19,9 +19,7 @@
package admin
import (
- "bytes"
"context"
- "errors"
"fmt"
"io"
@@ -38,22 +36,8 @@ func (p *processor) EmojiCreate(ctx context.Context, account *gtsmodel.Account,
return nil, gtserror.NewErrorNotAuthorized(fmt.Errorf("user %s not an admin", user.ID), "user is not an admin")
}
- data := func(innerCtx context.Context) ([]byte, error) {
- // open the emoji and extract the bytes from it
- f, err := form.Image.Open()
- if err != nil {
- return nil, fmt.Errorf("error opening emoji: %s", err)
- }
- buf := new(bytes.Buffer)
- size, err := io.Copy(buf, f)
- if err != nil {
- return nil, fmt.Errorf("error reading emoji: %s", err)
- }
- if size == 0 {
- return nil, errors.New("could not read provided emoji: size 0 bytes")
- }
-
- return buf.Bytes(), f.Close()
+ data := func(innerCtx context.Context) (io.Reader, error) {
+ return form.Image.Open()
}
emojiID, err := id.NewRandomULID()
diff --git a/internal/processing/media/create.go b/internal/processing/media/create.go
index 0896315b1..0fda4c27b 100644
--- a/internal/processing/media/create.go
+++ b/internal/processing/media/create.go
@@ -19,9 +19,7 @@
package media
import (
- "bytes"
"context"
- "errors"
"fmt"
"io"
@@ -31,21 +29,8 @@ import (
)
func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, form *apimodel.AttachmentRequest) (*apimodel.Attachment, error) {
- data := func(innerCtx context.Context) ([]byte, error) {
- // open the attachment and extract the bytes from it
- f, err := form.File.Open()
- if err != nil {
- return nil, fmt.Errorf("error opening attachment: %s", err)
- }
- buf := new(bytes.Buffer)
- size, err := io.Copy(buf, f)
- if err != nil {
- return nil, fmt.Errorf("error reading attachment: %s", err)
- }
- if size == 0 {
- return nil, errors.New("could not read provided attachment: size 0 bytes")
- }
- return buf.Bytes(), f.Close()
+ data := func(innerCtx context.Context) (io.Reader, error) {
+ return form.File.Open()
}
focusX, focusY, err := parseFocus(form.Focus)