Skip to content

Commit a221c74

Browse files
Fix/plugin metadata repo type guard (#8207)
* fix: 修复插件 repo 字段类型导致前端报错 * fix: 修复插件 repo 字段类型导致前端报错 * fix: 使用 normalizeInstallUrl 统一 repo 字段处理 * fix:优化 installedRepos 构建方式
1 parent 7f94bce commit a221c74

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

astrbot/dashboard/routes/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ async def process_plugin(plugin):
12811281
for plugin, logo_url, pages in results:
12821282
_t = {
12831283
"name": plugin.name,
1284-
"repo": "" if plugin.repo is None else plugin.repo,
1284+
"repo": "" if plugin.repo is None else str(plugin.repo),
12851285
"author": plugin.author,
12861286
"desc": plugin.desc,
12871287
"version": plugin.version,
@@ -1333,7 +1333,7 @@ async def get_plugin_detail(self):
13331333
.ok(
13341334
{
13351335
"name": plugin.name,
1336-
"repo": "" if plugin.repo is None else plugin.repo,
1336+
"repo": "" if plugin.repo is None else str(plugin.repo),
13371337
"author": plugin.author,
13381338
"desc": plugin.desc,
13391339
"version": plugin.version,

dashboard/src/views/extension/useExtensionPage.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,14 @@ export const useExtensionPage = () => {
640640

641641
pluginMarketData.value.forEach((plugin) => {
642642
if (plugin.repo) {
643-
onlinePluginsMap.set(plugin.repo.toLowerCase(), plugin);
643+
onlinePluginsMap.set(normalizeInstallUrl(plugin.repo).toLowerCase(), plugin);
644644
}
645645
onlinePluginsNameMap.set(plugin.name, plugin);
646646
});
647647

648648
const data = Array.isArray(extension_data?.data) ? extension_data.data : [];
649649
data.forEach((extension) => {
650-
const repoKey = extension.repo?.toLowerCase();
650+
const repoKey = extension.repo ? normalizeInstallUrl(extension.repo).toLowerCase() : undefined;
651651
const onlinePlugin = repoKey ? onlinePluginsMap.get(repoKey) : null;
652652
const onlinePluginByName = onlinePluginsNameMap.get(extension.name);
653653
const matchedPlugin = onlinePlugin || onlinePluginByName;
@@ -1233,21 +1233,21 @@ export const useExtensionPage = () => {
12331233

12341234
const checkAlreadyInstalled = () => {
12351235
const data = Array.isArray(extension_data?.data) ? extension_data.data : [];
1236-
const installedRepos = new Set(data.map((ext) => ext.repo?.toLowerCase()));
1237-
const installedNames = new Set(
1238-
data.map((ext) => normalizeStr(ext.name).replace(/_/g, "-")),
1239-
); //统一格式,以防下面的匹配不生效
12401236
const installedByRepo = new Map(
12411237
data
12421238
.filter((ext) => ext.repo)
1243-
.map((ext) => [ext.repo.toLowerCase(), ext]),
1239+
.map((ext) => [normalizeInstallUrl(ext.repo).toLowerCase(), ext]),
12441240
);
1241+
const installedRepos = new Set(installedByRepo.keys());
1242+
const installedNames = new Set(
1243+
data.map((ext) => normalizeStr(ext.name).replace(/_/g, "-")),
1244+
); //统一格式,以防下面的匹配不生效
12451245
const installedByName = new Map(data.map((ext) => [ext.name, ext]));
12461246

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

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

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

0 commit comments

Comments
 (0)