mirror of
https://github.com/TheFunny/ArisuAutoSweeper
synced 2026-10-10 04:52:05 +00:00
feat: add patch_mimetype function for consistent mimetype handling
This commit is contained in:
+2
-1
@@ -51,7 +51,7 @@ from module.webui.fake import (
|
||||
)
|
||||
from module.webui.fastapi import asgi_app
|
||||
from module.webui.lang import _t, t
|
||||
from module.webui.patch import patch_executor
|
||||
from module.webui.patch import patch_executor, patch_mimetype
|
||||
from module.webui.pin import put_input, put_select
|
||||
from module.webui.process_manager import ProcessManager
|
||||
from module.webui.remote_access import RemoteAccess
|
||||
@@ -83,6 +83,7 @@ from module.webui.widgets import (
|
||||
)
|
||||
|
||||
patch_executor()
|
||||
patch_mimetype()
|
||||
task_handler = TaskHandler()
|
||||
|
||||
|
||||
|
||||
@@ -39,3 +39,24 @@ def patch_executor():
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.set_default_executor(CachedThreadPoolExecutor.executor)
|
||||
|
||||
|
||||
def patch_mimetype():
|
||||
"""
|
||||
Patch mimetype db to use the builtin table instead of reading from environment.
|
||||
|
||||
By default, mimetype reads user configured mimetype table from environment. It's good for server but bad on our
|
||||
side, because we deploy on user's machine which may have polluted environment. To have a consistent behaviour on
|
||||
all deployment, we use the builtin mimetype table only.
|
||||
"""
|
||||
import mimetypes
|
||||
# lock as inited
|
||||
mimetypes.inited = True
|
||||
# create a new clean instance
|
||||
db = mimetypes.MimeTypes(filenames=())
|
||||
mimetypes._db = db
|
||||
# override global variable
|
||||
mimetypes.encodings_map = db.encodings_map
|
||||
mimetypes.suffix_map = db.suffix_map
|
||||
mimetypes.types_map = db.types_map[True]
|
||||
mimetypes.common_types = db.types_map[False]
|
||||
|
||||
Reference in New Issue
Block a user