mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
faviconCache: check favicon.ico explicitly
This commit is contained in:
parent
e7027af1ae
commit
48507b7505
2 changed files with 11 additions and 6 deletions
|
|
@ -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' });
|
||||
|
||||
throw new Error(`Favicon not found: ${domain}`);
|
||||
|
|
|
|||
|
|
@ -47,11 +47,6 @@ function renderAccount(event: Omit<DittoEvent, 'id' | 'sig'>, 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<DittoEvent, 'id' | 'sig'>, 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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue