summaryrefslogtreecommitdiff
path: root/internal/media/processingemoji.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-11-03 15:03:12 +0100
committerLibravatar GitHub <noreply@github.com>2022-11-03 15:03:12 +0100
commit1dfa7fe0d51b75792db7b0c28ffad7d1f650834d (patch)
tree0af4de062d33e6c292d8b42dbf4d13f16125b959 /internal/media/processingemoji.go
parent[bugfix] Use []rune to check length of user-submitted text (#948) (diff)
downloadgotosocial-1dfa7fe0d51b75792db7b0c28ffad7d1f650834d.tar.xz
[bugfix] Wrap media in read closer (#941)
* use readcloser for content.Content * call media postdata function no matter what * return a readcloser from data func * tidy of logic of readertostore * fix whoopsie
Diffstat (limited to 'internal/media/processingemoji.go')
-rw-r--r--internal/media/processingemoji.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/internal/media/processingemoji.go b/internal/media/processingemoji.go
index e1c6f2efb..79bc23998 100644
--- a/internal/media/processingemoji.go
+++ b/internal/media/processingemoji.go
@@ -193,24 +193,22 @@ func (p *ProcessingEmoji) store(ctx context.Context) error {
return nil
}
- // execute the data function to get the reader out of it
- reader, fileSize, err := p.data(ctx)
+ // execute the data function to get the readcloser out of it
+ rc, fileSize, err := p.data(ctx)
if err != nil {
return fmt.Errorf("store: error executing data function: %s", err)
}
// defer closing the reader when we're done with it
defer func() {
- if rc, ok := reader.(io.ReadCloser); ok {
- if err := rc.Close(); err != nil {
- log.Errorf("store: error closing readcloser: %s", err)
- }
+ if err := rc.Close(); err != nil {
+ log.Errorf("store: error closing readcloser: %s", err)
}
}()
// extract no more than 261 bytes from the beginning of the file -- this is the header
firstBytes := make([]byte, maxFileHeaderBytes)
- if _, err := reader.Read(firstBytes); err != nil {
+ if _, err := rc.Read(firstBytes); err != nil {
return fmt.Errorf("store: error reading initial %d bytes: %s", maxFileHeaderBytes, err)
}
@@ -242,7 +240,7 @@ func (p *ProcessingEmoji) store(ctx context.Context) error {
p.emoji.ImageContentType = contentType
// concatenate the first bytes with the existing bytes still in the reader (thanks Mara)
- readerToStore := io.MultiReader(bytes.NewBuffer(firstBytes), reader)
+ readerToStore := io.MultiReader(bytes.NewBuffer(firstBytes), rc)
var maxEmojiSize int64
if p.emoji.Domain == "" {