mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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
This commit is contained in:
@@ -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 == "" {
|
||||
|
Reference in New Issue
Block a user