feat: image variants engine
This commit is contained in:
1 parent
f0845de643
commit
f1d56ef50e
80 files changed
+7312
-84
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package useCases
|
||||
|
||||
import "RenewCMS/internal/domain/image"
|
||||
|
||||
type VariantPurgeResult struct {
|
||||
Files int
|
||||
Bytes int64
|
||||
}
|
||||
|
||||
type variantCache struct {
|
||||
files image.VariantFileRepository
|
||||
storage image.Storage
|
||||
}
|
||||
|
||||
func (c variantCache) purgeVariant(name string) (VariantPurgeResult, error) {
|
||||
rows, err := c.files.ListByVariant(name)
|
||||
if err != nil {
|
||||
return VariantPurgeResult{}, err
|
||||
}
|
||||
return c.purge(rows)
|
||||
}
|
||||
|
||||
func (c variantCache) purgeSource(storedName string) error {
|
||||
rows, err := c.files.ListBySource(storedName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.purge(rows)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c variantCache) purge(rows []image.VariantFile) (VariantPurgeResult, error) {
|
||||
var result VariantPurgeResult
|
||||
var failure error
|
||||
for _, row := range rows {
|
||||
if err := c.purgeRow(row); err != nil {
|
||||
failure = err
|
||||
continue
|
||||
}
|
||||
result.Files++
|
||||
result.Bytes += row.Size
|
||||
}
|
||||
return result, failure
|
||||
}
|
||||
|
||||
func (c variantCache) purgeRow(row image.VariantFile) error {
|
||||
if err := c.storage.Delete(row.CachedName); err != nil {
|
||||
return err
|
||||
}
|
||||
return c.files.Delete(row.ID)
|
||||
}
|
||||
Reference in new issue
Block a user