mirror of
https://github.com/arcan1s/ffxivbis.git
synced 2025-07-14 06:15:50 +00:00
small static cleanup
This commit is contained in:
@ -12,11 +12,21 @@ from aiohttp.web import HTTPNotFound, Response, View
|
||||
|
||||
class StaticHtmlView(View):
|
||||
|
||||
def __get_content_type(self, filename: str) -> str:
|
||||
_, ext = os.path.splitext(filename)
|
||||
print(ext)
|
||||
if ext == '.css':
|
||||
return 'text/css'
|
||||
elif ext == '.js':
|
||||
return 'text/javascript'
|
||||
return 'text/plain'
|
||||
|
||||
async def get(self) -> Response:
|
||||
resource_name = self.request.match_info['resource_id']
|
||||
resource_path = os.path.join(self.request.app['templates_root'], 'static', resource_name)
|
||||
if not os.path.exists(resource_path) or os.path.isdir(resource_path):
|
||||
return HTTPNotFound()
|
||||
content_type = self.__get_content_type(resource_name)
|
||||
|
||||
with open(resource_path) as resource_file:
|
||||
return Response(text=resource_file.read(), content_type='text/css')
|
||||
return Response(text=resource_file.read(), content_type=content_type)
|
Reference in New Issue
Block a user