diff --git a/iwm_browser/main.py b/iwm_browser/main.py index 8208ed2..504a19f 100644 --- a/iwm_browser/main.py +++ b/iwm_browser/main.py @@ -1,22 +1,19 @@ from typing import Union from fastapi.staticfiles import StaticFiles -from fastapi.middleware.gzip import GZipMiddleware -from fastapi.responses import HTMLResponse, PlainTextResponse -from fastapi import FastAPI, Form, Response +from fastapi.responses import HTMLResponse +from fastapi import FastAPI, Form import jinja2 import uvicorn import httpx import json import os import re -import importlib.resources from . import utils from . import __version__ basedir = os.path.dirname(__file__) app = FastAPI(openapi_url=None) -app.add_middleware(GZipMiddleware) app.mount("/static", StaticFiles(directory=basedir + "/static"), name="static") template_env = jinja2.Environment( @@ -26,7 +23,6 @@ template_env = jinja2.Environment( error_template = template_env.get_template("error.html") template_env.globals["convert_times"] = utils.convert_times -template_env.globals["combineCSS"] = utils.combineCSS template_env.globals["isSelected"] = utils.isSelected template_env.globals["generate_thumbnail_url"] = utils.generate_thumbnail_url template_env.globals["__version__"] = __version__ @@ -44,21 +40,6 @@ utils.global_imgproxy_params = json.loads(utils.config_value("IMGPROXY_PARAMS", # \S[A-Z0-9]{8} = without dash, no whitespace level_code_regex = re.compile("[A-Z0-9]{4}\-[A-Z0-9]{4}|[A-Z0-9]{8}") -class CSSResponse(Response): - media_type = "text/css" - def render(self, content: any) -> bytes: - return content.encode() - -@app.get("/assets/combine_css", response_class=CSSResponse) -async def combineCSSResources(resources: str, response: Response): - """Combines and returns the css stylesheets. The resources have to be accessible via /static.""" - combined_css = "" - for resource in resources.split(","): - path = os.path.join(os.path.abspath(basedir), "static", os.path.relpath(resource)) - with open(path) as f: - contents = f.read() - combined_css += f"\n/* SRC: {resource} */\n" + re.sub(" {4}| {2}"," ", re.sub("\n.*\/\*.*\*\/", "", contents)) - return combined_css @app.get("/", response_class=HTMLResponse) async def root(): @@ -97,6 +78,7 @@ async def search( timeout=10, ) searchResults = rq.json() + print(rq.url, p * limit) except httpx.ReadTimeout: return "Server timed out" else: @@ -144,6 +126,7 @@ async def search( reason="Server is unavailable right now." ) searchResults = rq.json() + print(rq.url, p * limit) except httpx.ReadTimeout: return error_template.render(reason="Server timed out") except json.decoder.JSONDecodeError: diff --git a/iwm_browser/templates/error.html b/iwm_browser/templates/error.html index 506e73b..4ab7e6f 100644 --- a/iwm_browser/templates/error.html +++ b/iwm_browser/templates/error.html @@ -4,11 +4,6 @@