-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: register javascript mime types for dashboard assets #6984
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import asyncio | ||
| import hashlib | ||
| import logging | ||
| import mimetypes | ||
| import os | ||
| import socket | ||
| from datetime import datetime | ||
|
|
@@ -44,6 +45,13 @@ class _AddrWithPort(Protocol): | |
| APP: Quart | ||
|
|
||
|
|
||
| def _ensure_static_asset_mime_types() -> None: | ||
| # Override platform-specific mappings so module scripts are always served | ||
| # with a JavaScript MIME type, especially on Windows hosts. | ||
| mimetypes.add_type("application/javascript", ".js") | ||
| mimetypes.add_type("application/javascript", ".mjs") | ||
|
|
||
|
|
||
| def _parse_env_bool(value: str | None, default: bool) -> bool: | ||
| if value is None: | ||
| return default | ||
|
|
@@ -68,6 +76,7 @@ def __init__( | |
| self.core_lifecycle = core_lifecycle | ||
| self.config = core_lifecycle.astrbot_config | ||
| self.db = db | ||
| _ensure_static_asset_mime_types() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| # Path priority: | ||
| # 1. Explicit webui_dir argument | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import mimetypes | ||
|
|
||
| from astrbot.dashboard.server import _ensure_static_asset_mime_types | ||
|
|
||
|
|
||
| def test_ensure_static_asset_mime_types_registers_javascript_types(monkeypatch): | ||
| calls = [] | ||
|
|
||
| def fake_add_type(mime_type: str, extension: str, strict: bool = True): | ||
| calls.append((mime_type, extension, strict)) | ||
|
|
||
| monkeypatch.setattr(mimetypes, "add_type", fake_add_type) | ||
|
|
||
| _ensure_static_asset_mime_types() | ||
|
|
||
| assert ("application/javascript", ".js", True) in calls | ||
| assert ("application/javascript", ".mjs", True) in calls |
Oops, something went wrong.
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.
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.
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
AstrBotDashboardis instantiated multiple times.Please call
_ensure_static_asset_mime_types()here, and remove the call fromAstrBotDashboard.__init__.