mirrors page

This commit is contained in:
JMARyA 2022-09-02 03:41:05 +02:00
parent b5b52205c4
commit 9a12cfa491
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 34 additions and 3 deletions

View file

@ -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`.
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`

View file

@ -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

View file

@ -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"<pre>{txt}</pre>",
),
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(
[