mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Model refactor (#3915)
* Add mockery config file * Move basic file/folder structs to models * Fix hack due to import loop * Move file interfaces to models * Move folder interfaces to models * Move scene interfaces to models * Move scene marker interfaces to models * Move image interfaces to models * Move gallery interfaces to models * Move gallery chapter interfaces to models * Move studio interfaces to models * Move movie interfaces to models * Move performer interfaces to models * Move tag interfaces to models * Move autotag interfaces to models * Regenerate mocks
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/file/video"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
@@ -19,21 +18,22 @@ var (
|
||||
ErrNotVideoFile = errors.New("not a video file")
|
||||
)
|
||||
|
||||
type CreatorUpdater interface {
|
||||
FindByFileID(ctx context.Context, fileID file.ID) ([]*models.Scene, error)
|
||||
FindByFingerprints(ctx context.Context, fp []file.Fingerprint) ([]*models.Scene, error)
|
||||
Creator
|
||||
type ScanCreatorUpdater interface {
|
||||
FindByFileID(ctx context.Context, fileID models.FileID) ([]*models.Scene, error)
|
||||
FindByFingerprints(ctx context.Context, fp []models.Fingerprint) ([]*models.Scene, error)
|
||||
GetFiles(ctx context.Context, relatedID int) ([]*models.VideoFile, error)
|
||||
|
||||
Create(ctx context.Context, newScene *models.Scene, fileIDs []models.FileID) error
|
||||
UpdatePartial(ctx context.Context, id int, updatedScene models.ScenePartial) (*models.Scene, error)
|
||||
AddFileID(ctx context.Context, id int, fileID file.ID) error
|
||||
models.VideoFileLoader
|
||||
AddFileID(ctx context.Context, id int, fileID models.FileID) error
|
||||
}
|
||||
|
||||
type ScanGenerator interface {
|
||||
Generate(ctx context.Context, s *models.Scene, f *file.VideoFile) error
|
||||
Generate(ctx context.Context, s *models.Scene, f *models.VideoFile) error
|
||||
}
|
||||
|
||||
type ScanHandler struct {
|
||||
CreatorUpdater CreatorUpdater
|
||||
CreatorUpdater ScanCreatorUpdater
|
||||
|
||||
ScanGenerator ScanGenerator
|
||||
CaptionUpdater video.CaptionUpdater
|
||||
@@ -63,12 +63,12 @@ func (h *ScanHandler) validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *ScanHandler) Handle(ctx context.Context, f file.File, oldFile file.File) error {
|
||||
func (h *ScanHandler) Handle(ctx context.Context, f models.File, oldFile models.File) error {
|
||||
if err := h.validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
videoFile, ok := f.(*file.VideoFile)
|
||||
videoFile, ok := f.(*models.VideoFile)
|
||||
if !ok {
|
||||
return ErrNotVideoFile
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (h *ScanHandler) Handle(ctx context.Context, f file.File, oldFile file.File
|
||||
|
||||
logger.Infof("%s doesn't exist. Creating new scene...", f.Base().Path)
|
||||
|
||||
if err := h.CreatorUpdater.Create(ctx, newScene, []file.ID{videoFile.ID}); err != nil {
|
||||
if err := h.CreatorUpdater.Create(ctx, newScene, []models.FileID{videoFile.ID}); err != nil {
|
||||
return fmt.Errorf("creating new scene: %w", err)
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func (h *ScanHandler) Handle(ctx context.Context, f file.File, oldFile file.File
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *ScanHandler) associateExisting(ctx context.Context, existing []*models.Scene, f *file.VideoFile, updateExisting bool) error {
|
||||
func (h *ScanHandler) associateExisting(ctx context.Context, existing []*models.Scene, f *models.VideoFile, updateExisting bool) error {
|
||||
for _, s := range existing {
|
||||
if err := s.LoadFiles(ctx, h.CreatorUpdater); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user