feat: optional S3-compatible storage for uploaded images, instead of the local upload directory
This commit is contained in:
1 parent
d752a61e52
commit
eb9bfabed5
23 files changed
+1962
-7
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
domain "RenewCMS/internal/domain/image"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type ReadCountingStorage struct {
|
||||
domain.Storage
|
||||
opened atomic.Int64
|
||||
}
|
||||
|
||||
var _ domain.Storage = &ReadCountingStorage{}
|
||||
|
||||
func NewReadCountingStorage(inner domain.Storage) *ReadCountingStorage {
|
||||
return &ReadCountingStorage{Storage: inner}
|
||||
}
|
||||
|
||||
func (s *ReadCountingStorage) Open(storedName string) (domain.Blob, error) {
|
||||
blob, err := s.Storage.Open(storedName)
|
||||
if err == nil {
|
||||
s.opened.Add(1)
|
||||
}
|
||||
return blob, err
|
||||
}
|
||||
|
||||
func (s *ReadCountingStorage) Opened() int {
|
||||
return int(s.opened.Load())
|
||||
}
|
||||
|
||||
type Logger interface {
|
||||
Printf(format string, args ...any)
|
||||
}
|
||||
|
||||
func RunBackfillReportingReads(inner domain.Storage, logger Logger, run func(domain.Storage) error) error {
|
||||
counting := NewReadCountingStorage(inner)
|
||||
err := run(counting)
|
||||
if opened := counting.Opened(); opened > 0 {
|
||||
logger.Printf("image metadata backfill read %d images from the bucket", opened)
|
||||
}
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user