fix(storage): stop deleting covers, place images and journey photos another row may still show

Replacing a trip or list cover, changing or deleting a place or saved-place
image and deleting a journey photo removed the bytes at once, without asking
whether a trip copy, a journey, a saved place or another photo row still
named them (#2924). Those paths now leave the object in place and the reclaim
job removes it once no row names it. A journey photo the user deletes takes
its local photo row with it when nothing else links it, so its bytes become
reclaimable instead of being kept by a row nobody sees.

A place image copied from a trip file is still dropped at once when the
update that would name it fails: that copy was never anyone else's.

Size and warning baselines follow the shrunk files.
This commit is contained in:
Maurice
2026-11-01 13:59:28 +01:00
parent 095bed2db8
commit db0fbc1ccd
19 changed files with 101 additions and 317 deletions
@@ -448,10 +448,8 @@ describe('TripsController (parity with the legacy /api/trips route)', async () =
const update = vi
.fn()
.mockReturnValue({ updatedTrip: { id: 9 }, changes: {}, newTitle: 'b', newReminder: 0, oldReminder: 0 });
const deleteOldCover = vi.fn();
const s = svc({
update,
deleteOldCover,
getRaw: vi.fn().mockReturnValue({ cover_image: null }),
} as Partial<TripsService>);
await tc(s).update(user, '9', { cover_image: 'https://images.unsplash.com/photo-123?w=1080' }, req);
@@ -591,16 +589,15 @@ describe('TripsController (parity with the legacy /api/trips route)', async () =
),
),
).toEqual({ status: 400, body: { error: 'No image uploaded' } });
const deleteOldCover = vi.fn();
const updateCoverImage = vi.fn();
const s = svc({
getRaw: vi.fn().mockReturnValue({ cover_image: '/old.jpg' }),
deleteOldCover,
updateCoverImage,
} as Partial<TripsService>);
expect(await tc(s).cover(user, '9', file)).toEqual({ cover_image: '/uploads/covers/abc.jpg' });
expect(storageStub.put).toHaveBeenCalledWith('covers', 'abc.jpg', { tmpPath: undefined });
expect(deleteOldCover).toHaveBeenCalledWith('/old.jpg');
// The replaced cover is left to the storage reclaim job: a copy may share it (#2924).
expect(storageStub.put).toHaveBeenCalledTimes(1);
expect(updateCoverImage).toHaveBeenCalledWith('9', '/uploads/covers/abc.jpg');
});