summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/media/processingemoji.go16
-rw-r--r--internal/media/processingmedia.go16
-rw-r--r--internal/storage/storage.go42
3 files changed, 45 insertions, 29 deletions
diff --git a/internal/media/processingemoji.go b/internal/media/processingemoji.go
index 89a1bcc91..18d7895fd 100644
--- a/internal/media/processingemoji.go
+++ b/internal/media/processingemoji.go
@@ -216,10 +216,18 @@ func (p *ProcessingEmoji) store(ctx context.Context) error {
"png",
)
+ // Get mimetype for the file container
+ // type, falling back to generic data.
+ p.emoji.ImageContentType = getMimeType(ext)
+
+ // Set the known emoji static content type.
+ p.emoji.ImageStaticContentType = "image/png"
+
// Copy temporary file into storage at path.
filesz, err := p.mgr.state.Storage.PutFile(ctx,
p.emoji.ImagePath,
temppath,
+ p.emoji.ImageContentType,
)
if err != nil {
return gtserror.Newf("error writing emoji to storage: %w", err)
@@ -229,6 +237,7 @@ func (p *ProcessingEmoji) store(ctx context.Context) error {
staticsz, err := p.mgr.state.Storage.PutFile(ctx,
p.emoji.ImageStaticPath,
staticpath,
+ p.emoji.ImageStaticContentType,
)
if err != nil {
return gtserror.Newf("error writing static to storage: %w", err)
@@ -256,13 +265,6 @@ func (p *ProcessingEmoji) store(ctx context.Context) error {
"png",
)
- // Get mimetype for the file container
- // type, falling back to generic data.
- p.emoji.ImageContentType = getMimeType(ext)
-
- // Set the known emoji static content type.
- p.emoji.ImageStaticContentType = "image/png"
-
// We can now consider this cached.
p.emoji.Cached = util.Ptr(true)
diff --git a/internal/media/processingmedia.go b/internal/media/processingmedia.go
index 78c6c61a9..acd326457 100644
--- a/internal/media/processingmedia.go
+++ b/internal/media/processingmedia.go
@@ -261,10 +261,15 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
ext,
)
+ // Get mimetype for the file container
+ // type, falling back to generic data.
+ p.media.File.ContentType = getMimeType(ext)
+
// Copy temporary file into storage at path.
filesz, err := p.mgr.state.Storage.PutFile(ctx,
p.media.File.Path,
temppath,
+ p.media.File.ContentType,
)
if err != nil {
return gtserror.Newf("error writing media to storage: %w", err)
@@ -286,10 +291,14 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
thumbExt,
)
+ // Determine thumbnail content-type from thumb ext.
+ p.media.Thumbnail.ContentType = getMimeType(thumbExt)
+
// Copy thumbnail file into storage at path.
thumbsz, err := p.mgr.state.Storage.PutFile(ctx,
p.media.Thumbnail.Path,
thumbpath,
+ p.media.Thumbnail.ContentType,
)
if err != nil {
return gtserror.Newf("error writing thumb to storage: %w", err)
@@ -298,9 +307,6 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
// Set final determined thumbnail size.
p.media.Thumbnail.FileSize = int(thumbsz)
- // Determine thumbnail content-type from thumb ext.
- p.media.Thumbnail.ContentType = getMimeType(thumbExt)
-
// Generate a media attachment thumbnail URL.
p.media.Thumbnail.URL = uris.URIForAttachment(
p.media.AccountID,
@@ -320,10 +326,6 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
ext,
)
- // Get mimetype for the file container
- // type, falling back to generic data.
- p.media.File.ContentType = getMimeType(ext)
-
// We can now consider this cached.
p.media.Cached = util.Ptr(true)
diff --git a/internal/storage/storage.go b/internal/storage/storage.go
index f3cb814f1..dcef9cde4 100644
--- a/internal/storage/storage.go
+++ b/internal/storage/storage.go
@@ -97,23 +97,39 @@ func (d *Driver) Put(ctx context.Context, key string, value []byte) (int, error)
return d.Storage.WriteBytes(ctx, key, value)
}
-// PutStream writes the bytes from supplied reader at key in the storage
-func (d *Driver) PutStream(ctx context.Context, key string, r io.Reader) (int64, error) {
- return d.Storage.WriteStream(ctx, key, r)
-}
-
-// PutFile moves the contents of file at path, to storage.Driver{} under given key.
-func (d *Driver) PutFile(ctx context.Context, key string, filepath string) (int64, error) {
+// PutFile moves the contents of file at path, to storage.Driver{} under given key (with content-type if supported).
+func (d *Driver) PutFile(ctx context.Context, key, filepath, contentType string) (int64, error) {
// Open file at path for reading.
file, err := os.Open(filepath)
if err != nil {
return 0, gtserror.Newf("error opening file %s: %w", filepath, err)
}
- // Write the file data to storage under key. Note
- // that for disk.DiskStorage{} this should end up
- // being a highly optimized Linux sendfile syscall.
- sz, err := d.Storage.WriteStream(ctx, key, file)
+ var sz int64
+
+ switch d := d.Storage.(type) {
+ case *s3.S3Storage:
+ var info minio.UploadInfo
+
+ // For S3 storage, write the file but specifically pass in the
+ // content-type as an extra option. This handles the case of media
+ // being served via CDN redirect (where we don't handle content-type).
+ info, err = d.PutObject(ctx, key, file, minio.PutObjectOptions{
+ ContentType: contentType,
+ })
+
+ // Get size from
+ // uploaded info.
+ sz = info.Size
+
+ default:
+ // Write the file data to storage under key. Note
+ // that for disk.DiskStorage{} this should end up
+ // being a highly optimized Linux sendfile syscall.
+ sz, err = d.WriteStream(ctx, key, file)
+ }
+
+ // Wrap write error.
if err != nil {
err = gtserror.Newf("error writing file %s: %w", key, err)
}
@@ -305,11 +321,7 @@ func NewS3Storage() (*Driver, error) {
Creds: credentials.NewStaticV4(access, secret, ""),
Secure: secure,
},
- GetOpts: minio.GetObjectOptions{},
- PutOpts: minio.PutObjectOptions{},
PutChunkSize: 5 * 1024 * 1024, // 5MiB
- StatOpts: minio.StatObjectOptions{},
- RemoveOpts: minio.RemoveObjectOptions{},
ListSize: 200,
})
if err != nil {