File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import asyncio
22import hashlib
33import logging
4+ import mimetypes
45import os
56import socket
67from datetime import datetime
@@ -44,6 +45,13 @@ class _AddrWithPort(Protocol):
4445APP : Quart
4546
4647
48+ def _ensure_static_asset_mime_types () -> None :
49+ # Override platform-specific mappings so module scripts are always served
50+ # with a JavaScript MIME type, especially on Windows hosts.
51+ mimetypes .add_type ("application/javascript" , ".js" )
52+ mimetypes .add_type ("application/javascript" , ".mjs" )
53+
54+
4755def _parse_env_bool (value : str | None , default : bool ) -> bool :
4856 if value is None :
4957 return default
@@ -68,6 +76,7 @@ def __init__(
6876 self .core_lifecycle = core_lifecycle
6977 self .config = core_lifecycle .astrbot_config
7078 self .db = db
79+ _ensure_static_asset_mime_types ()
7180
7281 # Path priority:
7382 # 1. Explicit webui_dir argument
Original file line number Diff line number Diff line change 1+ import mimetypes
2+
3+ from astrbot .dashboard .server import _ensure_static_asset_mime_types
4+
5+
6+ def test_ensure_static_asset_mime_types_registers_javascript_types (monkeypatch ):
7+ calls = []
8+
9+ def fake_add_type (mime_type : str , extension : str , strict : bool = True ):
10+ calls .append ((mime_type , extension , strict ))
11+
12+ monkeypatch .setattr (mimetypes , "add_type" , fake_add_type )
13+
14+ _ensure_static_asset_mime_types ()
15+
16+ assert ("application/javascript" , ".js" , True ) in calls
17+ assert ("application/javascript" , ".mjs" , True ) in calls
You can’t perform that action at this time.
0 commit comments