fix(immich): remove album photos on unlink

When unlinking an Immich album, photos synced from that album are now
deleted. A new `album_link_id` FK column on `trip_photos` tracks the
source album link at sync time; `deleteAlbumLink` deletes matching
photos before removing the link. Individually-added photos are
unaffected. The client now refreshes the photo grid after unlinking.

Adds integration tests IMMICH-020 through IMMICH-024.

Closes #398
This commit is contained in:
jubnl
2026-04-04 16:36:44 +02:00
parent 43c801232e
commit c4c3ea1e6d
5 changed files with 108 additions and 3 deletions

View File

@@ -387,6 +387,8 @@ export function createAlbumLink(
}
export function deleteAlbumLink(linkId: string, tripId: string, userId: number) {
db.prepare('DELETE FROM trip_photos WHERE album_link_id = ? AND trip_id = ? AND user_id = ?')
.run(linkId, tripId, userId);
db.prepare('DELETE FROM trip_album_links WHERE id = ? AND trip_id = ? AND user_id = ?')
.run(linkId, tripId, userId);
}
@@ -413,11 +415,11 @@ export async function syncAlbumAssets(
const assets = (albumData.assets || []).filter((a: any) => a.type === 'IMAGE');
const insert = db.prepare(
'INSERT OR IGNORE INTO trip_photos (trip_id, user_id, immich_asset_id, shared) VALUES (?, ?, ?, 1)'
'INSERT OR IGNORE INTO trip_photos (trip_id, user_id, immich_asset_id, shared, album_link_id) VALUES (?, ?, ?, 1, ?)'
);
let added = 0;
for (const asset of assets) {
const r = insert.run(tripId, userId, asset.id);
const r = insert.run(tripId, userId, asset.id, linkId);
if (r.changes > 0) added++;
}