diff --git a/astrbot/dashboard/routes/plugin.py b/astrbot/dashboard/routes/plugin.py index 10d87eabea..9486a20499 100644 --- a/astrbot/dashboard/routes/plugin.py +++ b/astrbot/dashboard/routes/plugin.py @@ -1270,6 +1270,7 @@ async def get_plugins(self): logo_url = await self.get_plugin_logo_token(plugin.logo_path) _t = { "name": plugin.name, + "marketplace_name": (plugin.name or "").replace("_", "-"), "repo": "" if plugin.repo is None else plugin.repo, "author": plugin.author, "desc": plugin.desc, @@ -1320,6 +1321,7 @@ async def get_plugin_detail(self): .ok( { "name": plugin.name, + "marketplace_name": (plugin.name or "").replace("_", "-"), "repo": "" if plugin.repo is None else plugin.repo, "author": plugin.author, "desc": plugin.desc, @@ -1372,6 +1374,7 @@ async def get_plugin_page_components(self, plugin) -> list[dict]: "i18n_key": page["i18n_key"], "description": "Plugin Page entry", "plugin_name": plugin.name, + "plugin_marketplace_name": (plugin.name or "").replace("_", "-"), } for page in pages ] diff --git a/dashboard/src/views/extension/useExtensionPage.js b/dashboard/src/views/extension/useExtensionPage.js index e23716acdc..ebe1ebb718 100644 --- a/dashboard/src/views/extension/useExtensionPage.js +++ b/dashboard/src/views/extension/useExtensionPage.js @@ -484,7 +484,7 @@ export const useExtensionPage = () => { const failRes = await axios.get("/api/plugin/source/get-failed-plugins"); failedPluginsDict.value = failRes.data.data || {}; - checkUpdate(); + // checkUpdate() is called after pluginMarketData is loaded in onMounted } catch (err) { toast(err, "error"); } finally { @@ -642,14 +642,20 @@ export const useExtensionPage = () => { if (plugin.repo) { onlinePluginsMap.set(plugin.repo.toLowerCase(), plugin); } - onlinePluginsNameMap.set(plugin.name, plugin); + const normalizedName = normalizeStr(plugin.name); + onlinePluginsNameMap.set(normalizedName, plugin); }); const data = Array.isArray(extension_data?.data) ? extension_data.data : []; + data.forEach((extension) => { const repoKey = extension.repo?.toLowerCase(); const onlinePlugin = repoKey ? onlinePluginsMap.get(repoKey) : null; - const onlinePluginByName = onlinePluginsNameMap.get(extension.name); + + // 使用 marketplace_name 进行市场匹配(已统一为减号格式) + const normalizedExtensionName = normalizeStr(extension.marketplace_name || extension.name); + const onlinePluginByName = onlinePluginsNameMap.get(normalizedExtensionName); + const matchedPlugin = onlinePlugin || onlinePluginByName; if (matchedPlugin) { @@ -1234,15 +1240,15 @@ export const useExtensionPage = () => { const checkAlreadyInstalled = () => { const data = Array.isArray(extension_data?.data) ? extension_data.data : []; const installedRepos = new Set(data.map((ext) => ext.repo?.toLowerCase())); - const installedNames = new Set( - data.map((ext) => normalizeStr(ext.name).replace(/_/g, "-")), - ); //统一格式,以防下面的匹配不生效 + // 使用 marketplace_name 进行市场匹配(已统一为减号格式) + const installedNames = new Set(data.map((ext) => normalizeStr(ext.marketplace_name || ext.name))); const installedByRepo = new Map( data .filter((ext) => ext.repo) .map((ext) => [ext.repo.toLowerCase(), ext]), ); - const installedByName = new Map(data.map((ext) => [ext.name, ext])); + // 使用 marketplace_name 创建映射,用于市场匹配 + const installedByName = new Map(data.map((ext) => [ext.marketplace_name || ext.name, ext])); for (let i = 0; i < pluginMarketData.value.length; i++) { const plugin = pluginMarketData.value[i]; @@ -1266,7 +1272,7 @@ export const useExtensionPage = () => { plugin.installed = installedRepos.has(plugin.repo?.toLowerCase()) || - installedNames.has(normalizeStr(plugin.name).replace(/_/g, "-")); //统一格式,防止匹配失败 + installedNames.has(normalizeStr(plugin.name)); } let installed = []; @@ -1477,6 +1483,7 @@ export const useExtensionPage = () => { selectedMarketInstallPlugin.value = null; await getExtensions(); checkAlreadyInstalled(); + checkUpdate(); viewReadme({ name: resData.data.name, diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index 86bdf455ef..36f4c52d11 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -887,6 +887,7 @@ async def test_plugin_detail_includes_scanned_page_component( "i18n_key": f"pages.{PLUGIN_PAGE_DEMO_PAGE_NAME}", "description": "Plugin Page entry", "plugin_name": PLUGIN_PAGE_DEMO_NAME, + "plugin_marketplace_name": PLUGIN_PAGE_DEMO_NAME.replace("_", "-"), } ]