fix: register javascript mime types for dashboard assets#6984
fix: register javascript mime types for dashboard assets#69841zzxy1 wants to merge 1 commit intoAstrBotDevs:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue where the dashboard WebUI would appear blank on Windows systems due to incorrect MIME type handling for JavaScript module scripts. By explicitly configuring the server to recognize '.js' and '.mjs' files as 'application/javascript', it ensures consistent and correct asset delivery across different operating systems, thereby restoring full dashboard functionality. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new function _ensure_static_asset_mime_types to explicitly set MIME types for JavaScript files (.js and .mjs) to application/javascript, addressing potential inconsistencies across different operating systems. This function is currently called within the AstrBotDashboard's __init__ method, and a new test has been added to verify its functionality. The review suggests moving the call to _ensure_static_asset_mime_types to the module level to ensure it's executed only once upon import, preventing redundant calls if AstrBotDashboard is instantiated multiple times.
| # with a JavaScript MIME type, especially on Windows hosts. | ||
| mimetypes.add_type("application/javascript", ".js") | ||
| mimetypes.add_type("application/javascript", ".mjs") | ||
|
|
There was a problem hiding this comment.
For one-time initializations like this, it's best practice to execute them at the module level. This ensures the setup runs only once when the module is imported, avoiding redundant calls if AstrBotDashboard is instantiated multiple times.
Please call _ensure_static_asset_mime_types() here, and remove the call from AstrBotDashboard.__init__.
| _ensure_static_asset_mime_types() |
| self.core_lifecycle = core_lifecycle | ||
| self.config = core_lifecycle.astrbot_config | ||
| self.db = db | ||
| _ensure_static_asset_mime_types() |
Summary
.jsand.mjsMIME mappings before Quart serves dashboard static assetstext/plainfor module scripts and causing a blank WebUIFixes #6253
Testing
uv run --group dev pytest tests/test_dashboard_static_mime.py -qSummary by Sourcery
Register correct JavaScript MIME types for dashboard static assets to ensure the WebUI loads correctly across platforms.
Bug Fixes:
Tests: