mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-22 19:56:39 +00:00
lint, fmt
This commit is contained in:
parent
6bf39d0fc1
commit
723bfe8944
|
@ -260,30 +260,27 @@ func (p *ProcessingMedia) fetchRawData(ctx context.Context) error {
|
||||||
return fmt.Errorf("fetchRawData: error parsing content type: %s", err)
|
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, "/")
|
split := strings.Split(contentType, "/")
|
||||||
if len(split) != 2 {
|
if len(split) != 2 {
|
||||||
return fmt.Errorf("fetchRawData: content type %s was not valid", contentType)
|
return fmt.Errorf("fetchRawData: content type %s was not valid", contentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
mainType := split[0] // something like 'image'
|
|
||||||
extension := split[1] // something like 'jpeg'
|
extension := split[1] // something like 'jpeg'
|
||||||
|
|
||||||
// set some additional fields on the attachment now that
|
// set some additional fields on the attachment now that
|
||||||
// we know more about what the underlying media actually is
|
// we know more about what the underlying media actually is
|
||||||
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 {
|
if extension == mimeGif {
|
||||||
p.attachment.Type = gtsmodel.FileTypeGif
|
p.attachment.Type = gtsmodel.FileTypeGif
|
||||||
} else {
|
} else {
|
||||||
p.attachment.Type = gtsmodel.FileTypeImage
|
p.attachment.Type = gtsmodel.FileTypeImage
|
||||||
}
|
}
|
||||||
default:
|
p.attachment.URL = uris.GenerateURIForAttachment(p.attachment.AccountID, string(TypeAttachment), string(SizeOriginal), p.attachment.ID, extension)
|
||||||
return fmt.Errorf("fetchRawData: cannot process mime type %s (yet)", mainType)
|
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
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,10 @@
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/h2non/filetype"
|
"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").
|
// 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
|
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 {
|
func supportedEmoji(mimeType string) bool {
|
||||||
acceptedEmojiTypes := []string{
|
acceptedEmojiTypes := []string{
|
||||||
mimeImageGif,
|
mimeImageGif,
|
||||||
|
@ -106,18 +104,3 @@ func ParseMediaSize(s string) (Size, error) {
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("%s not a recognized MediaSize", s)
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue