Update server.py

This commit is contained in:
Nova Cat 2025-01-13 20:27:09 -08:00
parent 97b9a37add
commit d4dc2f603b

View file

@ -39,16 +39,17 @@ def style():
@app.route("/gem")
def relay():
url = request.args.get('gemini')
queries = request.args.get('query')
if url == None:
return redirect("/")
code = "<h1>Something went wrong...</h1>\n"
title = "Something went wrong..."
try:
gsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
fulladdr = "gemini://" + url
fulladdr = "gemini://" + url + ("?" + queries if queries != None else "")
gemsocket = ssl._create_unverified_context().wrap_socket(gsocket, server_hostname=urlparse(fulladdr).hostname)
gemsocket.connect((urlparse(fulladdr).hostname, 1965))
gemsocket.send(bytes("gemini://" + url + "\r\n", "UTF-8"))
gemsocket.send(bytes(fulladdr + "\r\n", "UTF-8"))
received = ""
while True:
gemresponse = gemsocket.recv(2048)
@ -70,6 +71,8 @@ def relay():
if firstline:
if i.split(" ")[0][0] == "3":
return redirect("/gem?gemini=" + i.split(" ")[1][9:])
elif i.split(" ")[0][0] == "1":
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><link rel="stylesheet" href="/style.css"><title>Input required</title></head><body><h1>Input required</h1><p>The specified Gemini server wants more data: "<pre>{i}</pre>"</p><br><form action="/gem"><input hidden class="input" value="{url}" type="text" name="gemini"><input hidden class="input" type="text" name="query"><br><input type="submit" class="go" value="Go!"><br></form></body></html>'
elif i.split(" ")[0][0] != "2":
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><link rel="stylesheet" href="/style.css"><title>Something went wrong...</title></head><body><h1>Something went wrong...</h1><p>The specified Gemini server returned a status of: {i}</p></body></html>'
else: