Add QQ avatar proxy and render avatars

Add a /avatar/:uin proxy endpoint that fetches QQ avatars (fetchQqAvatar) and caches them server-side (30d TTL) with browser-cache headers (30d max-age, immutable). Validate UINs and handle upstream failures (502 if no cache), and log failures. Update ConfigPage and OverviewPage to render avatar <img> from /avatar/:uin (referrerPolicy=no-referrer) and adjust styles (overflow-hidden, object-cover) to replace initial-letter placeholders with actual avatars.
This commit is contained in:
手瓜一十雪 committed 2026-05-02 20:11:11 +08:00
1 parent e059a12cc4
commit ac1ddee54e
3 files changed
+70 -4

No files matched your search

+11 -2
View File
@@ -16,6 +16,10 @@ interface ConfigPageProps {
onConfigChange: (config: OneBotConfig) => void;
}
function qqAvatarUrl(uin: string): string {
return `/avatar/${encodeURIComponent(uin)}`;
}
export function ConfigPage({
qqList, selectedUin, config, saveStatus,
onSelectAccount, onSave, onConfigChange,
@@ -63,7 +67,7 @@ export function ConfigPage({
}}
>
<div
className="size-7 rounded-md flex items-center justify-center text-white text-[11px] font-bold shrink-0"
className="size-7 rounded-md flex items-center justify-center text-white text-[11px] font-bold shrink-0 overflow-hidden"
style={{
background: isActive
? 'linear-gradient(135deg, var(--accent), #818cf8)'
@@ -71,7 +75,12 @@ export function ConfigPage({
color: isActive ? '#fff' : 'var(--text-secondary)',
}}
>
{q.nickname[0]?.toUpperCase() || '?'}
<img
src={qqAvatarUrl(q.uin)}
alt={q.nickname || q.uin}
className="size-full object-cover"
referrerPolicy="no-referrer"
/>
</div>
<div className="min-w-0 flex-1">
<div
+11 -2
View File
@@ -32,6 +32,10 @@ function processStatusColor(status: HookProcessInfo['status']): string {
return 'var(--text-secondary)';
}
function qqAvatarUrl(uin: string): string {
return `/avatar/${encodeURIComponent(uin)}`;
}
export function OverviewPage({
qqList,
status,
@@ -250,13 +254,18 @@ export function OverviewPage({
}}
>
<div
className="size-10 rounded-lg flex items-center justify-center text-white text-sm font-bold shrink-0"
className="size-10 rounded-lg flex items-center justify-center text-white text-sm font-bold shrink-0 overflow-hidden"
style={{
background: 'linear-gradient(135deg, var(--accent), #818cf8)',
boxShadow: '0 0 12px var(--accent-glow)',
}}
>
{q.nickname[0]?.toUpperCase() || '?'}
<img
src={qqAvatarUrl(q.uin)}
alt={q.nickname || q.uin}
className="size-full object-cover"
referrerPolicy="no-referrer"
/>
</div>
<div className="min-w-0 flex-1">
<div className="text-sm font-semibold truncate" style={{ color: 'var(--text-primary)' }}>