Documentation
¶
Index ¶
- Constants
- func DeleteCachedFile(cacheDir string, fileID int, ext string) error
- func DeleteKepubCachedFile(cacheDir string, fileID int) error
- func DeletePluginCachedFile(cacheDir string, fileID int, formatID string) error
- func FormatDownloadFilename(book *models.Book, file *models.File) string
- func FormatKepubDownloadFilename(book *models.Book, file *models.File) string
- func FormatPluginDownloadFilename(book *models.Book, file *models.File, formatID string) string
- func GetCachedFilePath(cacheDir string, fileID int, ext string, currentHash string) (string, error)
- func GetKepubCachedFilePath(cacheDir string, fileID int, currentHash string) (string, error)
- func GetPluginCachedFilePath(cacheDir string, fileID int, formatID, currentHash string) (string, error)
- func GetTotalCacheSize(cacheDir string) (int64, error)
- func RunCleanup(cacheDir string, maxSizeBytes int64) error
- func UpdateKepubLastAccessed(cacheDir string, fileID int) error
- func UpdateLastAccessed(cacheDir string, fileID int) error
- func UpdatePluginLastAccessed(cacheDir string, fileID int, formatID string) error
- func WriteKepubMetadata(cacheDir string, meta *CacheMetadata) error
- func WriteMetadata(cacheDir string, meta *CacheMetadata) error
- func WritePluginMetadata(cacheDir string, fileID int, formatID string, meta *CacheMetadata) error
- type Cache
- func (c *Cache) Dir() string
- func (c *Cache) GetCachedPath(fileID int, fileType string, book *models.Book, file *models.File) (string, error)
- func (c *Cache) GetOrGenerate(ctx context.Context, book *models.Book, file *models.File) (cachedPath string, downloadFilename string, err error)
- func (c *Cache) GetOrGenerateKepub(ctx context.Context, book *models.Book, file *models.File) (cachedPath string, downloadFilename string, err error)
- func (c *Cache) GetOrGeneratePlugin(ctx context.Context, book *models.Book, file *models.File, ...) (cachedPath string, downloadFilename string, err error)
- func (c *Cache) Invalidate(fileID int, fileType string) error
- func (c *Cache) InvalidateKepub(fileID int) error
- func (c *Cache) InvalidatePlugin(fileID int, formatID string) error
- func (c *Cache) MaxSize() int64
- func (c *Cache) TriggerCleanup()
- type CacheMetadata
- func ListCacheEntries(cacheDir string) ([]*CacheMetadata, error)
- func ReadKepubMetadata(cacheDir string, fileID int) (*CacheMetadata, error)
- func ReadMetadata(cacheDir string, fileID int) (*CacheMetadata, error)
- func ReadPluginMetadata(cacheDir string, fileID int, formatID string) (*CacheMetadata, error)
- type CleanupStats
- type Fingerprint
- type FingerprintAuthor
- type FingerprintChapter
- type FingerprintCover
- type FingerprintIdentifier
- type FingerprintNarrator
- type FingerprintSeries
Constants ¶
const ( FormatOriginal = "original" FormatKepub = "kepub" )
Download format constants.
const CleanupThreshold = 0.8
CleanupThreshold is the percentage of maxSize to reduce the cache to during cleanup. For example, 0.8 means cleanup will reduce the cache to 80% of maxSize.
Variables ¶
This section is empty.
Functions ¶
func DeleteCachedFile ¶
DeleteCachedFile removes both the cached file and its metadata.
func DeleteKepubCachedFile ¶
DeleteKepubCachedFile removes both the cached KePub file and its metadata.
func DeletePluginCachedFile ¶
DeletePluginCachedFile removes both the cached plugin file and its metadata.
func FormatDownloadFilename ¶
FormatDownloadFilename generates a formatted filename for downloading a file. Format: [Author] Series #Number - Title.ext For audiobooks with narrators: [Author] Series #Number - Title {Narrator}.ext If no series: [Author] Title.ext. If no author: Title.ext.
func FormatKepubDownloadFilename ¶
FormatKepubDownloadFilename generates a formatted filename for downloading a KePub file. Uses Kobo-safe characters only to ensure compatibility with Kobo e-readers. Format: Author - Series Number - Title.kepub.epub (no brackets, no hash symbols).
func FormatPluginDownloadFilename ¶
FormatPluginDownloadFilename generates a formatted filename for a plugin-generated download. It replaces the file extension with the plugin's format ID.
func GetCachedFilePath ¶
GetCachedFilePath returns the path to a cached file if it exists and is valid. Returns empty string if the cache is invalid or doesn't exist.
func GetKepubCachedFilePath ¶
GetKepubCachedFilePath returns the path to a cached KePub file if it exists and is valid. Returns empty string if the cache is invalid or doesn't exist.
func GetPluginCachedFilePath ¶
func GetPluginCachedFilePath(cacheDir string, fileID int, formatID, currentHash string) (string, error)
GetPluginCachedFilePath returns the path to a cached plugin file if it exists and is valid. Returns empty string if the cache is invalid or doesn't exist.
func GetTotalCacheSize ¶
GetTotalCacheSize returns the total size of all cached files in bytes.
func RunCleanup ¶
RunCleanup removes cached files until the total size is below the threshold. Files are removed in LRU (least recently used) order.
func UpdateKepubLastAccessed ¶
UpdateKepubLastAccessed updates the last accessed time for a cached KePub file.
func UpdateLastAccessed ¶
UpdateLastAccessed updates the last accessed time for a cached file.
func UpdatePluginLastAccessed ¶
UpdatePluginLastAccessed updates the last accessed time for a cached plugin file.
func WriteKepubMetadata ¶
func WriteKepubMetadata(cacheDir string, meta *CacheMetadata) error
WriteKepubMetadata writes the cache metadata for a KePub cache entry.
func WriteMetadata ¶
func WriteMetadata(cacheDir string, meta *CacheMetadata) error
WriteMetadata writes the cache metadata for a file ID.
func WritePluginMetadata ¶
func WritePluginMetadata(cacheDir string, fileID int, formatID string, meta *CacheMetadata) error
WritePluginMetadata writes the cache metadata for a plugin cache entry.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache manages the download cache for generated files.
func (*Cache) GetCachedPath ¶
func (c *Cache) GetCachedPath(fileID int, fileType string, book *models.Book, file *models.File) (string, error)
GetCachedPath returns the path to a cached file if it exists and is valid. Returns empty string if the cache doesn't exist or is invalid.
func (*Cache) GetOrGenerate ¶
func (c *Cache) GetOrGenerate(ctx context.Context, book *models.Book, file *models.File) (cachedPath string, downloadFilename string, err error)
GetOrGenerate returns the path to a cached file, generating it if necessary. It returns the cached file path, the formatted download filename, and any error.
func (*Cache) GetOrGenerateKepub ¶
func (c *Cache) GetOrGenerateKepub(ctx context.Context, book *models.Book, file *models.File) (cachedPath string, downloadFilename string, err error)
GetOrGenerateKepub returns the path to a cached KePub file, generating it if necessary. It returns the cached file path, the formatted download filename, and any error. Returns ErrKepubNotSupported if the file type cannot be converted to KePub.
func (*Cache) GetOrGeneratePlugin ¶
func (c *Cache) GetOrGeneratePlugin(ctx context.Context, book *models.Book, file *models.File, generator *plugins.PluginGenerator) (cachedPath string, downloadFilename string, err error)
GetOrGeneratePlugin returns the path to a cached plugin-generated file. The pluginGenerator handles both generation and fingerprinting.
func (*Cache) Invalidate ¶
Invalidate removes the cached file for a given file ID.
func (*Cache) InvalidateKepub ¶
InvalidateKepub removes the cached KePub file for a given file ID.
func (*Cache) InvalidatePlugin ¶
InvalidatePlugin removes the cached plugin file for a given file ID and format.
func (*Cache) TriggerCleanup ¶
func (c *Cache) TriggerCleanup()
TriggerCleanup runs cache cleanup if the cache exceeds the max size. This runs in the current goroutine - call with `go` to run in background.
type CacheMetadata ¶
type CacheMetadata struct {
FileID int `json:"file_id"`
Format string `json:"format,omitempty"` // "original" or "kepub"
FingerprintHash string `json:"fingerprint_hash"`
GeneratedAt time.Time `json:"generated_at"`
LastAccessedAt time.Time `json:"last_accessed_at"`
SizeBytes int64 `json:"size_bytes"`
}
CacheMetadata stores information about a cached file.
func ListCacheEntries ¶
func ListCacheEntries(cacheDir string) ([]*CacheMetadata, error)
ListCacheEntries returns all cache entries in the directory.
func ReadKepubMetadata ¶
func ReadKepubMetadata(cacheDir string, fileID int) (*CacheMetadata, error)
ReadKepubMetadata reads the cache metadata for a KePub cache entry. Returns nil if the metadata file doesn't exist.
func ReadMetadata ¶
func ReadMetadata(cacheDir string, fileID int) (*CacheMetadata, error)
ReadMetadata reads the cache metadata for a file ID. Returns nil if the metadata file doesn't exist.
func ReadPluginMetadata ¶
func ReadPluginMetadata(cacheDir string, fileID int, formatID string) (*CacheMetadata, error)
ReadPluginMetadata reads the cache metadata for a plugin cache entry. Returns nil if the metadata file doesn't exist.
type CleanupStats ¶
type CleanupStats struct {
FilesRemoved int
BytesRemoved int64
FilesRemained int
BytesRemained int64
}
CleanupStats holds statistics about a cleanup operation.
func RunCleanupWithStats ¶
func RunCleanupWithStats(cacheDir string, maxSizeBytes int64) (*CleanupStats, error)
RunCleanupWithStats performs cleanup and returns statistics.
type Fingerprint ¶
type Fingerprint struct {
Title string `json:"title"`
Subtitle *string `json:"subtitle,omitempty"`
Description *string `json:"description,omitempty"`
Authors []FingerprintAuthor `json:"authors"`
Narrators []FingerprintNarrator `json:"narrators"`
Series []FingerprintSeries `json:"series"`
Genres []string `json:"genres"`
Tags []string `json:"tags"`
Identifiers []FingerprintIdentifier `json:"identifiers,omitempty"`
URL *string `json:"url,omitempty"`
Publisher *string `json:"publisher,omitempty"`
Imprint *string `json:"imprint,omitempty"`
ReleaseDate *time.Time `json:"release_date,omitempty"`
Cover *FingerprintCover `json:"cover,omitempty"`
CoverPage *int `json:"cover_page,omitempty"` // For CBZ files: page index of cover
Chapters []FingerprintChapter `json:"chapters,omitempty"`
Format string `json:"format,omitempty"` // Download format: original, kepub, or plugin:<id>
Name *string `json:"name,omitempty"` // File name (edition name)
PluginFingerprint string `json:"plugin_fingerprint,omitempty"` // Plugin-specific fingerprint for cache invalidation
}
Fingerprint represents the metadata that affects file generation. Changes to any of these fields should invalidate the cached file.
func ComputeFingerprint ¶
ComputeFingerprint creates a fingerprint from a book and file.
func (*Fingerprint) Equal ¶
func (fp *Fingerprint) Equal(other *Fingerprint) bool
Equal compares two fingerprints for equality.
func (*Fingerprint) Hash ¶
func (fp *Fingerprint) Hash() (string, error)
Hash computes a SHA256 hash of the fingerprint.
type FingerprintAuthor ¶
type FingerprintAuthor struct {
Name string `json:"name"`
Role *string `json:"role,omitempty"` // CBZ author role (writer, penciller, etc.)
SortOrder int `json:"sort_order"`
}
FingerprintAuthor represents author information for fingerprinting.
type FingerprintChapter ¶
type FingerprintChapter struct {
Title string `json:"title"`
SortOrder int `json:"sort_order"`
StartPage *int `json:"start_page,omitempty"`
StartTimestampMs *int64 `json:"start_timestamp_ms,omitempty"`
Href *string `json:"href,omitempty"`
Children []FingerprintChapter `json:"children,omitempty"`
}
FingerprintChapter represents chapter information for fingerprinting.
type FingerprintCover ¶
type FingerprintCover struct {
Path string `json:"path"`
MimeType string `json:"mime_type"`
ModTime time.Time `json:"mod_time"`
}
FingerprintCover represents cover image information for fingerprinting.
type FingerprintIdentifier ¶
FingerprintIdentifier represents identifier information for fingerprinting.
type FingerprintNarrator ¶
FingerprintNarrator represents narrator information for fingerprinting.
type FingerprintSeries ¶
type FingerprintSeries struct {
Name string `json:"name"`
Number *float64 `json:"number,omitempty"`
SortOrder int `json:"sort_order"`
}
FingerprintSeries represents series information for fingerprinting.