diff --git a/docs/configuration.md b/docs/configuration.md index 69966da..06a2d4d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -10,4 +10,7 @@ The main configuration is in `config.json`. See [this](./config.json.md) If you want to show a picture on the main page, place a file called `me.avif` in the config folder. ## PGP Key -If you want to share your public key, put it inside `pub.key`. \ No newline at end of file +If you want to share your public key, put it inside `pub.key`. + +## Mirrors +Specify mirror urls inside of `mirrors.txt` and it will be served at `/mirrors.txt` \ No newline at end of file diff --git a/src/fn.py b/src/fn.py index 1e48ae1..bdacad1 100644 --- a/src/fn.py +++ b/src/fn.py @@ -18,3 +18,10 @@ def dynamic_link( if is_i2p(req): return Link(i2p, inner) return Link(normal, inner) + + +def is_browser(req: flask.globals.request) -> bool: + ua = req.user_agent.string.lower() + if "chrome" in ua or "safari" in ua or "firefox" in ua: + return True + return False diff --git a/src/index.py b/src/index.py index 4936f29..455fa45 100644 --- a/src/index.py +++ b/src/index.py @@ -8,9 +8,31 @@ from config import CONFIG from html_fn import buildSite from msg import encrypt, save_message from notification import notify +from fn import is_browser main_pages = Blueprint("main", __name__) +# Mirrors +@main_pages.route("/mirrors.txt", methods=["GET"]) +def mirrors(): + # TODO : Autogenerate GPG Sign Message + if exists("/config/mirrors.txt"): + txt = open("/config/mirrors.txt").read() + if is_browser(request): + site = buildSite(None, "Mirrors") + + site.body = Body( + content=Div( + f"
{txt}", + ), + global_attr=GlobalAttributes(style="background: black; color: white"), + ) + return site.to_code() + + return txt + else: + return Response(response="", status=404) + # Message Sending Page @main_pages.route("/message", methods=["GET", "POST"]) @@ -85,8 +107,7 @@ def public_key(): str(pgp.list_keys()[0]["uids"][0]).replace("<", "[ ").replace(">", " ]") ) - ua = request.user_agent.string.lower() - if "chrome" in ua or "safari" in ua or "firefox" in ua: + if is_browser(request): # If request is from common browser return stylized html return buildSite( [