mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-08-28 19:47:49 +08:00
fix(site): 静默处理站点图标缺失
This commit is contained in:
@@ -66,7 +66,7 @@ async function getSiteIcon() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const icon = await getCachedSiteIcon(siteId, async () => {
|
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
|
return response?.icon || defaultSiteIcon
|
||||||
})
|
})
|
||||||
siteIcon.value = getDisplayImageUrl(icon, globalSettingsStore.globalSettings.GLOBAL_IMAGE_CACHE)
|
siteIcon.value = getDisplayImageUrl(icon, globalSettingsStore.globalSettings.GLOBAL_IMAGE_CACHE)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ async function getSiteIcon() {
|
|||||||
try {
|
try {
|
||||||
const icon = await getCachedSiteIcon(subtitle.value.site, async () => {
|
const icon = await getCachedSiteIcon(subtitle.value.site, async () => {
|
||||||
try {
|
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 || ''
|
return response?.icon || ''
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load site icon:', error)
|
console.error('Failed to load site icon:', error)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ async function getSiteIcon() {
|
|||||||
try {
|
try {
|
||||||
const icon = await getCachedSiteIcon(subtitle.value.site, async () => {
|
const icon = await getCachedSiteIcon(subtitle.value.site, async () => {
|
||||||
try {
|
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 || ''
|
return response?.icon || ''
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load site icon:', error)
|
console.error('Failed to load site icon:', error)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ async function getSiteIcon(site: number | undefined) {
|
|||||||
try {
|
try {
|
||||||
const icon = await getCachedSiteIcon(site, async () => {
|
const icon = await getCachedSiteIcon(site, async () => {
|
||||||
try {
|
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 || ''
|
return response?.icon || ''
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ async function getSiteIcon(site: number | undefined) {
|
|||||||
try {
|
try {
|
||||||
const icon = await getCachedSiteIcon(site, async () => {
|
const icon = await getCachedSiteIcon(site, async () => {
|
||||||
try {
|
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 || ''
|
return response?.icon || ''
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load site icon:', error)
|
console.error('Failed to load site icon:', error)
|
||||||
|
|||||||
@@ -237,10 +237,10 @@ describe('SiteCard interactions', () => {
|
|||||||
expect(mocks.openSharedDialog).not.toHaveBeenCalled()
|
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 site = createSite()
|
||||||
const requested = vi.fn()
|
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, {
|
const { container } = await renderWithProviders(SiteCard, {
|
||||||
global: { stubs: imageStubs },
|
global: { stubs: imageStubs },
|
||||||
props: { site },
|
props: { site },
|
||||||
@@ -249,5 +249,6 @@ describe('SiteCard interactions', () => {
|
|||||||
await waitFor(() => expect(requested).toHaveBeenCalledOnce())
|
await waitFor(() => expect(requested).toHaveBeenCalledOnce())
|
||||||
await waitFor(() => expect(getActiveRequestsCount()).toBe(0))
|
await waitFor(() => expect(getActiveRequestsCount()).toBe(0))
|
||||||
await waitFor(() => expect(container.querySelector<HTMLImageElement>('img')?.src).toContain('/site.webp'))
|
await waitFor(() => expect(container.querySelector<HTMLImageElement>('img')?.src).toContain('/site.webp'))
|
||||||
|
expect(mocks.toastError).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ function response(body: JsonBodyType, status: number) {
|
|||||||
return HttpResponse.json(body, { status })
|
return HttpResponse.json(body, { status })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 模拟站点图标接口,并保留后端缺失图标时的业务失败语义。 */
|
||||||
export function siteIconHandler(
|
export function siteIconHandler(
|
||||||
id: number,
|
id: number,
|
||||||
icon: string | null,
|
icon: string | null,
|
||||||
@@ -141,7 +142,10 @@ export function siteIconHandler(
|
|||||||
) {
|
) {
|
||||||
return http.get(siteApiUrls.icon(id), async () => {
|
return http.get(siteApiUrls.icon(id), async () => {
|
||||||
await onRequest()
|
await onRequest()
|
||||||
return response(apiEnvelope(icon ? { icon } : {}, Boolean(icon)), status)
|
return response(
|
||||||
|
apiEnvelope(icon ? { icon } : {}, Boolean(icon), icon ? '' : '站点图标不存在!'),
|
||||||
|
status,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user