mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Add external provider icons with favicons
This commit is contained in:
15 files changed
+300
-89
No files matched your search
+32
-18
@@ -1,7 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Check, Bot, ArrowLeft, Trash2, GripVertical } from 'lucide-react';
|
||||
import { SiOpenai, SiAnthropic, SiGoogle, SiX } from '@icons-pack/react-simple-icons';
|
||||
import {
|
||||
DndContext,
|
||||
closestCenter,
|
||||
@@ -21,7 +20,6 @@ import {
|
||||
useSortable,
|
||||
} from '@dnd-kit/sortable';
|
||||
import { CSS } from '@dnd-kit/utilities';
|
||||
import { IconMasksTheater } from '@tabler/icons-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { PasswordInput } from '@/components/ui/password-input';
|
||||
@@ -37,21 +35,25 @@ import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useNavigate, Link } from 'react-router-dom';
|
||||
import type { AIProvider } from '@/contexts/AISettingsContext';
|
||||
import { AI_PROVIDER_PRESETS, type PresetProvider } from '@/lib/aiProviderPresets';
|
||||
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
||||
|
||||
function renderIcon(providerId: string, size = 16) {
|
||||
switch (providerId) {
|
||||
case 'shakespeare':
|
||||
return <IconMasksTheater size={size} />;
|
||||
case 'openai':
|
||||
return <SiOpenai size={size} />;
|
||||
case 'anthropic':
|
||||
return <SiAnthropic size={size} />;
|
||||
case 'google':
|
||||
return <SiGoogle size={size} />;
|
||||
case 'xai':
|
||||
return <SiX size={size} />;
|
||||
default:
|
||||
return <Bot size={size} />;
|
||||
/** 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +101,15 @@ function SortableProviderItem({ provider, preset, onRemove, onSetProvider, onOpe
|
||||
<GripVertical className="h-4 w-4" />
|
||||
</div>
|
||||
)}
|
||||
{renderIcon(provider.id)}
|
||||
{provider.baseURL ? (
|
||||
<ExternalFavicon
|
||||
url={getProviderIconUrl(provider)}
|
||||
size={16}
|
||||
fallback={<Bot size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Bot size={16} />
|
||||
)}
|
||||
<span className="font-medium">
|
||||
{preset?.name || provider.id}
|
||||
</span>
|
||||
@@ -379,7 +389,11 @@ export function AISettings() {
|
||||
<div key={preset.id} className="border rounded-lg p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
{renderIcon(preset.id)}
|
||||
<ExternalFavicon
|
||||
url={getProviderIconUrl(preset)}
|
||||
size={16}
|
||||
fallback={<Bot size={16} />}
|
||||
/>
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
{(preset.apiKeysURL && preset.id !== "routstr") && (
|
||||
|
||||
@@ -2,7 +2,6 @@ import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Rocket, ArrowLeft, Trash2, Check, GripVertical, ChevronDown } from 'lucide-react';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { SiNetlify, SiVercel } from '@icons-pack/react-simple-icons';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -28,7 +27,6 @@ import {
|
||||
useSortable,
|
||||
} from '@dnd-kit/sortable';
|
||||
import { CSS } from '@dnd-kit/utilities';
|
||||
import { IconMasksTheater } from '@tabler/icons-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { PasswordInput } from '@/components/ui/password-input';
|
||||
@@ -42,6 +40,8 @@ import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useNavigate, Link } from 'react-router-dom';
|
||||
import type { DeployProvider } from '@/contexts/DeploySettingsContext';
|
||||
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
||||
import { normalizeUrl } from '@/lib/faviconUrl';
|
||||
|
||||
interface PresetProvider {
|
||||
id: string;
|
||||
@@ -96,7 +96,18 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
||||
<GripVertical className="h-4 w-4" />
|
||||
</div>
|
||||
)}
|
||||
{renderIcon(provider.id)}
|
||||
{(() => {
|
||||
const url = getProviderUrl(provider);
|
||||
return url ? (
|
||||
<ExternalFavicon
|
||||
url={url}
|
||||
size={16}
|
||||
fallback={<Rocket size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Rocket size={16} />
|
||||
);
|
||||
})()}
|
||||
<span className="font-medium">
|
||||
{provider.name}
|
||||
</span>
|
||||
@@ -272,16 +283,35 @@ function generateCustomProviderId(type: string): string {
|
||||
return `${type}-${randomSegment}`;
|
||||
}
|
||||
|
||||
function renderIcon(providerId: string, size = 16) {
|
||||
switch (providerId) {
|
||||
function getProviderUrl(provider: DeployProvider | PresetProvider): string | null {
|
||||
switch (provider.type) {
|
||||
case 'shakespeare':
|
||||
return <IconMasksTheater size={size} />;
|
||||
// For Shakespeare providers, check for custom host first, then use default
|
||||
if ('host' in provider && provider.host) {
|
||||
return normalizeUrl(provider.host);
|
||||
}
|
||||
return 'https://shakespeare.diy';
|
||||
|
||||
case 'netlify':
|
||||
return <SiNetlify size={size} />;
|
||||
// For Netlify providers, check for custom baseURL first, then use default
|
||||
if ('baseURL' in provider && provider.baseURL) {
|
||||
return provider.baseURL;
|
||||
}
|
||||
return 'https://netlify.com';
|
||||
|
||||
case 'vercel':
|
||||
return <SiVercel size={size} />;
|
||||
// For Vercel providers, check for custom baseURL first, then use default
|
||||
if ('baseURL' in provider && provider.baseURL) {
|
||||
return provider.baseURL;
|
||||
}
|
||||
return 'https://vercel.com';
|
||||
|
||||
case 'nsite':
|
||||
// nsite uses Rocket icon fallback
|
||||
return null;
|
||||
|
||||
default:
|
||||
return <Rocket size={size} />;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -564,7 +594,18 @@ export function DeploySettings() {
|
||||
<div key={preset.id} className="border rounded-lg p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
{renderIcon(preset.id)}
|
||||
{(() => {
|
||||
const url = getProviderUrl(preset);
|
||||
return url ? (
|
||||
<ExternalFavicon
|
||||
url={url}
|
||||
size={16}
|
||||
fallback={<Rocket size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Rocket size={16} />
|
||||
);
|
||||
})()}
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
{preset.apiKeyURL && !isOAuthConfigured && (
|
||||
@@ -607,7 +648,18 @@ export function DeploySettings() {
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{renderIcon(preset.id)}
|
||||
{(() => {
|
||||
const url = getProviderUrl(preset);
|
||||
return url ? (
|
||||
<ExternalFavicon
|
||||
url={url}
|
||||
size={16}
|
||||
fallback={<Rocket size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Rocket size={16} />
|
||||
);
|
||||
})()}
|
||||
<span className="truncate text-ellipsis overflow-hidden">
|
||||
Connect to {preset.name}
|
||||
</span>
|
||||
|
||||
+16
-15
@@ -2,7 +2,6 @@ import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Check, GitBranch, ArrowLeft, Trash2, ChevronDown } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { SiGithub, SiGitlab } from '@icons-pack/react-simple-icons';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
@@ -20,6 +19,7 @@ import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import type { GitCredential } from '@/contexts/GitSettingsContext';
|
||||
import { PasswordInput } from '@/components/ui/password-input';
|
||||
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
||||
|
||||
interface PresetProvider {
|
||||
id: string;
|
||||
@@ -46,17 +46,6 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
},
|
||||
];
|
||||
|
||||
function renderIcon(providerId: string, size = 16) {
|
||||
switch (providerId) {
|
||||
case 'github':
|
||||
return <SiGithub size={size} />;
|
||||
case 'gitlab':
|
||||
return <SiGitlab size={size} />;
|
||||
default:
|
||||
return <GitBranch size={size} />;
|
||||
}
|
||||
}
|
||||
|
||||
export function GitSettings() {
|
||||
const { t } = useTranslation();
|
||||
const { settings, addCredential, removeCredential, updateCredential, updateSettings } = useGitSettings();
|
||||
@@ -170,7 +159,11 @@ export function GitSettings() {
|
||||
<AccordionItem key={origin} value={origin} className="border rounded-lg">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
{preset && renderIcon(preset.id)}
|
||||
<ExternalFavicon
|
||||
url={origin}
|
||||
size={16}
|
||||
fallback={<GitBranch size={16} />}
|
||||
/>
|
||||
<span className="font-medium">
|
||||
{preset?.name || new URL(origin).hostname}
|
||||
</span>
|
||||
@@ -233,7 +226,11 @@ export function GitSettings() {
|
||||
<div key={preset.id} className="border rounded-lg p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
{renderIcon(preset.id)}
|
||||
<ExternalFavicon
|
||||
url={preset.origin}
|
||||
size={16}
|
||||
fallback={<GitBranch size={16} />}
|
||||
/>
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
{preset.tokenURL && (preset.id !== 'github' || !isOAuthConfigured) && (
|
||||
@@ -265,7 +262,11 @@ export function GitSettings() {
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<SiGithub size={16} />
|
||||
<ExternalFavicon
|
||||
url="https://github.com"
|
||||
size={16}
|
||||
fallback={<GitBranch size={16} />}
|
||||
/>
|
||||
<span className="truncate text-ellipsis overflow-hidden">
|
||||
Connect to GitHub
|
||||
</span>
|
||||
|
||||
@@ -18,6 +18,7 @@ export function SystemSettings() {
|
||||
const [projectTemplateInput, setProjectTemplateInput] = useState(config.projectTemplate);
|
||||
const [esmUrlInput, setEsmUrlInput] = useState(config.esmUrl);
|
||||
const [corsProxyInput, setCorsProxyInput] = useState(config.corsProxy);
|
||||
const [faviconUrlInput, setFaviconUrlInput] = useState(config.faviconUrl);
|
||||
const [previewDomainInput, setPreviewDomainInput] = useState(config.previewDomain);
|
||||
const [showcaseModeratorInput, setShowcaseModeratorInput] = useState(config.showcaseModerator);
|
||||
|
||||
@@ -119,6 +120,36 @@ export function SystemSettings() {
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* Favicon URL Configuration */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="favicon-url" className="border rounded-lg">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<h4 className="text-sm font-medium">Favicon URL</h4>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="py-1 space-y-2">
|
||||
<Input
|
||||
id="favicon-url"
|
||||
type="url"
|
||||
placeholder="https://external-content.duckduckgo.com/ip3/{hostname}.ico"
|
||||
value={faviconUrlInput}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setFaviconUrlInput(value);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
faviconUrl: value,
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
URL template for fetching favicons. Available variables: {'{hostname}'}, {'{origin}'}, {'{href}'}, {'{protocol}'}, {'{pathname}'}
|
||||
</p>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* JavaScript CDN Configuration */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="esm-url" className="border rounded-lg">
|
||||
|
||||
Reference in new issue
Block a user