Skeudenn / main/services/thumbnail-cache / ThumbnailCache
Class: ThumbnailCache ​
Defined in: src/main/services/thumbnail-cache.ts:61
The thumbnails of the library. A cover is kept beside its comic (coverSidecarPath()), so it is shared with the library folder; the cache directory is the fallback for a comic whose folder can't be written to, and still serves the covers made before sidecars existed. Every generation goes through a single queue, one book at a time: a library page asking for hundreds of covers at once, or a rebuild after an import, must not open hundreds of archives in parallel. Concurrent requests for the same book share one generation.
Constructors ​
Constructor ​
new ThumbnailCache(
directory,open?):ThumbnailCache
Defined in: src/main/services/thumbnail-cache.ts:69
Parameters ​
directory ​
string
open? ​
(filePath) => Promise<ComicArchive>
Returns ​
ThumbnailCache
Properties ​
sidecars ​
sidecars:
boolean=true
Defined in: src/main/services/thumbnail-cache.ts:67
Whether new covers go beside the comic (else only to the local cache).
Methods ​
ensure() ​
ensure(
filePath,readFirstPage?):Promise<Uint8Array<ArrayBuffer> |null>
Defined in: src/main/services/thumbnail-cache.ts:102
The thumbnail of a book, generated and cached first when missing. readFirstPage reads the cover from an archive that is already open (the reader's); without it, the file is opened just for this. Resolves to null when the book has no image page or can't be read.
Parameters ​
filePath ​
string
readFirstPage? ​
() => Promise<ComicPage>
Returns ​
Promise<Uint8Array<ArrayBuffer> | null>
prune() ​
prune(
filePaths):Promise<void>
Defined in: src/main/services/thumbnail-cache.ts:185
Deletes every cached file that isn't the thumbnail of one of filePaths, including temporary files left by a crash. Queued like a generation, so it never deletes one being written.
Parameters ​
filePaths ​
readonly string[]
Returns ​
Promise<void>
read() ​
read(
filePath):Promise<Uint8Array<ArrayBuffer> |null>
Defined in: src/main/services/thumbnail-cache.ts:79
The cached thumbnail of a book, or null when there is none yet. Never generates one. The sidecar comes first, unless it is a cloud placeholder (reading it would download it): the local cache then answers, or nothing.
Parameters ​
filePath ​
string
Returns ​
Promise<Uint8Array<ArrayBuffer> | null>
rebuild() ​
rebuild(
filePaths):Promise<void>
Defined in: src/main/services/thumbnail-cache.ts:206
Brings the cache in line with the library after a JSON import: drops the thumbnails of books no longer listed, then generates the missing ones, one book at a time, giving earlier failures a new chance. Requests made meanwhile (the library page) take their turn between two books instead of waiting for the whole rebuild.
Parameters ​
filePaths ​
readonly string[]
Returns ​
Promise<void>
remove() ​
remove(
filePath):Promise<void>
Defined in: src/main/services/thumbnail-cache.ts:174
Deletes the local cache's thumbnail of a book (removed from the library); does nothing when there is none. A sidecar belongs to the comic's folder and is left alone. Queued like a generation, so one still running for this book finishes first and its file is deleted too, instead of being written after the deletion and left orphaned.
Parameters ​
filePath ​
string
Returns ​
Promise<void>
replace() ​
replace(
filePath,image):Promise<void>
Defined in: src/main/services/thumbnail-cache.ts:155
Replaces a book's cover with a picture chosen by the user (any image renderThumbnail() accepts: it is shrunk to the thumbnail size like a first page). Rejects with the decoding error when it isn't a usable image, leaving the current cover as it was. Queued like a generation. When the cover can't go beside the comic (setting off, read-only folder), an older sidecar is deleted if possible, since read() would prefer it.
Parameters ​
filePath ​
string
image ​
Uint8Array
Returns ​
Promise<void>
storeFromArchive() ​
storeFromArchive(
archive,maxWaitMs?):Promise<void>
Defined in: src/main/services/thumbnail-cache.ts:126
Generates the thumbnail of a book from an archive the caller has open (a folder scan), unless it is already cached. Never throws: a book without a cover only goes without a thumbnail. The caller is a timed decoder call (inspect), so the wait in the queue is bounded by maxWaitMs: past it the cover is given up (the queued generation then does nothing) and made later, on demand or by the next resynchronization, rather than letting the queue's backlog of covers cost the scan its own deadline.
Parameters ​
archive ​
maxWaitMs? ​
number = STORE_MAX_WAIT_MS
Returns ​
Promise<void>