Remove the content cache's handling of an earlier version's live-photo ZIP (closes #151) #152

Merged
clawbot merged 3 commits from issue-151-remove-old-livephoto-zip into next 2026-10-02 04:14:30 +02:00
Showing only changes of commit 02afdd6d09 - Show all commits
+60
View File
@@ -176,6 +176,66 @@ describe("Library content wiring", () => {
await lib.close();
});
it("does not take a live photo's image or video with no JSON file as its original when it opens, and precaches both", async () => {
const { file: live, body } = await asLivePhoto(file(1, 1));
class LiveClient extends MockClient {
override async filesSince(): Promise<FilesPage> {
return { files: [live], deleted: [], cursor: 1 };
}
}
const originals = join(root, "cache", "originals");
const open = (opts: Partial<LibraryOptions>): Promise<Library> =>
Library.open({
client: new LiveClient(),
cacheDirectory: join(root, "cache"),
contentSource: cdnSource(new Map([[1, body]])),
refreshIntervalSeconds: 3600,
precacheThumbnails: false,
precacheOriginals: false,
...opts,
});
// A first run records the library, so the next one knows that file 1
// is a live photo when it opens the cache.
await (await open({})).close();
writeFileSync(join(originals, "1.heic"), "an image");
writeFileSync(join(originals, "1.mov"), "a video");
let precached!: () => void;
const done = new Promise<void>((r) => (precached = r));
const lib = await open({
precacheOriginals: true,
onProgress: (e) => {
if (e.operation === "precacheOriginals" && e.status === "done")
precached();
},
});
expect(
lib.photos.byID({ fileID: 1 })!.record().originalPath,
).toBeUndefined();
await done;
expect(readdirSync(originals).sort()).toEqual([
"1.heic",
"1.livephoto.json",
"1.mov",
]);
expect(readFileSync(join(originals, "1.heic"))).toEqual(
Buffer.from(IMAGE),
);
expect(readFileSync(join(originals, "1.mov"))).toEqual(
Buffer.from(VIDEO),
);
expect(
JSON.parse(
readFileSync(join(originals, "1.livephoto.json"), "utf-8"),
),
).toEqual({ image: "1.heic", video: "1.mov" });
expect(lib.photos.byID({ fileID: 1 })!.record().originalPath).toBe(
join(originals, "1.heic"),
);
await lib.close();
});
it("throws from content methods when opened without a content source", async () => {
const lib = await Library.open({
client: new MockClient(),