intercept file response and add correct mime-type
This commit is contained in:
parent
689ce421e9
commit
1fa4c523bb
2 changed files with 26 additions and 1 deletions
|
|
@ -119,6 +119,7 @@ class HttpAPI(Common):
|
||||||
HttpAPI: The instance of the HttpAPI.
|
HttpAPI: The instance of the HttpAPI.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
app.middlewares.append(HttpAPI.middle_wares())
|
||||||
if self.config.auth_username and self.config.auth_password:
|
if self.config.auth_username and self.config.auth_password:
|
||||||
app.middlewares.append(HttpAPI.basic_auth(self.config.auth_username, 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
|
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:.*}")
|
@route("OPTIONS", "/{path:.*}")
|
||||||
async def add_coors(self, _: Request) -> Response:
|
async def add_coors(self, _: Request) -> Response:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -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 () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue