diff --git a/src/components/cards/SiteCard.vue b/src/components/cards/SiteCard.vue index d93de36d..3edb81a1 100644 --- a/src/components/cards/SiteCard.vue +++ b/src/components/cards/SiteCard.vue @@ -66,7 +66,7 @@ async function getSiteIcon() { try { const icon = await getCachedSiteIcon(siteId, async () => { - const response = await api.get<{ icon?: string }>(`site/icon/${siteId}`) + const response = await api.get<{ icon?: string }>(`site/icon/${siteId}`, { feedback: 'silent' }) return response?.icon || defaultSiteIcon }) siteIcon.value = getDisplayImageUrl(icon, globalSettingsStore.globalSettings.GLOBAL_IMAGE_CACHE) diff --git a/src/components/cards/SubtitleCard.vue b/src/components/cards/SubtitleCard.vue index 4fa2ed43..874798db 100644 --- a/src/components/cards/SubtitleCard.vue +++ b/src/components/cards/SubtitleCard.vue @@ -44,7 +44,7 @@ async function getSiteIcon() { try { const icon = await getCachedSiteIcon(subtitle.value.site, async () => { try { - const response = await api.get<{ icon?: string }>(`site/icon/${subtitle.value?.site}`) + const response = await api.get<{ icon?: string }>(`site/icon/${subtitle.value?.site}`, { feedback: 'silent' }) return response?.icon || '' } catch (error) { console.error('Failed to load site icon:', error) diff --git a/src/components/cards/SubtitleItem.vue b/src/components/cards/SubtitleItem.vue index c8bb115b..99f099d1 100644 --- a/src/components/cards/SubtitleItem.vue +++ b/src/components/cards/SubtitleItem.vue @@ -43,7 +43,7 @@ async function getSiteIcon() { try { const icon = await getCachedSiteIcon(subtitle.value.site, async () => { try { - const response = await api.get<{ icon?: string }>(`site/icon/${subtitle.value?.site}`) + const response = await api.get<{ icon?: string }>(`site/icon/${subtitle.value?.site}`, { feedback: 'silent' }) return response?.icon || '' } catch (error) { console.error('Failed to load site icon:', error) diff --git a/src/components/cards/TorrentCard.vue b/src/components/cards/TorrentCard.vue index e13868aa..13042d78 100644 --- a/src/components/cards/TorrentCard.vue +++ b/src/components/cards/TorrentCard.vue @@ -56,7 +56,7 @@ async function getSiteIcon(site: number | undefined) { try { const icon = await getCachedSiteIcon(site, async () => { try { - const response = await api.get<{ icon?: string }>(`site/icon/${site}`) + const response = await api.get<{ icon?: string }>(`site/icon/${site}`, { feedback: 'silent' }) return response?.icon || '' } catch (error) { console.error(error) diff --git a/src/components/cards/TorrentItem.vue b/src/components/cards/TorrentItem.vue index f5a000da..dbf8dcee 100644 --- a/src/components/cards/TorrentItem.vue +++ b/src/components/cards/TorrentItem.vue @@ -41,7 +41,7 @@ async function getSiteIcon(site: number | undefined) { try { const icon = await getCachedSiteIcon(site, async () => { try { - const response = await api.get<{ icon?: string }>(`site/icon/${site}`) + const response = await api.get<{ icon?: string }>(`site/icon/${site}`, { feedback: 'silent' }) return response?.icon || '' } catch (error) { console.error('Failed to load site icon:', error) diff --git a/src/components/cards/__tests__/SiteCard.spec.ts b/src/components/cards/__tests__/SiteCard.spec.ts index d468670e..eabed872 100644 --- a/src/components/cards/__tests__/SiteCard.spec.ts +++ b/src/components/cards/__tests__/SiteCard.spec.ts @@ -237,10 +237,10 @@ describe('SiteCard interactions', () => { expect(mocks.openSharedDialog).not.toHaveBeenCalled() }) - it('falls back to the default icon when the icon request fails', async () => { + it('silently falls back to the default icon when the icon is unavailable', async () => { const site = createSite() const requested = vi.fn() - server.use(siteIconHandler(site.id, null, 500, requested)) + server.use(siteIconHandler(site.id, null, 200, requested)) const { container } = await renderWithProviders(SiteCard, { global: { stubs: imageStubs }, props: { site }, @@ -249,5 +249,6 @@ describe('SiteCard interactions', () => { await waitFor(() => expect(requested).toHaveBeenCalledOnce()) await waitFor(() => expect(getActiveRequestsCount()).toBe(0)) await waitFor(() => expect(container.querySelector('img')?.src).toContain('/site.webp')) + expect(mocks.toastError).not.toHaveBeenCalled() }) }) diff --git a/tests/support/msw/handlers/site.ts b/tests/support/msw/handlers/site.ts index 1b4720f8..f91101bd 100644 --- a/tests/support/msw/handlers/site.ts +++ b/tests/support/msw/handlers/site.ts @@ -133,6 +133,7 @@ function response(body: JsonBodyType, status: number) { return HttpResponse.json(body, { status }) } +/** 模拟站点图标接口,并保留后端缺失图标时的业务失败语义。 */ export function siteIconHandler( id: number, icon: string | null, @@ -141,7 +142,10 @@ export function siteIconHandler( ) { return http.get(siteApiUrls.icon(id), async () => { await onRequest() - return response(apiEnvelope(icon ? { icon } : {}, Boolean(icon)), status) + return response( + apiEnvelope(icon ? { icon } : {}, Boolean(icon), icon ? '' : '站点图标不存在!'), + status, + ) }) }