diff --git a/app/src/immich.ts b/app/src/immich.ts index 0975305..b3cac5a 100644 --- a/app/src/immich.ts +++ b/app/src/immich.ts @@ -286,6 +286,15 @@ async function fetchShareByKey (key: string, password?: string, keyType: KeyType // This link has expired log('Expired link ' + key) } else { + if (!Array.isArray(link.assets)) { + // Immich can return a shared link with no `assets` array (seen on + // 3.0.x INDIVIDUAL shares - see #267). The album path above always + // populates `link.assets`, so this only bites non-album shares. + // Treat a missing array as empty rather than letting `.filter` of + // undefined reject and take the whole process down. + log('Shared link ' + key + ' returned no assets array (type ' + link.type + ')') + link.assets = [] + } // Filter assets to exclude trashed assets link.assets = link.assets.filter(asset => !asset.isTrashed) // Populate the shared assets with the public key/password diff --git a/app/tests/albumTimeline.test.ts b/app/tests/albumTimeline.test.ts index 7117cbf..7a598ae 100644 --- a/app/tests/albumTimeline.test.ts +++ b/app/tests/albumTimeline.test.ts @@ -134,6 +134,19 @@ describe('album timeline enumeration (Immich 3.0)', () => { expect(result.valid).toBe(false) }) + it('does not crash when an individual share returns no assets array (#267)', async () => { + // Immich 3.0.x can return an INDIVIDUAL shared link with no `assets` key. + // `.filter` of undefined used to reject and take the container down. + const noAssets = { type: 'INDIVIDUAL', key: 'real-key', allowDownload: true } + vi.stubGlobal('fetch', vi.fn(async (url: string) => { + if (url.includes('/shared-links/me')) return jsonResponse(noAssets) + throw new Error('Unexpected fetch to ' + url) + })) + const result = await getShareByKey(uniqueKey(), undefined, KeyType.key) + expect(result.valid).toBe(true) + expect(result.link!.assets).toEqual([]) + }) + it('is invalid (not cached empty) when timeline enumeration fails upstream', async () => { vi.stubGlobal('fetch', vi.fn(async (url: string) => { if (url.includes('/shared-links/me')) return jsonResponse(sharedLinkResponse())