Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions astrbot/dashboard/routes/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
]
Expand Down
23 changes: 15 additions & 8 deletions dashboard/src/views/extension/useExtensionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]));
Comment on lines +1244 to +1251
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

installedByName 映射的键应使用 normalizeStr 进行归一化,以确保大小写不敏感的匹配,这与 checkUpdate 中处理 onlinePluginsNameMap 的方式一致。请注意,1257 行(目前在此 diff 之外)的查找逻辑也需要同步更新为使用 normalizeStr(plugin.name) 才能正确匹配。


for (let i = 0; i < pluginMarketData.value.length; i++) {
const plugin = pluginMarketData.value[i];
Expand All @@ -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 = [];
Expand Down Expand Up @@ -1477,6 +1483,7 @@ export const useExtensionPage = () => {
selectedMarketInstallPlugin.value = null;
await getExtensions();
checkAlreadyInstalled();
checkUpdate();

viewReadme({
name: resData.data.name,
Expand Down
1 change: 1 addition & 0 deletions tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("_", "-"),
}
]

Expand Down
Loading