-
-
Notifications
You must be signed in to change notification settings - Fork 862
feat: 添加平台适配器 logo 支持 #2109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: 添加平台适配器 logo 支持 #2109
The head ref may contain hidden characters: "\u63D2\u4EF6logo"
Conversation
Original review guide in EnglishReviewer's GuideEnable 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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>
帮助我变得更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
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>
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 |
There was a problem hiding this comment.
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.
257d742
to
b1e4bff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉强制logo_path是绝对路径就行了,不然整体逻辑过于复杂
改了 |
Motivation
现在的平台适配器logo都是硬编码,插件所实现的平台适配器无法展示logo
Modifications
为注册平台适配器增加了一个logo_path,插件可以通过提供logo_path路径在前端显示logo图片
Check
requirements.txt
和pyproject.toml
文件相应位置。好的,这是翻译成中文的 pull request 总结:
Sourcery 总结
允许插件通过添加
logo_path
参数来提供自定义平台适配器 logo,在后端注册 logo 文件以颁发访问令牌,并更新 UI 以动态获取和显示这些 logo。新功能:
register_platform_adapter
装饰器和PlatformMetadata
添加logo_path
选项,以允许插件指定平台适配器 logofile_token_service
注册文件令牌,并将 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: