lint, fmt

This commit is contained in:
tsmethurst
2022-01-15 17:41:18 +01:00
parent 6bf39d0fc1
commit 723bfe8944
2 changed files with 10 additions and 30 deletions

View File

@@ -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
}