Skip to content

Conversation

kterna
Copy link
Contributor

@kterna kterna commented Jul 12, 2025

Motivation

现在的平台适配器logo都是硬编码,插件所实现的平台适配器无法展示logo

Modifications

为注册平台适配器增加了一个logo_path,插件可以通过提供logo_path路径在前端显示logo图片

Check

  • 😊 我的 Commit Message 符合良好的规范
  • 👀 我的更改经过良好的测试
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。
  • 😮 我的更改没有引入恶意代码

好的,这是翻译成中文的 pull request 总结:

Sourcery 总结

允许插件通过添加 logo_path 参数来提供自定义平台适配器 logo,在后端注册 logo 文件以颁发访问令牌,并更新 UI 以动态获取和显示这些 logo。

新功能:

  • register_platform_adapter 装饰器和 PlatformMetadata 添加 logo_path 选项,以允许插件指定平台适配器 logo
  • 实现后端逻辑以定位插件 logo 文件,通过 file_token_service 注册文件令牌,并将 logo 令牌注入到平台配置响应中
  • 更新前端以使用 logo 令牌来实现动态的插件提供的平台 logo,并回退到现有的硬编码图标
Original summary in English

Summary by Sourcery

Enable plugins to supply custom platform adapter logos by adding a logo_path parameter, registering logo files on the backend to issue access tokens, and updating the UI to fetch and display those logos dynamically.

New Features:

  • Add a logo_path option to the register_platform_adapter decorator and PlatformMetadata to allow plugins to specify platform adapter logos
  • Implement backend logic to locate plugin logo files, register file tokens via file_token_service, and inject logo tokens into platform configuration responses
  • Update the frontend to use logo tokens for dynamic plugin-provided platform logos with a fallback to existing hardcoded icons

Copy link
Contributor

sourcery-ai bot commented Jul 12, 2025

## 审查者指南

通过扩展注册 API 以接受 logo_path,实现服务器端 logo 文件注册和令牌注入,并更新 UI 以获取插件提供的 logo,从而为平台适配器启用动态 logo 支持。

### 文件级别变更

| 变更 | 详情 | 文件 |
| ------ | ------- | ----- |
| 扩展平台适配器注册以接受 logo 路径 | <ul><li>向 register_platform_adapter 装饰器添加 logo_path 参数</li><li>将 logo_path 传递到 PlatformMetadata 构造函数中</li><li>在 PlatformMetadata 中定义一个新的 logo_path 属性,并附带文档</li></ul> | `astrbot/core/platform/register.py`<br/>`astrbot/core/platform/platform_metadata.py` |
| 实现服务器端 logo 注册和令牌注入 | <ul><li>引入 _register_platform_logo 以通过 file_token_service 解析和注册 logo 文件</li><li>处理绝对和相对路径、存在性检查和错误日志记录</li><li>为 get_astrbot_config 中的每个平台调用 _register_platform_logo</li></ul> | `astrbot/dashboard/routes/config.py` |
| 更新前端以使用令牌获取插件提供的 logo | <ul><li>检查平台模板中的 logo_token 并返回 /api/file/{token} URL</li><li>保留现有的硬编码图标逻辑作为后备方案</li></ul> | `dashboard/src/views/PlatformPage.vue` |

---

<details>
<summary>提示和命令</summary>

#### 与 Sourcery 互动

- **触发新的审查:** 在 pull request 上评论 `@sourcery-ai review`。
- **继续讨论:** 直接回复 Sourcery 的审查评论。
- **从审查评论生成 GitHub issue:** 通过回复审查评论,让 Sourcery 从该评论创建一个 issue。您也可以回复审查评论并使用 `@sourcery-ai issue` 来从中创建一个 issue。
- **生成 pull request 标题:** 在 pull request 标题中的任何位置写入 `@sourcery-ai` 以随时生成标题。您也可以在 pull request 上评论 `@sourcery-ai title` 以随时(重新)生成标题。
- **生成 pull request 摘要:** 在 pull request 正文中的任何位置写入 `@sourcery-ai summary` 以随时在您想要的位置生成 PR 摘要。您也可以在 pull request 上评论 `@sourcery-ai summary` 以随时(重新)生成摘要。
- **生成审查者指南:** 在 pull request 上评论 `@sourcery-ai guide` 以随时(重新)生成审查者指南。
- **解决所有 Sourcery 评论:** 在 pull request 上评论 `@sourcery-ai resolve` 以解决所有 Sourcery 评论。如果您已经解决了所有评论并且不想再看到它们,这将非常有用。
- **驳回所有 Sourcery 审查:** 在 pull request 上评论 `@sourcery-ai dismiss` 以驳回所有现有的 Sourcery 审查。如果您想重新开始新的审查,这将特别有用 - 不要忘记评论 `@sourcery-ai review` 以触发新的审查!

#### 自定义您的体验

访问您的 [仪表板](https://app.sourcery.ai) 以:
- 启用或禁用审查功能,例如 Sourcery 生成的 pull request 摘要、审查者指南等。
- 更改审查语言。
- 添加、删除或编辑自定义审查说明。
- 调整其他审查设置。

#### 获取帮助

- [联系我们的支持团队](mailto:support@sourcery.ai) 提出问题或反馈。
- 访问我们的[文档](https://docs.sourcery.ai) 以获取详细的指南和信息。
- 通过在 [X/Twitter](https://x.com/SourceryAI)、[LinkedIn](https://www.linkedin.com/company/sourcery-ai/) 或 [GitHub](https://github.com/sourcery-ai) 上关注我们,与 Sourcery 团队保持联系。

</details>
Original review guide in English

Reviewer's Guide

Enable dynamic logo support for platform adapters by extending registration API to accept logo_path, implementing server-side logo file registration with tokens, and updating the UI to fetch plugin-provided logos.

File-Level Changes

Change Details Files
Extend platform adapter registration to accept a logo path
  • Add logo_path parameter to the register_platform_adapter decorator
  • Pass logo_path into the PlatformMetadata constructor
  • Define a new logo_path attribute with documentation in PlatformMetadata
astrbot/core/platform/register.py
astrbot/core/platform/platform_metadata.py
Implement server-side logo registration and token injection
  • Introduce _register_platform_logo to resolve and register logo files via file_token_service
  • Handle absolute and relative paths, existence checks, and error logging
  • Call _register_platform_logo for each platform in get_astrbot_config
astrbot/dashboard/routes/config.py
Update front-end to fetch plugin-provided logos using tokens
  • Check for logo_token in platform template and return /api/file/{token} URL
  • Retain existing hardcoded icon logic as a fallback
dashboard/src/views/PlatformPage.vue

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

@kterna - 我已经查看了你的更改 - 这里有一些反馈:

  • 考虑将 os、inspect 和 file_token_service 导入提升到模块级别,这样它们就不会在每次 _register_platform_logo 调用时重新导入。
  • 不要按顺序等待循环中每个平台的 logo 注册,而是使用 asyncio.gather 收集这些任务以并行化并加快配置加载。
  • 你可能想要缓存或记忆每个平台生成的 logo_token,以避免在每次配置获取时重新注册相同的文件,直到令牌过期。
AI 代理的提示
请解决此代码审查中的评论:
## 总体评论
- 考虑将 os、inspect 和 file_token_service 导入提升到模块级别,这样它们就不会在每次 _register_platform_logo 调用时重新导入。
- 不要按顺序等待循环中每个平台的 logo 注册,而是使用 asyncio.gather 收集这些任务以并行化并加快配置加载。
- 你可能想要缓存或记忆每个平台生成的 logo_token,以避免在每次配置获取时重新注册相同的文件,直到令牌过期。

## 单独评论

### 评论 1
<location> `astrbot/dashboard/routes/config.py:509` </location>
<code_context>
+                logo_token = await file_token_service.register_file(
+                    logo_file_path, timeout=3600
+                )
+                platform_default_tmpl[platform.name]["logo_token"] = logo_token
+                logger.debug(f"Logo token registered for platform {platform.name}")
+            else:
</code_context>

<issue_to_address>
如果 platform_default_tmpl[platform.name] 不是一个字典,则可能出现 KeyError。

在将值赋给 'logo_token' 之前,添加一个检查或将 platform_default_tmpl[platform.name] 初始化为一个字典,以防止 KeyError 或 TypeError。
</issue_to_address>

Sourcery 对开源项目是免费的 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我变得更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English

Hey @kterna - I've reviewed your changes - here's some feedback:

  • Consider hoisting the os, inspect, and file_token_service imports to module level so they aren’t re-imported on every _register_platform_logo call.
  • Instead of sequentially awaiting each platform’s logo registration inside the loop, gather those tasks with asyncio.gather to parallelize and speed up config loading.
  • You may want to cache or memoize the generated logo_token per platform to avoid re-registering the same file on every config fetch until the token expires.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider hoisting the os, inspect, and file_token_service imports to module level so they aren’t re-imported on every _register_platform_logo call.
- Instead of sequentially awaiting each platform’s logo registration inside the loop, gather those tasks with asyncio.gather to parallelize and speed up config loading.
- You may want to cache or memoize the generated logo_token per platform to avoid re-registering the same file on every config fetch until the token expires.

## Individual Comments

### Comment 1
<location> `astrbot/dashboard/routes/config.py:509` </location>
<code_context>
+                logo_token = await file_token_service.register_file(
+                    logo_file_path, timeout=3600
+                )
+                platform_default_tmpl[platform.name]["logo_token"] = logo_token
+                logger.debug(f"Logo token registered for platform {platform.name}")
+            else:
</code_context>

<issue_to_address>
Potential KeyError if platform_default_tmpl[platform.name] is not a dict.

Add a check or initialize platform_default_tmpl[platform.name] as a dict before assigning to 'logo_token' to prevent KeyError or TypeError.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

logo_token = await file_token_service.register_file(
logo_file_path, timeout=3600
)
platform_default_tmpl[platform.name]["logo_token"] = logo_token
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): 如果 platform_default_tmpl[platform.name] 不是一个字典,则可能出现 KeyError。

在将值赋给 'logo_token' 之前,添加一个检查或将 platform_default_tmpl[platform.name] 初始化为一个字典,以防止 KeyError 或 TypeError。

Original comment in English

issue (bug_risk): Potential KeyError if platform_default_tmpl[platform.name] is not a dict.

Add a check or initialize platform_default_tmpl[platform.name] as a dict before assigning to 'logo_token' to prevent KeyError or TypeError.

@Soulter Soulter force-pushed the master branch 2 times, most recently from 257d742 to b1e4bff Compare August 31, 2025 11:55
Copy link
Member

@Soulter Soulter left a comment

Choose a reason for hiding this comment

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

感觉强制logo_path是绝对路径就行了,不然整体逻辑过于复杂

@kterna
Copy link
Contributor Author

kterna commented Sep 11, 2025

改了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants