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
4 changes: 2 additions & 2 deletions astrbot/dashboard/routes/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ async def get_plugins(self):
logo_url = await self.get_plugin_logo_token(plugin.logo_path)
_t = {
"name": plugin.name,
"repo": "" if plugin.repo is None else plugin.repo,
"repo": "" if plugin.repo is None else str(plugin.repo),
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

While this fix addresses the serialization in get_plugins, the repo field is also returned by other endpoints like install_plugin and install_plugin_from_file. To ensure consistency and prevent similar issues elsewhere, consider casting repo to a string when it is first loaded in StarMetadata (within star_manager.py) or ensuring all serialization points are covered.

References
  1. When implementing similar functionality for different cases, refactor the logic into a shared helper function or central location to avoid code duplication and ensure consistency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

似乎超出pr范围

"author": plugin.author,
"desc": plugin.desc,
"version": plugin.version,
Expand Down Expand Up @@ -1320,7 +1320,7 @@ async def get_plugin_detail(self):
.ok(
{
"name": plugin.name,
"repo": "" if plugin.repo is None else plugin.repo,
"repo": "" if plugin.repo is None else str(plugin.repo),
"author": plugin.author,
"desc": plugin.desc,
"version": plugin.version,
Expand Down
18 changes: 9 additions & 9 deletions dashboard/src/views/extension/useExtensionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,14 @@ export const useExtensionPage = () => {

pluginMarketData.value.forEach((plugin) => {
if (plugin.repo) {
onlinePluginsMap.set(plugin.repo.toLowerCase(), plugin);
onlinePluginsMap.set(normalizeInstallUrl(plugin.repo).toLowerCase(), plugin);
Comment thread
lingyun14beta marked this conversation as resolved.
}
onlinePluginsNameMap.set(plugin.name, plugin);
});

const data = Array.isArray(extension_data?.data) ? extension_data.data : [];
data.forEach((extension) => {
const repoKey = extension.repo?.toLowerCase();
const repoKey = extension.repo ? normalizeInstallUrl(extension.repo).toLowerCase() : undefined;
const onlinePlugin = repoKey ? onlinePluginsMap.get(repoKey) : null;
const onlinePluginByName = onlinePluginsNameMap.get(extension.name);
const matchedPlugin = onlinePlugin || onlinePluginByName;
Expand Down Expand Up @@ -1233,21 +1233,21 @@ 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, "-")),
); //统一格式,以防下面的匹配不生效
const installedByRepo = new Map(
data
.filter((ext) => ext.repo)
.map((ext) => [ext.repo.toLowerCase(), ext]),
.map((ext) => [normalizeInstallUrl(ext.repo).toLowerCase(), ext]),
);
const installedRepos = new Set(installedByRepo.keys());
const installedNames = new Set(
data.map((ext) => normalizeStr(ext.name).replace(/_/g, "-")),
); //统一格式,以防下面的匹配不生效
const installedByName = new Map(data.map((ext) => [ext.name, ext]));

for (let i = 0; i < pluginMarketData.value.length; i++) {
const plugin = pluginMarketData.value[i];
const matchedInstalled =
(plugin.repo && installedByRepo.get(plugin.repo.toLowerCase())) ||
(plugin.repo && installedByRepo.get(normalizeInstallUrl(plugin.repo).toLowerCase())) ||
installedByName.get(plugin.name);

// 兜底:市场源未提供字段时,回填本地已安装插件中的元数据,便于在市场页直接展示
Expand All @@ -1265,7 +1265,7 @@ export const useExtensionPage = () => {
}

plugin.installed =
installedRepos.has(plugin.repo?.toLowerCase()) ||
(plugin.repo && installedRepos.has(normalizeInstallUrl(plugin.repo).toLowerCase())) ||
installedNames.has(normalizeStr(plugin.name).replace(/_/g, "-")); //统一格式,防止匹配失败
}

Expand Down
Loading