Special case LICENSE, ABOUT, .description, as well as fix feed mimetypes

This commit is contained in:
Robert Miles 2021-10-07 00:43:07 +00:00
parent bf289b1ee3
commit c7b178f44e
1 changed files with 6 additions and 4 deletions

10
app.py
View File

@ -37,6 +37,7 @@ class DefaultToGopher(JetforceApplication):
if fs_path.is_file():
mimetype = mimetypes.guess_type(fs_path,strict=False)[0] or "application/octet-stream"
if str(fs_path).endswith("gophermap"): mimetype = "text/gophermap"
if any([str(fs_path).endswith(x) for x in ("LICENSE","ABOUT",".description")]): mimetype = "text/plain"
return Response(Status.SUCCESS,mimetype,self.load_file(fs_path))
else: # don't bother with directory listings
return Response(Status.NOT_FOUND,"Not Found")
@ -176,8 +177,9 @@ def ship(request,ship=None):
return __generator()
@app.route("/(?P<format>rss|atom).xml")
@wrap_response()
def feeds(request,format="atom"):
with open(os.path.join("/var/gopher",format+".xml")) as f:
for line in f:
yield line.replace("gopher://cosmic.voyage/0/","gemini://cosmic.voyage/").replace("<link>gopher://cosmic.voyage","<link>gemini://cosmic.voyage")
def __generator():
with open(os.path.join("/var/gopher",format+".xml")) as f:
for line in f:
yield line.replace("gopher://cosmic.voyage/0/","gemini://cosmic.voyage/").replace("<link>gopher://cosmic.voyage","<link>gemini://cosmic.voyage")
return Response(Status.SUCCESS,f"application/{format}+xml",__generator())