Photo: save path, is-local, content bytes, metadata and EXIF getters (closes #141)
check / check (push) Successful in 1m24s
check / check (push) Successful in 1m24s
`Photo` gains:
- `savePath` and `isLocal`: synchronous, disk only. Where `lib.backup()` writes the original under the library's `downloadDirectory`, and whether all of it is there; a copy only in the cache does not count.
- `content()` and `exif()`: async, may download. `exif()` reads the common EXIF fields of a JPEG and returns `{}` for anything else.
- The getters `modifiedAt` and `hash`, also on `PhotoRecord`, and `year`.
For a live photo the backup has not stored yet, `savePath` carries the title's extension, and the image may be stored under a different one. The JPEG EXIF scan moved to `src/exif.ts`. The exported `PhotoContent` interface gains `savePath` and `isLocal`.
Judgement call: `iso` is read only when the file stores it as a single number.
Model: opus-5-5
This commit was merged in pull request #142.
This commit is contained in:
@@ -108,6 +108,11 @@ export interface ContentOptions {
|
||||
export interface PhotoContent {
|
||||
original(fileID: number, opts?: ContentOptions): Promise<ContentResult>;
|
||||
thumbnail(fileID: number, opts?: ContentOptions): Promise<ContentResult>;
|
||||
// Where a backup stores the original, whether or not it is there yet. For
|
||||
// a live photo not yet stored, it carries the title's extension, and the
|
||||
// backup may store the image under a different one.
|
||||
savePath(fileID: number): string | undefined;
|
||||
isLocal(fileID: number): boolean;
|
||||
}
|
||||
|
||||
export interface EnsureResult {
|
||||
@@ -435,6 +440,31 @@ export class ContentCache implements PhotoContent, ThumbnailsAPI {
|
||||
return this.get(fileID, "thumbnail", "on-demand", opts?.onProgress);
|
||||
}
|
||||
|
||||
// Where a backup to the download directory stores the file's original,
|
||||
// whether or not it is there yet: for a live photo already stored, its
|
||||
// image. For a live photo not yet stored, it carries the title's
|
||||
// extension, and the backup may store the image under a different one.
|
||||
// Undefined with no download directory.
|
||||
savePath(fileID: number): string | undefined {
|
||||
const file = this.getFile(fileID);
|
||||
if (this.downloadDirectory === undefined || file === undefined)
|
||||
return undefined;
|
||||
const dir = join(this.downloadDirectory, "originals");
|
||||
return (
|
||||
storedOriginal(dir, file)?.path ?? join(dir, nameInOriginals(file))
|
||||
);
|
||||
}
|
||||
|
||||
// Whether the whole original is in the download directory, as a backup
|
||||
// stores it. A copy only in the cache does not count.
|
||||
isLocal(fileID: number): boolean {
|
||||
const file = this.getFile(fileID);
|
||||
if (this.downloadDirectory === undefined || file === undefined)
|
||||
return false;
|
||||
const dir = join(this.downloadDirectory, "originals");
|
||||
return storedOriginal(dir, file) !== undefined;
|
||||
}
|
||||
|
||||
// Get an original for a backup. One not present anywhere is written
|
||||
// straight to `destination` and recorded there, so no second copy lands
|
||||
// in the cache; one already present is returned where it is.
|
||||
|
||||
Reference in New Issue
Block a user