27 lines
646 B
Python
27 lines
646 B
Python
import flask
|
|
from htmlpy import Link
|
|
|
|
|
|
def is_onion(req: flask.globals.request) -> bool:
|
|
return req.host.endswith("onion")
|
|
|
|
|
|
def is_i2p(req: flask.globals.request) -> bool:
|
|
return req.host.endswith("i2p")
|
|
|
|
|
|
def dynamic_link(
|
|
inner, normal: str, onion: str, i2p: str, req: flask.globals.request
|
|
) -> Link:
|
|
if is_onion(req):
|
|
return Link(onion, inner)
|
|
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
|