[chore] move s3 storage key prefixing into the storage library itself (#4246)

This is just a useful feature that it seemed more semantically correct to have in the storage library itself! Still, thank you to @vdyotte for the original change :)

Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4246
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
kim 2025-06-06 16:35:39 +02:00 committed by kim
commit b13a6437ff
6 changed files with 79 additions and 34 deletions

View file

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