history

package
v0.3.2-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func DetermineOperationType(moveFiles bool, linkMode organizer.LinkMode, isUpdateMode bool) string

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 NewLogger

func NewLogger(db *database.DB) *Logger

NewLogger creates a new history logger

func (*Logger) CleanupOldRecords

func (l *Logger) CleanupOldRecords(olderThan time.Duration) error

CleanupOldRecords removes history records older than the specified duration

func (*Logger) GetByMovieID

func (l *Logger) GetByMovieID(movieID string) ([]models.History, error)

GetByMovieID retrieves history for a specific movie

func (*Logger) GetByOperation

func (l *Logger) GetByOperation(operation string, limit int) ([]models.History, error)

GetByOperation retrieves history for a specific operation type

func (*Logger) GetByStatus

func (l *Logger) GetByStatus(status string, limit int) ([]models.History, error)

GetByStatus retrieves history with a specific status

func (*Logger) GetRecent

func (l *Logger) GetRecent(limit int) ([]models.History, error)

GetRecent retrieves recent history records

func (*Logger) GetStats

func (l *Logger) GetStats() (*Stats, error)

GetStats returns statistics about operations

func (*Logger) LogDownload

func (l *Logger) LogDownload(movieID, url, localPath, mediaType string, err error) error

LogDownload logs a media download operation

func (*Logger) LogNFO

func (l *Logger) LogNFO(movieID, nfoPath string, err error) error

LogNFO logs an NFO generation operation

func (*Logger) LogOrganize

func (l *Logger) LogOrganize(movieID, originalPath, newPath string, dryRun bool, err error) error

LogOrganize logs a file organization operation

func (*Logger) LogRevert

func (l *Logger) LogRevert(movieID, originalPath, revertedFrom string, err error) error

LogRevert logs a revert operation

func (*Logger) LogScrape

func (l *Logger) LogScrape(movieID, sourceURL string, metadata interface{}, err error) error

LogScrape logs a metadata scraping 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

func (r *Reverter) RevertBatch(ctx context.Context, batchJobID string) (*RevertBatchResult, error)

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).

type Stats

type Stats struct {
	Total    int64
	Success  int64
	Failed   int64
	Reverted int64
	Scrape   int64
	Organize int64
	Download int64
	NFO      int64
}

Stats represents history statistics

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL