Remove the content cache's handling of an earlier version's live-photo ZIP (closes #151)
check / check (push) Failing after 44s
check / check (push) Failing after 44s
quak is pre-1.0 and keeps no handling of old data. The content cache no longer recognises or removes a live photo that an earlier quak version cached as one ZIP. A live-photo download no longer removes what was at its destination before renaming the image and video into place; the rename already replaces it. The README sentences and the tests about that old ZIP are gone. The two removed tests that also covered current behaviour are replaced by tests with no ZIP: the cache re-fetching a live photo recorded with no video, and the library telling the cache which files are live photos when it opens. Model: opus-5-5
This commit was merged in pull request #152.
This commit is contained in:
@@ -176,7 +176,7 @@ describe("Library content wiring", () => {
|
||||
await lib.close();
|
||||
});
|
||||
|
||||
it("removes a live photo's ZIP an earlier version cached when it opens, and precaches its image and video", async () => {
|
||||
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> {
|
||||
@@ -197,7 +197,8 @@ describe("Library content wiring", () => {
|
||||
// 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.jpg"), livePhotoZip());
|
||||
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));
|
||||
@@ -208,7 +209,9 @@ describe("Library content wiring", () => {
|
||||
precached();
|
||||
},
|
||||
});
|
||||
expect(existsSync(join(originals, "1.jpg"))).toBe(false);
|
||||
expect(
|
||||
lib.photos.byID({ fileID: 1 })!.record().originalPath,
|
||||
).toBeUndefined();
|
||||
await done;
|
||||
|
||||
expect(readdirSync(originals).sort()).toEqual([
|
||||
@@ -216,6 +219,17 @@ describe("Library content wiring", () => {
|
||||
"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"),
|
||||
);
|
||||
|
||||
@@ -566,43 +566,6 @@ describe("ContentCache live photos", () => {
|
||||
expect(events).toEqual(["skipped"]);
|
||||
});
|
||||
|
||||
it("replaces a live photo an earlier version stored as a ZIP under the image's name", async () => {
|
||||
const { file: live, body } = await asLivePhoto(file(5, "IMG_5.HEIC"));
|
||||
mkdirSync(originals(), { recursive: true });
|
||||
writeFileSync(join(originals(), "5.HEIC"), livePhotoZip());
|
||||
const cache = cacheOf([live], new Map([[5, body]]));
|
||||
// Opened without being told that file 5 is a live photo, the cache
|
||||
// records the ZIP, and does not serve it.
|
||||
await cache.open();
|
||||
|
||||
const result = await cache.original(5);
|
||||
|
||||
expect(result.videoPath).toBe(join(originals(), "5.mov"));
|
||||
expect(readdirSync(originals()).sort()).toEqual([
|
||||
"5.heic",
|
||||
"5.livephoto.json",
|
||||
"5.mov",
|
||||
]);
|
||||
});
|
||||
|
||||
it("removes a live photo's ZIP an earlier version stored when it opens, so the precache fetches the image and video", async () => {
|
||||
const { file: live, body } = await asLivePhoto(file(5, "IMG_5.HEIC"));
|
||||
mkdirSync(originals(), { recursive: true });
|
||||
writeFileSync(join(originals(), "5.HEIC"), livePhotoZip());
|
||||
const cache = cacheOf([live], new Map([[5, body]]));
|
||||
|
||||
await cache.open((fileID) => fileID === 5);
|
||||
|
||||
expect(readdirSync(originals())).toEqual([]);
|
||||
expect(cache.pathsFor(5)).toEqual({});
|
||||
const [fetched] = await cache.ensureOriginals({ fileIDs: [5] });
|
||||
expect(fetched).toEqual({
|
||||
fileID: 5,
|
||||
path: join(originals(), "5.heic"),
|
||||
});
|
||||
expect(cache.pathsFor(5)).toEqual({ originalPath: fetched!.path });
|
||||
});
|
||||
|
||||
it("leaves the image and video another process has just stored when it opens before their JSON file is written", async () => {
|
||||
const { file: live, body } = await asLivePhoto(file(5, "IMG_5.HEIC"));
|
||||
const server = cdnSource(new Map([[5, body]]));
|
||||
@@ -633,6 +596,36 @@ describe("ContentCache live photos", () => {
|
||||
expect(second!.pathsFor(5)).toEqual({});
|
||||
});
|
||||
|
||||
it("fetches a live photo's image and video again when the cache opened before knowing it is a live photo and no JSON file names them", async () => {
|
||||
const { file: live, body } = await asLivePhoto(file(5, "IMG_5.HEIC"));
|
||||
mkdirSync(originals(), { recursive: true });
|
||||
writeFileSync(join(originals(), "5.heic"), "an image");
|
||||
writeFileSync(join(originals(), "5.mov"), "a video");
|
||||
const cache = cacheOf([live], new Map([[5, body]]));
|
||||
// Opened without being told that file 5 is a live photo, the cache
|
||||
// records one of the two files as its original, with no video.
|
||||
await cache.open();
|
||||
|
||||
const events: string[] = [];
|
||||
const result = await cache.original(5, {
|
||||
onProgress: (e) => events.push(e.status),
|
||||
});
|
||||
|
||||
expect(events.at(-1)).toBe("done");
|
||||
expect(result).toEqual({
|
||||
path: join(originals(), "5.heic"),
|
||||
videoPath: join(originals(), "5.mov"),
|
||||
bytes: IMAGE.length,
|
||||
});
|
||||
expect(readFileSync(result.path)).toEqual(Buffer.from(IMAGE));
|
||||
expect(readFileSync(result.videoPath!)).toEqual(Buffer.from(VIDEO));
|
||||
expect(
|
||||
JSON.parse(
|
||||
readFileSync(join(originals(), "5.livephoto.json"), "utf-8"),
|
||||
),
|
||||
).toEqual({ image: "5.heic", video: "5.mov" });
|
||||
});
|
||||
|
||||
it.each(["missing", "empty"])(
|
||||
"fetches a live photo again when the video its JSON file names is %s",
|
||||
async (state) => {
|
||||
|
||||
Reference in New Issue
Block a user