Documentation
¶
Overview ¶
Package fingerprints provides CRUD operations on the file_fingerprints table.
A file_fingerprint row stores one algorithm's fingerprint for one file. The MVP only writes sha256 rows for exact-content move/rename detection, but the schema is already shape-compatible with future fuzzy algorithms (cover pHash, text SimHash, Chromaprint, etc.) so they can reuse the same table, service, and generation job.
Index ¶
- type Service
- func (svc *Service) CountForFile(ctx context.Context, fileID int) (int, error)
- func (svc *Service) DeleteForFile(ctx context.Context, fileID int) error
- func (svc *Service) DocumentHashesOfBooks(ctx context.Context, bookIDs []int) ([]string, error)
- func (svc *Service) FindDocumentHash(ctx context.Context, hash string) ([]*models.DocumentHash, error)
- func (svc *Service) FindDocumentLink(ctx context.Context, userID int, hash string) (*models.DocumentHash, error)
- func (svc *Service) FindFilesByHash(ctx context.Context, libraryID int, algorithm, value string) ([]*models.File, error)
- func (svc *Service) Insert(ctx context.Context, fileID int, algorithm, value string) error
- func (svc *Service) LinkDocument(ctx context.Context, userID, fileID int, deliveredFileType, hash string) error
- func (svc *Service) LinkedHashesOfBooks(ctx context.Context, userID int, bookIDs []int) ([]string, error)
- func (svc *Service) ListFilesMissingAlgorithm(ctx context.Context, libraryID int, algorithm string) ([]int, error)
- func (svc *Service) ListForFile(ctx context.Context, fileID int, algorithm string) ([]*models.FileFingerprint, error)
- func (svc *Service) ListMainFilesMissingAlgorithm(ctx context.Context, libraryID int, algorithm string) ([]int, error)
- func (svc *Service) RecordDocumentHash(ctx context.Context, fileID int, deliveredFileType, hash string) error
- func (svc *Service) RecordOriginalDocumentHash(ctx context.Context, fileID int, fileType, hash string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) CountForFile ¶
CountForFile returns how many fingerprints exist for a file (across all algorithms).
func (*Service) DeleteForFile ¶
DeleteForFile removes all fingerprints for a file. Called when a file's content changes (size/mtime mismatch during rescan) so the next hash generation job recomputes a fresh fingerprint.
func (*Service) DocumentHashesOfBooks ¶ added in v0.8.0
DocumentHashesOfBooks returns every document hash in the map (ADR 0014) that names a File of one of bookIDs.
func (*Service) FindDocumentHash ¶ added in v0.7.0
func (svc *Service) FindDocumentHash(ctx context.Context, hash string) ([]*models.DocumentHash, error)
FindDocumentHash returns every File a KOReader document hash maps to, each with its File loaded, oldest File first. The caller resolves them through the user's library access.
func (*Service) FindDocumentLink ¶ added in v0.8.0
func (svc *Service) FindDocumentLink(ctx context.Context, userID int, hash string) (*models.DocumentHash, error)
FindDocumentLink returns the File userID linked a KOReader document hash to, as a user-made entry with its File loaded, or nil for none.
func (*Service) FindFilesByHash ¶
func (svc *Service) FindFilesByHash(ctx context.Context, libraryID int, algorithm, value string) ([]*models.File, error)
FindFilesByHash returns all files in the library whose fingerprint for the given algorithm matches value. Used for move detection.
func (*Service) Insert ¶
Insert upserts a fingerprint for (file_id, algorithm). If a row already exists for this pair the call is a no-op (ON CONFLICT DO NOTHING) — callers that need to replace a stale value should DeleteForFile first.
func (*Service) LinkDocument ¶ added in v0.8.0
func (svc *Service) LinkDocument(ctx context.Context, userID, fileID int, deliveredFileType, hash string) error
LinkDocument records that userID linked a KOReader copy with document hash to fileID, delivered as deliveredFileType (ADR 0017). Linking the copy again replaces the link.
func (*Service) LinkedHashesOfBooks ¶ added in v0.8.0
func (svc *Service) LinkedHashesOfBooks(ctx context.Context, userID int, bookIDs []int) ([]string, error)
LinkedHashesOfBooks returns the document hash of every copy userID linked to a File of one of bookIDs.
func (*Service) ListFilesMissingAlgorithm ¶
func (svc *Service) ListFilesMissingAlgorithm(ctx context.Context, libraryID int, algorithm string) ([]int, error)
ListFilesMissingAlgorithm returns IDs of files in the library that do not yet have a fingerprint for the given algorithm. Used by the hash generation job to determine what work needs doing.
Includes supplement files by design: supplements are real files on disk and benefit from content-hash move/rename detection just like main files. Callers that only want main files should filter the result in Go.
func (*Service) ListForFile ¶
func (svc *Service) ListForFile(ctx context.Context, fileID int, algorithm string) ([]*models.FileFingerprint, error)
ListForFile returns all fingerprints for a file matching the given algorithm. Used by the scan move reconciliation phase to look up each orphan's stored sha256.
func (*Service) ListMainFilesMissingAlgorithm ¶ added in v0.7.0
func (svc *Service) ListMainFilesMissingAlgorithm(ctx context.Context, libraryID int, algorithm string) ([]int, error)
ListMainFilesMissingAlgorithm is ListFilesMissingAlgorithm for main Files alone, for fingerprints only something that reads the File needs.
func (*Service) RecordDocumentHash ¶ added in v0.7.0
func (svc *Service) RecordDocumentHash(ctx context.Context, fileID int, deliveredFileType, hash string) error
RecordDocumentHash maps a KOReader document hash to fileID delivered as deliveredFileType. Recording one already mapped is a no-op.
func (*Service) RecordOriginalDocumentHash ¶ added in v0.7.0
func (svc *Service) RecordOriginalDocumentHash(ctx context.Context, fileID int, fileType, hash string) error
RecordOriginalDocumentHash maps the hash of fileID's Original File, and marks its current bytes as hashed. fileType is the File's own type.