Compare commits
No commits in common. "347143ab44979208ae0f5ad5a9e544166b1b70c6" and "8c0451c6409cec2c812e606a309b45fcd9bc714c" have entirely different histories.
347143ab44
...
8c0451c640
7 changed files with 22 additions and 60 deletions
|
@ -1,22 +1,19 @@
|
||||||
from typing import Union
|
from typing import Union
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.middleware.gzip import GZipMiddleware
|
from fastapi.responses import HTMLResponse
|
||||||
from fastapi.responses import HTMLResponse, PlainTextResponse
|
from fastapi import FastAPI, Form
|
||||||
from fastapi import FastAPI, Form, Response
|
|
||||||
import jinja2
|
import jinja2
|
||||||
import uvicorn
|
import uvicorn
|
||||||
import httpx
|
import httpx
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import importlib.resources
|
|
||||||
from . import utils
|
from . import utils
|
||||||
from . import __version__
|
from . import __version__
|
||||||
|
|
||||||
basedir = os.path.dirname(__file__)
|
basedir = os.path.dirname(__file__)
|
||||||
|
|
||||||
app = FastAPI(openapi_url=None)
|
app = FastAPI(openapi_url=None)
|
||||||
app.add_middleware(GZipMiddleware)
|
|
||||||
app.mount("/static", StaticFiles(directory=basedir + "/static"), name="static")
|
app.mount("/static", StaticFiles(directory=basedir + "/static"), name="static")
|
||||||
|
|
||||||
template_env = jinja2.Environment(
|
template_env = jinja2.Environment(
|
||||||
|
@ -26,7 +23,6 @@ template_env = jinja2.Environment(
|
||||||
error_template = template_env.get_template("error.html")
|
error_template = template_env.get_template("error.html")
|
||||||
|
|
||||||
template_env.globals["convert_times"] = utils.convert_times
|
template_env.globals["convert_times"] = utils.convert_times
|
||||||
template_env.globals["combineCSS"] = utils.combineCSS
|
|
||||||
template_env.globals["isSelected"] = utils.isSelected
|
template_env.globals["isSelected"] = utils.isSelected
|
||||||
template_env.globals["generate_thumbnail_url"] = utils.generate_thumbnail_url
|
template_env.globals["generate_thumbnail_url"] = utils.generate_thumbnail_url
|
||||||
template_env.globals["__version__"] = __version__
|
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
|
# \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}")
|
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)
|
@app.get("/", response_class=HTMLResponse)
|
||||||
async def root():
|
async def root():
|
||||||
|
@ -97,6 +78,7 @@ async def search(
|
||||||
timeout=10,
|
timeout=10,
|
||||||
)
|
)
|
||||||
searchResults = rq.json()
|
searchResults = rq.json()
|
||||||
|
print(rq.url, p * limit)
|
||||||
except httpx.ReadTimeout:
|
except httpx.ReadTimeout:
|
||||||
return "Server timed out"
|
return "Server timed out"
|
||||||
else:
|
else:
|
||||||
|
@ -144,6 +126,7 @@ async def search(
|
||||||
reason="Server is unavailable right now."
|
reason="Server is unavailable right now."
|
||||||
)
|
)
|
||||||
searchResults = rq.json()
|
searchResults = rq.json()
|
||||||
|
print(rq.url, p * limit)
|
||||||
except httpx.ReadTimeout:
|
except httpx.ReadTimeout:
|
||||||
return error_template.render(reason="Server timed out")
|
return error_template.render(reason="Server timed out")
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
|
|
|
@ -4,11 +4,6 @@
|
||||||
<title></title>
|
<title></title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="stylesheet" href="{{ combineCSS(
|
|
||||||
'/static/index.css',
|
|
||||||
'/static/main.css',
|
|
||||||
'/static/error.css'
|
|
||||||
) }}">
|
|
||||||
<link rel="stylesheet" href="/static/index.css">
|
<link rel="stylesheet" href="/static/index.css">
|
||||||
<link rel="stylesheet" href="/static/main.css">
|
<link rel="stylesheet" href="/static/main.css">
|
||||||
<link rel="stylesheet" href="/static/error.css">
|
<link rel="stylesheet" href="/static/error.css">
|
||||||
|
|
|
@ -4,12 +4,10 @@
|
||||||
<title>IWM Browser</title>
|
<title>IWM Browser</title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="stylesheet" href="{{ combineCSS(
|
<link rel="stylesheet" href="/static/index.css">
|
||||||
'/static/index.css',
|
<link rel="stylesheet" href="/static/main.css">
|
||||||
'/static/main.css',
|
<link rel="stylesheet" href="/static/homepage.css">
|
||||||
'/static/homepage.css',
|
<link rel="stylesheet" href="/static/search/search.css">
|
||||||
'/static/search/search.css'
|
|
||||||
) }}">
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="Home">
|
<div class="Home">
|
||||||
|
|
|
@ -4,12 +4,10 @@
|
||||||
<title></title>
|
<title></title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="stylesheet" href="{{ combineCSS(
|
<link rel="stylesheet" href="/static/index.css">
|
||||||
'/static/index.css',
|
<link rel="stylesheet" href="/static/main.css">
|
||||||
'/static/main.css',
|
<link rel="stylesheet" href="/static/search/search.css">
|
||||||
'/static/search/search.css',
|
<link rel="stylesheet" href="/static/search/searchResults.css">
|
||||||
'/static/search/searchResults.css'
|
|
||||||
) }}">
|
|
||||||
<!-- Optional features -->
|
<!-- Optional features -->
|
||||||
<script>
|
<script>
|
||||||
function copy(obj) {
|
function copy(obj) {
|
||||||
|
|
|
@ -5,12 +5,10 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="robots" content="noindex, nofollow">
|
<meta name="robots" content="noindex, nofollow">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="stylesheet" href="{{ combineCSS(
|
<link rel="stylesheet" href="/static/index.css">
|
||||||
'/static/index.css',
|
<link rel="stylesheet" href="/static/main.css">
|
||||||
'/static/main.css',
|
<link rel="stylesheet" href="/static/search/search.css">
|
||||||
'/static/search/search.css',
|
<link rel="stylesheet" href="/static/search/searchResults.css">
|
||||||
'/static/search/searchResults.css'
|
|
||||||
) }}">
|
|
||||||
<!-- Optional features -->
|
<!-- Optional features -->
|
||||||
<script>
|
<script>
|
||||||
function copy(obj) {
|
function copy(obj) {
|
||||||
|
|
|
@ -4,18 +4,11 @@
|
||||||
<title></title>
|
<title></title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="stylesheet" href="{{ combineCSS(
|
<link rel="stylesheet" href="/static/index.css">
|
||||||
'/static/index.css',
|
<link rel="stylesheet" href="/static/main.css">
|
||||||
'/static/main.css',
|
<link rel="stylesheet" href="/static/search/search.css">
|
||||||
'/static/search/search.css',
|
<link rel="stylesheet" href="/static/search/searchResults.css">
|
||||||
'/static/search/searchResults.css',
|
<link rel="stylesheet" href="/static/user.css">
|
||||||
'/static/user.css'
|
|
||||||
) }}">
|
|
||||||
<!-- <link rel="stylesheet" href="/static/index.css"> -->
|
|
||||||
<!-- <link rel="stylesheet" href="/static/main.css"> -->
|
|
||||||
<!-- <link rel="stylesheet" href="/static/search/search.css"> -->
|
|
||||||
<!-- <link rel="stylesheet" href="/static/search/searchResults.css"> -->
|
|
||||||
<!-- <link rel="stylesheet" href="/static/user.css"> -->
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="Search">
|
<div class="Search">
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from imgproxy import ImgProxy
|
from imgproxy import ImgProxy
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import urllib.parse
|
|
||||||
|
|
||||||
def convert_times(time):
|
def convert_times(time):
|
||||||
# Not sure if it's the right way to do that, but it seems to work.
|
# Not sure if it's the right way to do that, but it seems to work.
|
||||||
|
@ -31,11 +30,9 @@ def config_value(key: str, default_value=None):
|
||||||
def isSelected(selection, value):
|
def isSelected(selection, value):
|
||||||
"""Returns 'selected' if values are equal.
|
"""Returns 'selected' if values are equal.
|
||||||
Intended for selection boxes"""
|
Intended for selection boxes"""
|
||||||
|
print(f"DBG: {selection} {value},")
|
||||||
return 'selected="true"' if selection == value else ''
|
return 'selected="true"' if selection == value else ''
|
||||||
|
|
||||||
def combineCSS(*paths):
|
|
||||||
"""Generates the /assets/combine_css url"""
|
|
||||||
return f"/assets/combine_css?resources={','.join(paths)}"
|
|
||||||
|
|
||||||
# Specify default imgproxy instance.
|
# Specify default imgproxy instance.
|
||||||
global_imgproxy_url = None
|
global_imgproxy_url = None
|
||||||
|
|
Loading…
Reference in a new issue