intercept file response and add correct mime-type

This commit is contained in:
ArabCoders 2025-02-28 00:44:02 +03:00
parent 689ce421e9
commit 1fa4c523bb
2 changed files with 26 additions and 1 deletions

View file

@ -119,6 +119,7 @@ class HttpAPI(Common):
HttpAPI: The instance of the HttpAPI.
"""
app.middlewares.append(HttpAPI.middle_wares())
if self.config.auth_username and self.config.auth_password:
app.middlewares.append(HttpAPI.basic_auth(self.config.auth_username, self.config.auth_password))
@ -310,6 +311,24 @@ class HttpAPI(Common):
return middleware_handler
@staticmethod
def middle_wares() -> Awaitable:
@web.middleware
async def middleware_handler(request: Request, handler: RequestHandler) -> Response:
response = await handler(request)
if isinstance(response, web.FileResponse):
try:
ff_info = await ffprobe(response._path)
mime_type = get_mime_type(ff_info.get("metadata", {}), response._path)
response.content_type = mime_type
except Exception:
pass
return response
return middleware_handler
@route("OPTIONS", "/{path:.*}")
async def add_coors(self, _: Request) -> Response:
"""

View file

@ -145,7 +145,13 @@ const applyPreferredColorScheme = scheme => {
}
}
watch(() => config.app.sentry_dsn, dsn => dsn ? Sentry.init({ dsn: dsn }) : null)
watch(() => config.app.sentry_dsn, dsn => {
if (!dsn) {
return
}
console.warn('Loading sentry module.')
Sentry.init({ dsn: dsn })
})
onMounted(async () => {
try {