diff --git a/services/favicon.ts b/services/favicon.ts new file mode 100644 index 00000000..f5ee0597 --- /dev/null +++ b/services/favicon.ts @@ -0,0 +1,46 @@ +/** + * Favicon Proxy Service + * + * Proxies favicon requests to DuckDuckGo's favicon service. + * This allows fetching favicons for any domain without CORS issues. + * + * Usage: GET /favicon?url=https://example.com + * Returns: The favicon image for the specified domain + */ + +export default { + async fetch(request: Request): Promise { + const requestUrl = new URL(request.url); + const targetUrl = requestUrl.searchParams.get('url'); + + if (!targetUrl) { + return new Response('Missing url parameter', { status: 400 }); + } + + let url: URL; + try { + url = new URL(targetUrl); + } catch { + return new Response('Invalid url parameter', { status: 400 }); + } + + // AI-provider-specific hacks + let hostname = url.hostname; + if (url.host === 'localhost:11434' || url.origin === '127.0.0.1:11434') { + hostname = 'ollama.com'; + } else if (url.host === 'generativelanguage.googleapis.com') { + hostname = 'gemini.google.com'; + } else if (url.host === 'api.z.ai') { + hostname = 'docs.z.ai'; + } + + // Strip `ai.` and `api.` subdomains for a better chance at finding a favicon + hostname = hostname.replace(/^(ai\.|api\.)/, ''); + + return fetchFavicon(hostname); + }, +}; + +function fetchFavicon(hostname: string): Promise { + return fetch(`https://external-content.duckduckgo.com/ip3/${hostname}.ico`); +} \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 5b9ede72..41c0d521 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -49,7 +49,7 @@ const defaultConfig: AppConfig = { projectTemplate: "https://gitlab.com/soapbox-pub/mkstack.git", esmUrl: "https://esm.shakespeare.diy", corsProxy: "https://proxy.shakespeare.diy/?url={href}", - faviconUrl: "https://external-content.duckduckgo.com/ip3/{hostname}.ico", + faviconUrl: "https://favicon.shakespeare.diy/?url={href}", previewDomain: "local-shakespeare.dev", showcaseEnabled: true, showcaseModerator: "npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc", diff --git a/src/pages/AISettings.tsx b/src/pages/AISettings.tsx index 271445f0..1b0b99d6 100644 --- a/src/pages/AISettings.tsx +++ b/src/pages/AISettings.tsx @@ -37,26 +37,6 @@ import type { AIProvider } from '@/contexts/AISettingsContext'; import { AI_PROVIDER_PRESETS, type PresetProvider } from '@/lib/aiProviderPresets'; import { ExternalFavicon } from '@/components/ExternalFavicon'; -/** A few provider-specific icon hacks */ -function getProviderIconUrl(provider: { id: string; baseURL: string }): string { - if (provider.id === 'ollama' && provider.baseURL === 'http://localhost:11434/v1') { - return 'https://ollama.com/'; - } else if (provider.baseURL === 'https://generativelanguage.googleapis.com/v1beta/openai') { - return 'https://gemini.google.com/'; - } else if (provider.baseURL === 'https://api.z.ai/api/paas/v4') { - return 'https://docs.z.ai/'; - } - try { - // Strip .ai and .api subdomains for a better chance at finding a favicon - const urlObj = new URL(provider.baseURL); - urlObj.hostname = urlObj.hostname.replace(/^(ai\.|api\.)/, ''); - return urlObj.toString(); - } catch { - // Fallback to baseURL - return provider.baseURL; - } -} - interface SortableProviderItemProps { provider: AIProvider; preset?: PresetProvider; @@ -103,7 +83,7 @@ function SortableProviderItem({ provider, preset, onRemove, onSetProvider, onOpe )} {provider.baseURL ? ( } /> @@ -390,7 +370,7 @@ export function AISettings() {
} /> diff --git a/src/pages/SystemSettings.tsx b/src/pages/SystemSettings.tsx index f6b7e7d7..69c5a650 100644 --- a/src/pages/SystemSettings.tsx +++ b/src/pages/SystemSettings.tsx @@ -330,7 +330,7 @@ export function SystemSettings() { { const value = e.target.value;