Skip to content

fix: register standard SVG MIME type for WebUI static files - #9735

Open
wcqqq1214 wants to merge 3 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/9734-svg-mime-type
Open

fix: register standard SVG MIME type for WebUI static files#9735
wcqqq1214 wants to merge 3 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/9734-svg-mime-type

Conversation

@wcqqq1214

@wcqqq1214 wcqqq1214 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Modifications / 改动点

Fixes #9734

On Windows, Python's mimetypes resolves .svg from the registry to image/svg, a non-standard MIME type. The WebUI static file route serves favicon.svg (and any plugin icon fallback) via Starlette FileResponse, which infers Content-Type from mimetypes.guess_type, so Chrome fails to render these resources.

Registered the standard image/svg+xml type at module load in astrbot/dashboard/server.py. This runs on both entry paths (python main.py and the astrbot run CLI), so the override applies process-wide regardless of how the dashboard is started.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

The bug is Windows-specific and cannot be reproduced on macOS/Linux (which already map .svg to image/svg+xml). Simulated the Windows registry mis-mapping and verified the module-level override wins:

after bad mapping: ('image/svg', None)
after fix:        ('image/svg+xml', None)
via server module: ('image/svg+xml', None)

A manual curl -I /favicon.svg on Windows should now return Content-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.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Bug Fixes:

  • Ensure WebUI SVG assets are served with the standard image/svg+xml MIME type on Windows so browsers render them correctly.

Summary by Sourcery

Bug Fixes:

  • Ensure WebUI SVG assets are served with the standard image/svg+xml MIME type on Windows so browsers render them correctly.

@wcqqq1214
wcqqq1214 force-pushed the fix/9734-svg-mime-type branch from 939ab2b to 58a85a4 Compare August 18, 2026 14:22
@wcqqq1214
wcqqq1214 marked this pull request as ready for review August 18, 2026 14:36
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. labels Aug 18, 2026

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've left some high level feedback:

  • 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 FileResponses) 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.

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.

@Soulter

Soulter commented Aug 19, 2026

Copy link
Copy Markdown
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.

@wcqqq1214

Copy link
Copy Markdown
Contributor Author

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.

Done. ^ ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Windows 下 WebUI 将 SVG 返回为错误 MIME 类型,导致插件默认图标和 favicon 破图

2 participants