Support more favicon cases for applinks

This commit is contained in:
Johannes Zellner
2023-07-10 15:10:50 +02:00
parent 3a5d570e3c
commit 25abd8a67d

View File

@@ -107,16 +107,23 @@ async function detectMetaInfo(applink) {
if (!favicon.endsWith('.png') && dom.window.document.querySelector('meta[itemprop="image"]')) favicon = dom.window.document.querySelector('meta[itemprop="image"]').content;
if (favicon) {
if (favicon.startsWith('/')) favicon = (redirectUri || applink.upstreamUri) + favicon;
favicon = new URL(favicon, redirectUri || applink.upstreamUri).toString();
debug(`detectMetaInfo: found icon: ${favicon}`);
const [error, response] = await safe(superagent.get(favicon));
if (error) debug(`Failed to fetch icon ${favicon}: `, error);
else if (response.ok && response.headers['content-type'] === 'image/png') applink.icon = response.body;
else if (response.ok) applink.icon = response.body;
else debug(`Failed to fetch icon ${favicon}: statusCode=${response.status}`);
}
if (!favicon) {
debug(`Unable to find a suitable icon for ${applink.upstreamUri}, try fallback favicon.ico`);
const [error, response] = await safe(superagent.get(applink.upstreamUri + '/favicon.ico'));
if (error) debug(`Failed to fetch icon ${favicon}: `, error);
else if (response.ok) applink.icon = response.body;
else debug(`Failed to fetch icon ${favicon}: statusCode=${response.status}`);
} else {
debug(`Unable to find a suitable icon for ${applink.upstreamUri}`);
}
}