Skip to content

fix: register javascript mime types for dashboard assets#6984

Closed
1zzxy1 wants to merge 1 commit intoAstrBotDevs:masterfrom
1zzxy1:fix/dashboard-static-mime
Closed

fix: register javascript mime types for dashboard assets#6984
1zzxy1 wants to merge 1 commit intoAstrBotDevs:masterfrom
1zzxy1:fix/dashboard-static-mime

Conversation

@1zzxy1
Copy link
Copy Markdown
Contributor

@1zzxy1 1zzxy1 commented Mar 26, 2026

Summary

  • register explicit .js and .mjs MIME mappings before Quart serves dashboard static assets
  • avoid Windows host MIME associations returning text/plain for module scripts and causing a blank WebUI
  • add a small regression test for the MIME registration helper

Fixes #6253

Testing

  • uv run --group dev pytest tests/test_dashboard_static_mime.py -q

Summary by Sourcery

Register correct JavaScript MIME types for dashboard static assets to ensure the WebUI loads correctly across platforms.

Bug Fixes:

  • Force .js and .mjs dashboard assets to be served with a JavaScript MIME type to avoid incorrect text/plain responses on some platforms.

Tests:

  • Add a regression test verifying that JavaScript MIME types are registered for .js and .mjs dashboard assets.

@auto-assign auto-assign Bot requested review from Soulter and advent259141 March 26, 2026 04:44
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 26, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • MIME Type Registration: Explicitly registered 'application/javascript' MIME types for '.js' and '.mjs' files to ensure proper serving of dashboard static assets.
  • Windows Compatibility Fix: Addressed an issue where Windows hosts might incorrectly serve module scripts as 'text/plain', leading to a blank WebUI, by overriding platform-specific MIME mappings.
  • Regression Test Added: Included a new regression test to verify the correct registration of JavaScript MIME types, ensuring the fix remains stable.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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

Hey - I've reviewed your changes and they look great!


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.

@dosubot dosubot Bot added the area:webui The bug / feature is about webui(dashboard) of astrbot. label Mar 26, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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")

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.

medium

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__.

Suggested change
_ensure_static_asset_mime_types()

self.core_lifecycle = core_lifecycle
self.config = core_lifecycle.astrbot_config
self.db = db
_ensure_static_asset_mime_types()
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.

medium

Since the MIME type registration is now handled at the module level, this call inside __init__ is redundant and should be removed.

@1zzxy1 1zzxy1 closed this Mar 26, 2026
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:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

1 participant