atmosphere explorer
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add /favicon.ico fallback

Juliet 08adf4d0 411f5e11

+31 -32
+31 -32
src/worker.js
··· 586 586 } 587 587 } catch {} 588 588 589 - if (!faviconUrl) { 590 - faviconUrl = `https://${domain}/favicon.ico`; 591 - } 589 + const fallbackUrl = `https://${domain}/favicon.ico`; 590 + const urls = faviconUrl ? [faviconUrl, fallbackUrl] : [fallbackUrl]; 592 591 593 - try { 594 - const iconRes = await fetch(faviconUrl, { 595 - signal: AbortSignal.timeout(5000), 596 - redirect: "follow", 597 - }); 592 + for (const url of urls) { 593 + try { 594 + const iconRes = await fetch(url, { 595 + signal: AbortSignal.timeout(5000), 596 + redirect: "follow", 597 + }); 598 598 599 - if (!iconRes.ok) { 600 - return new Response("Favicon not found", { status: 404 }); 601 - } 599 + if (!iconRes.ok) continue; 602 600 603 - const contentType = iconRes.headers.get("content-type") ?? ""; 604 - if (!contentType.includes("image") && !contentType.includes("icon")) { 605 - return new Response("Not an image", { status: 404 }); 606 - } 601 + const contentType = iconRes.headers.get("content-type") ?? ""; 602 + if (contentType.includes("text/html") || contentType.includes("text/plain")) continue; 607 603 608 - const contentLength = parseInt(iconRes.headers.get("content-length") ?? "0", 10); 609 - if (contentLength > MAX_FAVICON_SIZE) { 610 - return new Response("Favicon too large", { status: 413 }); 611 - } 604 + const contentLength = parseInt(iconRes.headers.get("content-length") ?? "0", 10); 605 + if (contentLength > MAX_FAVICON_SIZE) { 606 + return new Response("Favicon too large", { status: 413 }); 607 + } 608 + 609 + const body = await iconRes.arrayBuffer(); 610 + if (body.byteLength > MAX_FAVICON_SIZE) { 611 + return new Response("Favicon too large", { status: 413 }); 612 + } 612 613 613 - const body = await iconRes.arrayBuffer(); 614 - if (body.byteLength > MAX_FAVICON_SIZE) { 615 - return new Response("Favicon too large", { status: 413 }); 614 + return new Response(body, { 615 + headers: { 616 + "Content-Type": contentType || "image/x-icon", 617 + "Cache-Control": "public, max-age=86400", 618 + "Access-Control-Allow-Origin": "*", 619 + }, 620 + }); 621 + } catch { 622 + continue; 616 623 } 624 + } 617 625 618 - return new Response(body, { 619 - headers: { 620 - "Content-Type": contentType, 621 - "Cache-Control": "public, max-age=86400", 622 - "Access-Control-Allow-Origin": "*", 623 - }, 624 - }); 625 - } catch { 626 - return new Response("Failed to fetch favicon", { status: 502 }); 627 - } 626 + return new Response("Favicon not found", { status: 404 }); 628 627 } 629 628 630 629 export default {