Documentation
¶
Index ¶
- Variables
- func BuildGeneratedFilesJSON(nfoPath string, subtitleResults []organizer.SubtitleResult, ...) string
- func DetermineOperationType(moveFiles bool, linkMode organizer.LinkMode, isUpdateMode bool) string
- func NewPreOrganizeRecord(...) *models.BatchFileOperation
- func UpdatePostOrganize(op *models.BatchFileOperation, newPath string, inPlaceRenamed bool, ...)
- type FileMove
- type GeneratedFilesJSON
- type Logger
- func (l *Logger) CleanupOldRecords(olderThan time.Duration) error
- func (l *Logger) GetByMovieID(movieID string) ([]models.History, error)
- func (l *Logger) GetByOperation(operation string, limit int) ([]models.History, error)
- func (l *Logger) GetByStatus(status string, limit int) ([]models.History, error)
- func (l *Logger) GetRecent(limit int) ([]models.History, error)
- func (l *Logger) GetStats() (*Stats, error)
- func (l *Logger) LogDownload(movieID, url, localPath, mediaType string, err error) error
- func (l *Logger) LogNFO(movieID, nfoPath string, err error) error
- func (l *Logger) LogOrganize(movieID, originalPath, newPath string, dryRun bool, err error) error
- func (l *Logger) LogRevert(movieID, originalPath, revertedFrom string, err error) error
- func (l *Logger) LogScrape(movieID, sourceURL string, metadata interface{}, err error) error
- type NFOSnapshotResult
- type RevertBatchResult
- type RevertFileResult
- type Reverter
- type Stats
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBatchAlreadyReverted is returned when a batch or operation is already reverted. ErrBatchAlreadyReverted = errors.New("batch already reverted") // ErrCopyModeNotRevertible is returned when attempting to revert a copy/hardlink/symlink operation. ErrCopyModeNotRevertible = errors.New("copy-mode operations cannot be reverted") // ErrNoOperationsFound is returned when no operations exist for the given batch. ErrNoOperationsFound = errors.New("no operations found for batch") )
Functions ¶
func BuildGeneratedFilesJSON ¶
func BuildGeneratedFilesJSON(nfoPath string, subtitleResults []organizer.SubtitleResult, downloadPaths []string) string
BuildGeneratedFilesJSON creates JSON with Delete list (NFO path, image paths) and MoveBack list (subtitle paths) for the GeneratedFiles field. Returns "" on empty or marshal error.
func DetermineOperationType ¶
DetermineOperationType maps organize flags to operation type constants.
func NewPreOrganizeRecord ¶
func NewPreOrganizeRecord(batchJobID, movieID, originalPath, nfoSnapshot, nfoPath, originalDirPath, operationType string, inPlaceRenamed bool) *models.BatchFileOperation
NewPreOrganizeRecord creates a BatchFileOperation with NFO snapshot for crash-safe persistence BEFORE organize (per D-01). Does NOT call repo.Create — caller is responsible for persisting (gives control over timing for crash-safety).
func UpdatePostOrganize ¶
func UpdatePostOrganize(op *models.BatchFileOperation, newPath string, inPlaceRenamed bool, originalDirPath string, generatedFilesJSON string)
UpdatePostOrganize updates the BatchFileOperation in-place (the struct, not the DB):
- op.NewPath = newPath
- op.InPlaceRenamed = inPlaceRenamed
- op.OriginalDirPath = originalDirPath
- op.GeneratedFiles = generatedFilesJSON
Caller persists via repo.Update after calling this.
Types ¶
type FileMove ¶
type FileMove struct {
OriginalPath string `json:"original_path"` // Where the file was before organize
NewPath string `json:"new_path"` // Where the file is after organize
}
FileMove represents a file that was moved during organize and should be moved back on revert.
type GeneratedFilesJSON ¶
type GeneratedFilesJSON struct {
Delete []string `json:"delete,omitempty"` // Files to delete on revert (NFO, images, screenshots)
MoveBack []FileMove `json:"move_back,omitempty"` // Files to move back on revert (subtitles)
}
GeneratedFilesJSON is the JSON structure stored in BatchFileOperation.GeneratedFiles. Phase 3 (Organize Integration) populates this during organize; Reverter consumes it.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger handles logging operations to the history database
func (*Logger) CleanupOldRecords ¶
CleanupOldRecords removes history records older than the specified duration
func (*Logger) GetByMovieID ¶
GetByMovieID retrieves history for a specific movie
func (*Logger) GetByOperation ¶
GetByOperation retrieves history for a specific operation type
func (*Logger) GetByStatus ¶
GetByStatus retrieves history with a specific status
func (*Logger) LogDownload ¶
LogDownload logs a media download operation
func (*Logger) LogOrganize ¶
LogOrganize logs a file organization operation
type NFOSnapshotResult ¶
type NFOSnapshotResult struct {
Content string // NFO file content (empty if no NFO found)
FoundPath string // Canonical path where the NFO was found (empty if not found)
}
NFOSnapshotResult holds the result of reading an NFO snapshot.
func ReadNFOSnapshot ¶
func ReadNFOSnapshot(fs afero.Fs, candidatePaths ...string) NFOSnapshotResult
ReadNFOSnapshot reads existing NFO content by trying each candidate path in order. Returns an NFOSnapshotResult with the content and the canonical path of the first file that exists. Returns empty Content and FoundPath if no file exists. Uses filepath.Abs + filepath.Clean for path canonicalization (T-03-01).
type RevertBatchResult ¶
type RevertBatchResult struct {
Total int // Total operations processed
Succeeded int // Successfully reverted
Skipped int // Skipped (e.g., anchor missing)
Failed int // Failed to revert
Outcomes []RevertFileResult // Per-operation outcomes (includes skipped and failed)
}
RevertBatchResult summarizes the outcome of a batch-level revert.
type RevertFileResult ¶
type RevertFileResult struct {
OperationID uint // BatchFileOperation.ID
MovieID string // Movie identifier
OriginalPath string
NewPath string
Outcome string // RevertOutcome: reverted, skipped, or failed
Reason string // RevertReason: why the outcome occurred (empty for success)
Error string // Error message for failed outcomes
}
RevertFileResult records a per-operation revert outcome with reason tracking (D-06).
type Reverter ¶
type Reverter struct {
// contains filtered or unexported fields
}
Reverter handles reverting file organization operations. It reads BatchFileOperation records from the database, performs inverse file operations via afero, and tracks per-operation revert status.
func NewReverter ¶
func NewReverter(fs afero.Fs, batchFileOpRepo database.BatchFileOperationRepositoryInterface) *Reverter
NewReverter creates a new Reverter with the given filesystem and repository.
func (*Reverter) RevertBatch ¶
RevertBatch reverts all operations in a batch (D-02, D-04). It uses best-effort processing: individual failures don't abort the batch. After all operations are processed, it sweeps empty destination directories.
func (*Reverter) RevertScrape ¶
func (r *Reverter) RevertScrape(ctx context.Context, batchJobID string, movieID string) (*RevertBatchResult, error)
RevertScrape reverts only the operations for a specific movie within a batch (HIST-04).