faviconCache: check favicon.ico explicitly

This commit is contained in:
Alex Gleason 2025-02-09 11:57:09 -06:00
parent e7027af1ae
commit 48507b7505
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 11 additions and 6 deletions

View file

@ -85,6 +85,16 @@ async function fetchFavicon(domain: string, signal?: AbortSignal): Promise<URL>
} }
} }
// 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' }); logi({ level: 'info', ns: 'ditto.favicon', domain, state: 'failed' });
throw new Error(`Favicon not found: ${domain}`); throw new Error(`Favicon not found: ${domain}`);

View file

@ -47,11 +47,6 @@ function renderAccount(event: Omit<DittoEvent, 'id' | 'sig'>, opts: ToAccountOpt
const parsed05 = stats?.nip05 ? parseNip05(stats.nip05) : undefined; const parsed05 = stats?.nip05 ? parseNip05(stats.nip05) : undefined;
const acct = parsed05?.handle || npub; 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 { html } = parseNoteContent(about || '', []);
const fields = _fields const fields = _fields
@ -137,7 +132,7 @@ function renderAccount(event: Omit<DittoEvent, 'id' | 'sig'>, opts: ToAccountOpt
is_local: parsed05?.domain === Conf.url.host, is_local: parsed05?.domain === Conf.url.host,
settings_store: opts.withSource ? opts.settingsStore : undefined, settings_store: opts.withSource ? opts.settingsStore : undefined,
tags: [...getTagSet(event.user?.tags ?? [], 't')], tags: [...getTagSet(event.user?.tags ?? [], 't')],
favicon, favicon: stats?.favicon,
}, },
nostr: { nostr: {
pubkey, pubkey,