Update server.py

This commit is contained in:
Nova Cat 2025-01-13 20:11:59 -08:00
parent f915810025
commit af2f23e44e

104
server.py
View file

@ -77,55 +77,65 @@ def relay():
print("Unrecognised type: " + i.split(" ")[1])
return Response(" ".join(received.split("\n")[1:]), mimetype=i.split(" ")[1])
else:
if i[0:2] == "# ":
if title == "Something went wrong...":
title = i[2:]
temp = i[2:]
code += f"<h1>{temp}</h1>\n"
elif i[0:3] == "## ":
temp = i[3:]
code += f"<h2>{temp}</h2>\n"
elif i[0:4] == "### ":
temp = i[4:]
code += f"<h3>{temp}</h3>\n"
elif i[0:2] == "* ":
temp = i[2:]
code += f"<ul><li>{temp}</li></ul>\n"
elif i[0:2] == "=>":
temp = " ".join(i[2:].strip().replace(" ", " ").split(" "))
goto = temp.split(" ")[0]
prse = urlparse(goto)
extra = ""
extracomment = goto
if prse.netloc == "" and prse.scheme == "":
isdir = url[len(url) - 1] == "/"
isabs = goto[0] == "/" or goto[0:2] == "//"
dubleslash = goto[0:2] == "//"
if isabs:
tempurl = urlparse(fulladdr).hostname + "/" + (goto[1:] if dubleslash else goto)
elif isdir:
tempurl = url + goto
else:
tempurl = "/".join(url.split("/")[:-1]) + "/" + goto
goto = f"/gem?gemini={tempurl}"
elif prse.scheme != "gemini":
extra = "<img height=\"19\" src=\"/external.png\">"
extracomment = f"This link points to an address that isn't gemini ({prse.scheme})"
if escaped:
if i[0:3] == "```":
code += "</pre>\n"
escaped = False
else:
if prse.hostname != urlparse(fulladdr).hostname:
extra = "<img height=\"19\" src=\"/cross-server.png\">"
extracomment = f"This link points to an address that isn't from the server you're currently connecting to ({prse.hostname})"
goto = goto.replace("gemini://", "")
goto = f"/gem?gemini={goto}"
if temp.split(" ") == 1:
comment = goto
else:
comment = " ".join(temp.split(" ")[1:])
code += f"<p title=\"{extracomment}\"><a href=\"{goto}\">{comment} {extra}</a></p>\n"
elif i[0:2] == "> ":
code += f"<p class='greentext'>{i}</p>\n"
code += i + "\n"
else:
code += f"<p>{i}</p>\n"
if i[0:2] == "# ":
if title == "Something went wrong...":
title = i[2:]
temp = i[2:]
code += f"<h1>{temp}</h1>\n"
elif i[0:3] == "## ":
temp = i[3:]
code += f"<h2>{temp}</h2>\n"
elif i[0:3] == "```":
code += "<pre>\n"
escaped = True
elif i[0:4] == "### ":
temp = i[4:]
code += f"<h3>{temp}</h3>\n"
elif i[0:2] == "* ":
temp = i[2:]
code += f"<ul><li>{temp}</li></ul>\n"
elif i[0:2] == "=>":
temp = " ".join(i[2:].strip().replace(" ", " ").split(" "))
goto = temp.split(" ")[0]
prse = urlparse(goto)
extra = ""
extracomment = goto
if prse.netloc == "" and prse.scheme == "":
isdir = url[len(url) - 1] == "/"
isabs = goto[0] == "/" or goto[0:2] == "//"
dubleslash = goto[0:2] == "//"
if isabs:
tempurl = urlparse(fulladdr).hostname + "/" + (goto[1:] if dubleslash else goto)
elif isdir:
tempurl = url + goto
else:
tempurl = "/".join(url.split("/")[:-1]) + "/" + goto
goto = f"/gem?gemini={tempurl}"
elif prse.scheme != "gemini":
extra = "<img height=\"19\" src=\"/external.png\">"
extracomment = f"This link points to an address that isn't gemini ({prse.scheme})"
else:
if prse.hostname != urlparse(fulladdr).hostname:
extra = "<img height=\"19\" src=\"/cross-server.png\">"
extracomment = f"This link points to an address that isn't from the server you're currently connecting to ({prse.hostname})"
goto = goto.replace("gemini://", "")
goto = f"/gem?gemini={goto}"
if temp.split(" ") == 1:
comment = goto
else:
comment = " ".join(temp.split(" ")[1:])
code += f"<p title=\"{extracomment}\"><a href=\"{goto}\">{comment} {extra}</a></p>\n"
elif i[0:2] == "> ":
code += f"<p class='greentext'>{i}</p>\n"
else:
code += f"<p>{i}</p>\n"
if title == "Something went wrong...":
title = "gemini://" + url
except: