From dd8b5f84a650eba1637f858337435805b959e9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 20 Feb 2026 23:35:49 +0800 Subject: [PATCH] Simplify plugin avatar logic Remove getAuthorAvatar and related homepage/repository parsing. Rely on getPluginIconUrl(icon) (backend-provided URL with token) and fall back to Vercel avatar. Update prop destructuring to drop homepage/repository and streamline avatar selection, removing fragile favicon/GitHub parsing logic. --- .../components/display_card/plugin_card.tsx | 45 ++----------------- 1 file changed, 3 insertions(+), 42 deletions(-) diff --git a/packages/napcat-webui-frontend/src/components/display_card/plugin_card.tsx b/packages/napcat-webui-frontend/src/components/display_card/plugin_card.tsx index 40fccf02..75f2ce58 100644 --- a/packages/napcat-webui-frontend/src/components/display_card/plugin_card.tsx +++ b/packages/napcat-webui-frontend/src/components/display_card/plugin_card.tsx @@ -13,45 +13,6 @@ import key from '@/const/key'; import { PluginItem } from '@/controllers/plugin_manager'; import { getPluginIconUrl } from '@/utils/plugin_icon'; -/** 提取作者头像 URL */ -function getAuthorAvatar (homepage?: string, repository?: string): string | undefined { - // 1. 尝试从 repository 提取 GitHub 用户名 - if (repository) { - try { - // 处理 git+https://github.com/... 或 https://github.com/... - const repoUrl = repository.replace(/^git\+/, '').replace(/\.git$/, ''); - const url = new URL(repoUrl); - if (url.hostname === 'github.com' || url.hostname === 'www.github.com') { - const parts = url.pathname.split('/').filter(Boolean); - if (parts.length >= 1) { - return `https://github.com/${parts[0]}.png`; - } - } - } catch { - // 忽略解析错误 - } - } - - // 2. 尝试从 homepage 提取 - if (homepage) { - try { - const url = new URL(homepage); - if (url.hostname === 'github.com' || url.hostname === 'www.github.com') { - const parts = url.pathname.split('/').filter(Boolean); - if (parts.length >= 1) { - return `https://github.com/${parts[0]}.png`; - } - } else { - // 如果是自定义域名,尝试获取 favicon - return `https://api.iowen.cn/favicon/${url.hostname}.png`; - } - } catch { - // 忽略解析错误 - } - } - return undefined; -} - export interface PluginDisplayCardProps { data: PluginItem; onToggleStatus: () => Promise; @@ -67,15 +28,15 @@ const PluginDisplayCard: React.FC = ({ onConfig, hasConfig = false, }) => { - const { name, version, author, description, status, homepage, repository, icon } = data; + const { name, version, author, description, status, icon } = data; const isEnabled = status === 'active'; const [processing, setProcessing] = useState(false); const [isExpanded, setIsExpanded] = useState(false); const [backgroundImage] = useLocalStorage(key.backgroundImage, ''); const hasBackground = !!backgroundImage; - // 优先使用后端返回的 icon URL(需要携带 token),否则尝试提取作者头像,最后兜底 Vercel 风格头像 - const avatarUrl = getPluginIconUrl(icon) || getAuthorAvatar(homepage, repository) || `https://avatar.vercel.sh/${encodeURIComponent(name)}`; + // 后端已处理 icon,前端只需拼接 token;无 icon 时兜底 Vercel 风格头像 + const avatarUrl = getPluginIconUrl(icon) || `https://avatar.vercel.sh/${encodeURIComponent(name)}`; const handleToggle = () => { setProcessing(true);