fix:正确识别已安装插件,并且修复无法更新和卸载自行安装插件的bug
This commit is contained in:
@@ -21,6 +21,7 @@ interface PluginApiResponse {
|
||||
id: string
|
||||
manifest: {
|
||||
manifest_version: number
|
||||
id?: string
|
||||
name: string
|
||||
version: string
|
||||
description: string
|
||||
@@ -56,6 +57,7 @@ function normalizePluginManifest(manifest: PluginApiResponse['manifest']): Plugi
|
||||
|
||||
return {
|
||||
manifest_version: manifest.manifest_version || 1,
|
||||
id: manifest.id,
|
||||
name: manifest.name,
|
||||
version: manifest.version,
|
||||
description: manifest.description || '',
|
||||
@@ -104,10 +106,15 @@ export async function fetchPluginList(): Promise<ApiResponse<PluginInfo[]>> {
|
||||
|
||||
const pluginList = data
|
||||
.filter(item => {
|
||||
if (!item?.id || !item?.manifest) {
|
||||
if (!item?.manifest) {
|
||||
console.warn('跳过无效插件数据:', item)
|
||||
return false
|
||||
}
|
||||
const pluginId = item.manifest.id || item.id
|
||||
if (!pluginId) {
|
||||
console.warn('跳过缺少 ID 的插件:', item)
|
||||
return false
|
||||
}
|
||||
if (!item.manifest.name || !item.manifest.version) {
|
||||
console.warn('跳过缺少必需字段的插件:', item.id)
|
||||
return false
|
||||
@@ -115,7 +122,7 @@ export async function fetchPluginList(): Promise<ApiResponse<PluginInfo[]>> {
|
||||
return true
|
||||
})
|
||||
.map((item) => ({
|
||||
id: item.id,
|
||||
id: item.manifest.id || item.id,
|
||||
manifest: normalizePluginManifest(item.manifest),
|
||||
downloads: 0,
|
||||
rating: 0,
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface InstalledPlugin {
|
||||
id: string
|
||||
manifest: {
|
||||
manifest_version: number
|
||||
id?: string
|
||||
name: string
|
||||
version: string
|
||||
description: string
|
||||
|
||||
@@ -104,21 +104,23 @@ export function PluginDetailPage() {
|
||||
}
|
||||
|
||||
const pluginList = JSON.parse(result.data)
|
||||
const foundPlugin = pluginList.find((p: any) => p.id === search.pluginId)
|
||||
const foundPlugin = pluginList.find((p: any) => (p.manifest?.id || p.id) === search.pluginId)
|
||||
|
||||
if (!foundPlugin) {
|
||||
throw new Error('未找到该插件')
|
||||
}
|
||||
|
||||
const rawManifest = foundPlugin.manifest || {}
|
||||
const pluginId = rawManifest.id || foundPlugin.id
|
||||
const repositoryUrl = rawManifest.repository_url || rawManifest.urls?.repository
|
||||
const homepageUrl = rawManifest.homepage_url || rawManifest.urls?.homepage
|
||||
|
||||
// 转换为 PluginInfo 格式
|
||||
const pluginInfo: PluginInfo = {
|
||||
id: foundPlugin.id,
|
||||
id: pluginId,
|
||||
manifest: {
|
||||
...rawManifest,
|
||||
id: pluginId,
|
||||
homepage_url: homepageUrl,
|
||||
repository_url: repositoryUrl,
|
||||
default_locale: rawManifest.default_locale || rawManifest.i18n?.default_locale || 'zh-CN',
|
||||
@@ -170,8 +172,8 @@ export function PluginDetailPage() {
|
||||
return
|
||||
}
|
||||
|
||||
setIsInstalled(checkPluginInstalled(search.pluginId, installedPlugins.data))
|
||||
setInstalledVersion(getInstalledPluginVersion(search.pluginId, installedPlugins.data))
|
||||
setIsInstalled(checkPluginInstalled(pluginId, installedPlugins.data))
|
||||
setInstalledVersion(getInstalledPluginVersion(pluginId, installedPlugins.data))
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : '加载失败')
|
||||
} finally {
|
||||
@@ -196,7 +198,7 @@ export function PluginDetailPage() {
|
||||
// 如果插件已安装,优先尝试从本地读取 README
|
||||
if (isInstalled && search.pluginId) {
|
||||
try {
|
||||
const localResponse = await fetchWithAuth(`/api/webui/plugins/local-readme/${search.pluginId}`)
|
||||
const localResponse = await fetchWithAuth(`/api/webui/plugins/local-readme/${plugin.id}`)
|
||||
|
||||
if (localResponse.ok) {
|
||||
const localResult = await localResponse.json()
|
||||
|
||||
@@ -220,6 +220,7 @@ function PluginsPageContent() {
|
||||
id: installedPlugin.id,
|
||||
manifest: {
|
||||
manifest_version: installedPlugin.manifest.manifest_version || 1,
|
||||
id: installedPlugin.manifest.id || installedPlugin.id,
|
||||
name: installedPlugin.manifest.name,
|
||||
version: installedPlugin.manifest.version,
|
||||
description: installedPlugin.manifest.description || '',
|
||||
|
||||
@@ -20,6 +20,8 @@ export interface HostApplication {
|
||||
export interface PluginManifest {
|
||||
/** 清单文件版本 */
|
||||
manifest_version: number
|
||||
/** Manifest 声明的插件唯一标识 */
|
||||
id?: string
|
||||
/** 插件名称 */
|
||||
name: string
|
||||
/** 插件版本 */
|
||||
|
||||
Reference in New Issue
Block a user