summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/cleaner/media.go7
-rw-r--r--internal/storage/storage.go13
2 files changed, 6 insertions, 14 deletions
diff --git a/internal/cleaner/media.go b/internal/cleaner/media.go
index 043d7cf5f..84473bc22 100644
--- a/internal/cleaner/media.go
+++ b/internal/cleaner/media.go
@@ -20,7 +20,6 @@ package cleaner
import (
"context"
"errors"
- "strings"
"time"
"code.superseriousbusiness.org/gotosocial/internal/db"
@@ -94,10 +93,10 @@ func (m *Media) LogFixCacheStates(ctx context.Context) {
func (m *Media) PruneOrphaned(ctx context.Context) (int, error) {
var files []string
- // All media files in storage will have path fitting: {$account}/{$type}/{$size}/{$id}.{$ext}
+ // All media in storage will have path: {$account}/{$type}/{$size}/{$id}.{$ext}
if err := m.state.Storage.WalkKeys(ctx, func(path string) error {
- // Check for our expected fileserver path format.
- path = strings.TrimPrefix(path, m.state.Storage.KeyPrefix)
+
+ // Check for expected fileserver path format.
if !regexes.FilePath.MatchString(path) {
log.Warnf(ctx, "unexpected storage item: %s", path)
return nil
diff --git a/internal/storage/storage.go b/internal/storage/storage.go
index 32e9ccd27..6c645f0ff 100644
--- a/internal/storage/storage.go
+++ b/internal/storage/storage.go
@@ -78,32 +78,28 @@ type Driver struct {
// S3-only parameters
Proxy bool
Bucket string
- KeyPrefix string
PresignedCache *ttl.Cache[string, PresignedURL]
RedirectURL string
}
// Get returns the byte value for key in storage.
func (d *Driver) Get(ctx context.Context, key string) ([]byte, error) {
- key = d.KeyPrefix + key
return d.Storage.ReadBytes(ctx, key)
}
// GetStream returns an io.ReadCloser for the value bytes at key in the storage.
func (d *Driver) GetStream(ctx context.Context, key string) (io.ReadCloser, error) {
- key = d.KeyPrefix + key
return d.Storage.ReadStream(ctx, key)
}
// Put writes the supplied value bytes at key in the storage
func (d *Driver) Put(ctx context.Context, key string, value []byte) (int, error) {
- key = d.KeyPrefix + key
return d.Storage.WriteBytes(ctx, key, value)
}
// 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) {
- key = d.KeyPrefix + key
+
// Open file at path for reading.
file, err := os.Open(filepath)
if err != nil {
@@ -149,13 +145,11 @@ func (d *Driver) PutFile(ctx context.Context, key, filepath, contentType string)
// Delete attempts to remove the supplied key (and corresponding value) from storage.
func (d *Driver) Delete(ctx context.Context, key string) error {
- key = d.KeyPrefix + key
return d.Storage.Remove(ctx, key)
}
// Has checks if the supplied key is in the storage.
func (d *Driver) Has(ctx context.Context, key string) (bool, error) {
- key = d.KeyPrefix + key
stat, err := d.Storage.Stat(ctx, key)
return (stat != nil), err
}
@@ -163,7 +157,6 @@ func (d *Driver) Has(ctx context.Context, key string) (bool, error) {
// WalkKeys walks the keys in the storage.
func (d *Driver) WalkKeys(ctx context.Context, walk func(string) error) error {
return d.Storage.WalkKeys(ctx, storage.WalkKeysOpts{
- Prefix: d.KeyPrefix,
Step: func(entry storage.Entry) error {
return walk(entry.Key)
},
@@ -172,7 +165,7 @@ func (d *Driver) WalkKeys(ctx context.Context, walk func(string) error) error {
// URL will return a presigned GET object URL, but only if running on S3 storage with proxying disabled.
func (d *Driver) URL(ctx context.Context, key string) *PresignedURL {
- key = d.KeyPrefix + key
+
// Check whether S3 *without* proxying is enabled
s3, ok := d.Storage.(*s3.S3Storage)
if !ok || d.Proxy {
@@ -339,6 +332,7 @@ func NewS3Storage() (*Driver, error) {
// Open the s3 storage implementation
s3, err := s3.Open(endpoint, bucket, &s3.Config{
+ KeyPrefix: config.GetStorageS3KeyPrefix(),
CoreOpts: minio.Options{
Creds: credentials.NewStaticV4(access, secret, ""),
Secure: secure,
@@ -358,7 +352,6 @@ func NewS3Storage() (*Driver, error) {
return &Driver{
Proxy: config.GetStorageS3Proxy(),
Bucket: config.GetStorageS3BucketName(),
- KeyPrefix: config.GetStorageS3KeyPrefix(),
Storage: s3,
PresignedCache: presignedCache,
RedirectURL: redirectURL,