add list of uploads, /run/ entrypoint
This commit is contained in:
parent
d3709bd779
commit
3c651d65aa
34
app.py
34
app.py
|
@ -1,8 +1,11 @@
|
|||
import os
|
||||
import glob
|
||||
from subprocess import check_call, CalledProcessError
|
||||
from flask import Flask
|
||||
|
||||
from flask import request, render_template
|
||||
from flask import request, render_template, make_response
|
||||
|
||||
from threading import Thread
|
||||
|
||||
app = Flask(
|
||||
__name__,
|
||||
|
@ -28,11 +31,28 @@ def convert_to_wav(file_name: str):
|
|||
raise
|
||||
|
||||
|
||||
def run_cassetta(cassetta: str):
|
||||
command = f"aplay uploads/{cassetta}"
|
||||
|
||||
try:
|
||||
check_call(command.split())
|
||||
except CalledProcessError as exc:
|
||||
print(f"aplay failed: {exc.output=}\n{exc.stderr=}")
|
||||
|
||||
|
||||
def uploads():
|
||||
return map(
|
||||
os.path.basename,
|
||||
glob.glob("uploads/*wav"),
|
||||
)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def upload_form():
|
||||
return render_template(
|
||||
"upload.html",
|
||||
title="Upload your shit here",
|
||||
files=uploads(),
|
||||
)
|
||||
|
||||
|
||||
|
@ -65,5 +85,17 @@ def upload_file():
|
|||
return "File uploaded successfully"
|
||||
|
||||
|
||||
@app.route("/run/<string:cassetta>", methods=["GET"])
|
||||
def run(cassetta: str):
|
||||
thread = Thread(target=run_cassetta, args=(cassetta,))
|
||||
thread.start()
|
||||
|
||||
response = make_response(make_response("", 301))
|
||||
response.headers["Location"] = "/"
|
||||
response.status_code = 301
|
||||
|
||||
return response
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
|
|
|
@ -15,6 +15,28 @@
|
|||
<button type="submit">Upload</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p> Cassette:</p>
|
||||
<table border="1">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nome</th>
|
||||
<!-- {% for header in headers %} -->
|
||||
<!-- <th>{{ header }}</th> -->
|
||||
<!-- {% endfor %} -->
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for file in files %}
|
||||
<tr>
|
||||
<td>{{ file }}</td>
|
||||
<td><a href="/run/{{ file }}">run</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</p>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue
Block a user