Commit 4fbfcd4f authored by Per Cederqvist's avatar Per Cederqvist

Require a POST request to convert to mp3.

Use a simple form on a separate page so that the file
listing looks nicer (and is valid HTML).
parent d0f2bd70
......@@ -30,7 +30,7 @@ def os_path_split_asunder(path):
return parts
def application(environ, start_response):
if environ["REQUEST_METHOD"] != "GET":
if environ["REQUEST_METHOD"] not in ["GET", "POST"]:
start_response("405 Method Not Allowed",
[('Allow', 'GET')])
return []
......@@ -62,7 +62,8 @@ def application(environ, start_response):
except os.error:
pass
else:
return MP3_OPS[ops[0]](start_response, rel_base, ops[1:])
return MP3_OPS[ops[0]](environ, start_response,
rel_base, ops[1:])
start_response("404 Not found", [])
......@@ -78,10 +79,23 @@ def application(environ, start_response):
start_response("404 Not found", [])
return []
def convert(start_response, rel_base, ops):
def convert(environ, start_response, rel_base, ops):
if len(ops) > 0:
start_response("404 Not found", [])
return []
if environ["REQUEST_METHOD"] == "GET":
start_response("200 OK",
[('Content-Type', 'text/html')])
return ["<html><head><title>Request conversion</title></head>"
"<body><form method=\"POST\" action=\"convert\">"
"<button>Confirm conversion to mp3</button>"
"</form></body></html>"]
if environ["REQUEST_METHOD"] != "POST":
start_response("405 Method Not Allowed",
[('Allow', 'GET, POST')])
c = multiprocessing.connection.Client(mp3wavcfg.socketpath, 'AF_UNIX')
c.send(("encode", rel_base))
while True:
......@@ -162,10 +176,10 @@ def handle_directory(environ, start_response, rel_path):
res.write(" <a href=\"%s.mp3\">.mp3</a>" % quote(w))
res.write(" (" + sizeof_fmt(mp3s[w].st_size) + ")")
else:
res.write("<form method=\"GET\" action=\"%s.mp3/convert\">\n" % (
res.write("<a class=\"convert\" href=\"%s.mp3/convert\">\n" % (
quote(w)))
res.write("<button>Convert to mp3</button>")
res.write("</form>")
res.write("Convert to mp3")
res.write("</a>")
res.write("</li>\n")
res.write("</ul>")
res.write("</body>")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment