From 48507b7505bf295d4ee4a57afb5a2ca5b9bfba2f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 9 Feb 2025 11:57:09 -0600 Subject: [PATCH] faviconCache: check favicon.ico explicitly --- src/utils/favicon.ts | 10 ++++++++++ src/views/mastodon/accounts.ts | 7 +------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/utils/favicon.ts b/src/utils/favicon.ts index 549ae8df..b81b50cd 100644 --- a/src/utils/favicon.ts +++ b/src/utils/favicon.ts @@ -85,6 +85,16 @@ async function fetchFavicon(domain: string, signal?: AbortSignal): Promise } } + // Fallback to checking `/favicon.ico` of the domain. + const url = new URL('/favicon.ico', `https://${domain}/`); + const fallback = await fetchWorker(url, { method: 'HEAD', signal }); + const contentType = fallback.headers.get('content-type'); + + if (fallback.ok && contentType === 'image/vnd.microsoft.icon') { + logi({ level: 'info', ns: 'ditto.favicon', domain, state: 'found', url }); + return url; + } + logi({ level: 'info', ns: 'ditto.favicon', domain, state: 'failed' }); throw new Error(`Favicon not found: ${domain}`); diff --git a/src/views/mastodon/accounts.ts b/src/views/mastodon/accounts.ts index 3940b905..4e29e388 100644 --- a/src/views/mastodon/accounts.ts +++ b/src/views/mastodon/accounts.ts @@ -47,11 +47,6 @@ function renderAccount(event: Omit, opts: ToAccountOpt const parsed05 = stats?.nip05 ? parseNip05(stats.nip05) : undefined; const acct = parsed05?.handle || npub; - let favicon: string | undefined = stats?.favicon; - if (!favicon && parsed05) { - favicon = new URL('/favicon.ico', `https://${parsed05.domain}/`).toString(); - } - const { html } = parseNoteContent(about || '', []); const fields = _fields @@ -137,7 +132,7 @@ function renderAccount(event: Omit, opts: ToAccountOpt is_local: parsed05?.domain === Conf.url.host, settings_store: opts.withSource ? opts.settingsStore : undefined, tags: [...getTagSet(event.user?.tags ?? [], 't')], - favicon, + favicon: stats?.favicon, }, nostr: { pubkey,