Inline plugin icon helper into PluginCard
Some checks failed
Build NapCat Artifacts / Build-Framework (push) Has been cancelled
Build NapCat Artifacts / Build-Shell (push) Has been cancelled

Move getPluginIconUrl from utils/plugin_icon.ts into plugin_card.tsx and remove the now-unused util file. The function behavior is unchanged: it reads webui_token from localStorage and appends it as a query parameter to plugin icon URLs so authenticated icon endpoints can be used as img src.
This commit is contained in:
手瓜一十雪
2026-02-20 23:36:45 +08:00
parent dd8b5f84a6
commit f961830836
2 changed files with 14 additions and 21 deletions

View File

@@ -11,7 +11,20 @@ import { useState } from 'react';
import key from '@/const/key'; import key from '@/const/key';
import { PluginItem } from '@/controllers/plugin_manager'; import { PluginItem } from '@/controllers/plugin_manager';
import { getPluginIconUrl } from '@/utils/plugin_icon';
function getPluginIconUrl (iconPath?: string): string | undefined {
if (!iconPath) return undefined;
try {
const raw = localStorage.getItem(key.token);
if (!raw) return iconPath;
const token = JSON.parse(raw);
const url = new URL(iconPath, window.location.origin);
url.searchParams.set('webui_token', token);
return url.pathname + url.search;
} catch {
return iconPath;
}
}
export interface PluginDisplayCardProps { export interface PluginDisplayCardProps {
data: PluginItem; data: PluginItem;

View File

@@ -1,20 +0,0 @@
import key from '@/const/key';
/**
* 将后端返回的插件 icon 路径拼接上 webui_token 查询参数
* 后端 /api/Plugin/Icon/:pluginId 需要鉴权img src 无法携带 Authorization header
* 所以通过 query 参数传递 token
*/
export function getPluginIconUrl (iconPath?: string): string | undefined {
if (!iconPath) return undefined;
try {
const raw = localStorage.getItem(key.token);
if (!raw) return iconPath;
const token = JSON.parse(raw);
const url = new URL(iconPath, window.location.origin);
url.searchParams.set('webui_token', token);
return url.pathname + url.search;
} catch {
return iconPath;
}
}