fix cloud library mounts and artwork caching

This commit is contained in:
ShukeBta
2026-06-10 20:43:42 +08:00
parent 0bf983cec8
commit fd0428ee7d
36 changed files with 1469 additions and 140 deletions
+6
View File
@@ -455,6 +455,12 @@ func (r *MediaRepository) DeleteByLibrary(ctx context.Context, libraryID string)
return r.db.WithContext(ctx).Where("library_id = ?", libraryID).Delete(&model.Media{}).Error
}
// PurgeByLibrary permanently removes media tied to a library. Used for virtual
// cloud mounts where "remove mount" must not populate the recycle bin.
func (r *MediaRepository) PurgeByLibrary(ctx context.Context, libraryID string) error {
return r.db.WithContext(ctx).Unscoped().Where("library_id = ?", libraryID).Delete(&model.Media{}).Error
}
// ─── Series ──────────────────────────────────────────────────────────────────
// SeriesRepository persists model.Series records.
+30 -2
View File
@@ -3,7 +3,9 @@ package repository
import (
"context"
"errors"
"time"
"github.com/google/uuid"
"gorm.io/gorm"
"github.com/ShukeBta/MediaStationGo/internal/model"
@@ -34,6 +36,32 @@ func (r *StorageConfigRepository) List(ctx context.Context) ([]model.StorageConf
// Upsert creates or replaces a storage config keyed by Type.
func (r *StorageConfigRepository) Upsert(ctx context.Context, c *model.StorageConfig) error {
return r.db.WithContext(ctx).Where("type = ?", c.Type).
Assign(*c).FirstOrCreate(c).Error
db := r.db.WithContext(ctx)
var existing model.StorageConfig
err := db.Where("type = ?", c.Type).First(&existing).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
now := time.Now()
c.ID = uuid.NewString()
c.CreatedAt = now
c.UpdatedAt = now
return db.Model(&model.StorageConfig{}).Create(map[string]any{
"id": c.ID,
"type": c.Type,
"config": c.Config,
"enabled": c.Enabled,
"last_error": c.LastError,
"created_at": c.CreatedAt,
"updated_at": c.UpdatedAt,
}).Error
}
if err != nil {
return err
}
c.ID = existing.ID
return db.Model(&model.StorageConfig{}).Where("id = ?", existing.ID).Updates(map[string]any{
"config": c.Config,
"enabled": c.Enabled,
"last_error": c.LastError,
"updated_at": time.Now(),
}).Error
}