2025-01-12 21:36:58 -08:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import asyncio, traceback
|
2025-01-12 22:00:24 -08:00
|
|
|
from flask import Flask, request, redirect
|
2025-01-12 21:36:58 -08:00
|
|
|
from hypercorn.config import Config
|
|
|
|
from hypercorn.asyncio import serve
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/")
|
|
|
|
def root():
|
2025-01-12 22:00:24 -08:00
|
|
|
return """
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<link rel="stylesheet" href="https://swee.codes/style.css">
|
|
|
|
<title>Gem2Browser</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<center>
|
|
|
|
<h1>Gem2Browser</h1>
|
|
|
|
<form action="/gem">
|
|
|
|
<p style="font-size: 15pt;">gemini://<input class="input" value="geminiprotocol.net" type="text" name="gemini"></p><br>
|
2025-01-12 22:10:56 -08:00
|
|
|
<input type="submit" class="download" value="Go!">
|
2025-01-12 22:00:24 -08:00
|
|
|
</form>
|
|
|
|
</center>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"""
|
2025-01-12 21:51:59 -08:00
|
|
|
@app.route("/gem")
|
|
|
|
def relay():
|
|
|
|
url = request.args.get('gemini')
|
|
|
|
if url == None:
|
|
|
|
return redirect("/")
|
2025-01-12 22:00:24 -08:00
|
|
|
code = "<h1>Something went wrong...</h1>\n"
|
2025-01-12 21:36:58 -08:00
|
|
|
title = "Something went wrong..."
|
|
|
|
try:
|
|
|
|
raise Exception("Not implemented")
|
|
|
|
except:
|
2025-01-12 22:00:24 -08:00
|
|
|
code += traceback.format_exc()
|
2025-01-12 22:01:13 -08:00
|
|
|
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><link rel="stylesheet" href="https://swee.codes/style.css"><title>{title}</title></head><body>{code}</body></html>'
|
2025-01-12 21:36:58 -08:00
|
|
|
|
|
|
|
# Run the Hypercorn ASGI server
|
2025-01-12 21:49:36 -08:00
|
|
|
conf = Config()
|
|
|
|
conf.bind = "0.0.0.0:2009"
|
|
|
|
asyncio.run(serve(app, conf))
|