Photo: one async method per EXIF field (closes #148)
check / check (push) Successful in 1m46s

Thirteen methods on Photo, make() through gpsAltitude(), each named after
its PhotoExif field and typed by it. Each calls exif() with the same opts
and returns that one field, or undefined when the file lacks it. A test
checks, on the JPEG fixture and on test/exif.heic, that every field
exif() returns has a method giving the same value. README and TODO.md
list them.

Model: opus-5-5
This commit is contained in:
2026-10-01 20:37:02 +00:00
parent 67d554fb46
commit b669df220a
4 changed files with 106 additions and 10 deletions
+27 -5
View File
@@ -6,8 +6,8 @@
* `Photo` objects that fetch through it, `lib.thumbnails.ensure` drives it, and
* a cached path shows up on the projected record. A library opened without a
* content source leaves those methods throwing rather than silently doing
* nothing. It also covers a `Photo`'s `savePath`, `isLocal`, `content()` and
* `exif()`.
* nothing. It also covers a `Photo`'s `savePath`, `isLocal`, `content()`,
* `exif()` and the methods that each return one field of `exif()`.
*/
import { describe, it, expect, beforeEach, afterEach } from "vitest";
@@ -420,8 +420,8 @@ describe("Photo save path, local copy, content and EXIF", () => {
await lib.close();
});
// What exif() returns for HEIC_WITH_EXIF, which holds the same values as
// JPEG_WITH_EXIF.
// What exif() returns for HEIC_WITH_EXIF, and for JPEG_WITH_EXIF, which
// holds the same values.
const heicFields: PhotoExif = {
make: "Canon",
model: "EOS R5",
@@ -462,9 +462,31 @@ describe("Photo save path, local copy, content and EXIF", () => {
await lib.close();
});
it.each([
["JPEG", JPEG_WITH_EXIF],
["HEIC", HEIC_WITH_EXIF],
])(
"has a method for each field exif() returns, giving the same value, for a %s",
async (_, bytes) => {
const lib = await open({ contentSource: stubSource(bytes) });
const photo = lib.photos.byID({ fileID: 1 })!;
const exif = await photo.exif();
// The file holds every field, so every method is checked.
expect(exif).toStrictEqual(heicFields);
for (const [field, value] of Object.entries(exif)) {
expect(await photo[field as keyof PhotoExif]()).toStrictEqual(
value,
);
}
await lib.close();
},
);
it("returns no EXIF fields for an original that is not an image", async () => {
const lib = await open();
expect(await lib.photos.byID({ fileID: 1 })!.exif()).toStrictEqual({});
const photo = lib.photos.byID({ fileID: 1 })!;
expect(await photo.exif()).toStrictEqual({});
expect(await photo.dateTimeOriginal()).toBeUndefined();
await lib.close();
});