fix: register standard SVG MIME type for WebUI static files - #9735
Open
wcqqq1214 wants to merge 3 commits into
Open
fix: register standard SVG MIME type for WebUI static files#9735wcqqq1214 wants to merge 3 commits into
wcqqq1214 wants to merge 3 commits into
Conversation
wcqqq1214
force-pushed
the
fix/9734-svg-mime-type
branch
from
August 18, 2026 14:22
939ab2b to
58a85a4
Compare
wcqqq1214
marked this pull request as ready for review
August 18, 2026 14:36
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider guarding the
mimetypes.add_typecall with a Windows-only check (e.g.if os.name == 'nt':) so you don't override any custom or future mappings on non-Windows platforms unnecessarily. - Instead of a global mimetype side effect at module import, you might centralize this fix where static files are served (e.g. explicitly setting
media_typefor SVGFileResponses) to keep behavior changes more localized and easier to reason about.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider guarding the `mimetypes.add_type` call with a Windows-only check (e.g. `if os.name == 'nt':`) so you don't override any custom or future mappings on non-Windows platforms unnecessarily.
- Instead of a global mimetype side effect at module import, you might centralize this fix where static files are served (e.g. explicitly setting `media_type` for SVG `FileResponse`s) to keep behavior changes more localized and easier to reason about.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Member
|
Consider guarding the mimetypes.add_type call with a Windows-only check (e.g. if os.name == 'nt':) so you don't override any custom or future mappings on non-Windows platforms unnecessarily. |
Contributor
Author
Done. ^ ^ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Modifications / 改动点
Fixes #9734
On Windows, Python's
mimetypesresolves.svgfrom the registry toimage/svg, a non-standard MIME type. The WebUI static file route servesfavicon.svg(and any plugin icon fallback) via StarletteFileResponse, which infersContent-Typefrommimetypes.guess_type, so Chrome fails to render these resources.Registered the standard
image/svg+xmltype at module load inastrbot/dashboard/server.py. This runs on both entry paths (python main.pyand theastrbot runCLI), so the override applies process-wide regardless of how the dashboard is started.Screenshots or Test Results / 运行截图或测试结果
The bug is Windows-specific and cannot be reproduced on macOS/Linux (which already map
.svgtoimage/svg+xml). Simulated the Windows registry mis-mapping and verified the module-level override wins:A manual
curl -I /favicon.svgon Windows should now returnContent-Type: image/svg+xml.Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Bug Fixes:
image/svg+xmlMIME type on Windows so browsers render them correctly.Summary by Sourcery
Bug Fixes:
image/svg+xmlMIME type on Windows so browsers render them correctly.