commit 723bfe8944f80fd1ef935ad6878fc555fd42b8e7
parent 6bf39d0fc1286bdf2f4760adab52c6eff234d01d
Author: tsmethurst <tobi.smethurst@protonmail.com>
Date: Sat, 15 Jan 2022 17:41:18 +0100
lint, fmt
Diffstat:
2 files changed, 10 insertions(+), 30 deletions(-)
diff --git a/internal/media/processingmedia.go b/internal/media/processingmedia.go
@@ -260,31 +260,28 @@ func (p *ProcessingMedia) fetchRawData(ctx context.Context) error {
return fmt.Errorf("fetchRawData: error parsing content type: %s", err)
}
+ if !supportedImage(contentType) {
+ return fmt.Errorf("fetchRawData: media type %s not (yet) supported", contentType)
+ }
+
split := strings.Split(contentType, "/")
if len(split) != 2 {
return fmt.Errorf("fetchRawData: content type %s was not valid", contentType)
}
- mainType := split[0] // something like 'image'
extension := split[1] // something like 'jpeg'
// set some additional fields on the attachment now that
// we know more about what the underlying media actually is
+ if extension == mimeGif {
+ p.attachment.Type = gtsmodel.FileTypeGif
+ } else {
+ p.attachment.Type = gtsmodel.FileTypeImage
+ }
p.attachment.URL = uris.GenerateURIForAttachment(p.attachment.AccountID, string(TypeAttachment), string(SizeOriginal), p.attachment.ID, extension)
p.attachment.File.Path = fmt.Sprintf("%s/%s/%s/%s.%s", p.attachment.AccountID, TypeAttachment, SizeOriginal, p.attachment.ID, extension)
p.attachment.File.ContentType = contentType
- switch mainType {
- case mimeImage:
- if extension == mimeGif {
- p.attachment.Type = gtsmodel.FileTypeGif
- } else {
- p.attachment.Type = gtsmodel.FileTypeImage
- }
- default:
- return fmt.Errorf("fetchRawData: cannot process mime type %s (yet)", mainType)
- }
-
return nil
}
diff --git a/internal/media/util.go b/internal/media/util.go
@@ -20,12 +20,10 @@ package media
import (
"bytes"
- "context"
"errors"
"fmt"
"github.com/h2non/filetype"
- "github.com/superseriousbusiness/gotosocial/internal/db"
)
// parseContentType parses the MIME content type from a file, returning it as a string in the form (eg., "image/jpeg").
@@ -65,7 +63,7 @@ func supportedImage(mimeType string) bool {
return false
}
-// supportedEmoji checks that the content type is image/png -- the only type supported for emoji.
+// supportedEmoji checks that the content type is image/png or image/gif -- the only types supported for emoji.
func supportedEmoji(mimeType string) bool {
acceptedEmojiTypes := []string{
mimeImageGif,
@@ -106,18 +104,3 @@ func ParseMediaSize(s string) (Size, error) {
}
return "", fmt.Errorf("%s not a recognized MediaSize", s)
}
-
-// putOrUpdate is just a convenience function for first trying to PUT the attachment or emoji in the database,
-// and then if that doesn't work because the attachment/emoji already exists, updating it instead.
-func putOrUpdate(ctx context.Context, database db.DB, i interface{}) error {
- if err := database.Put(ctx, i); err != nil {
- if err != db.ErrAlreadyExists {
- return fmt.Errorf("putOrUpdate: proper error while putting: %s", err)
- }
- if err := database.UpdateByPrimaryKey(ctx, i); err != nil {
- return fmt.Errorf("putOrUpdate: error while updating: %s", err)
- }
- }
-
- return nil
-}