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 os
|
||||||
|
import glob
|
||||||
from subprocess import check_call, CalledProcessError
|
from subprocess import check_call, CalledProcessError
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
||||||
from flask import request, render_template
|
from flask import request, render_template, make_response
|
||||||
|
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
app = Flask(
|
app = Flask(
|
||||||
__name__,
|
__name__,
|
||||||
|
@ -28,11 +31,28 @@ def convert_to_wav(file_name: str):
|
||||||
raise
|
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("/")
|
@app.route("/")
|
||||||
def upload_form():
|
def upload_form():
|
||||||
return render_template(
|
return render_template(
|
||||||
"upload.html",
|
"upload.html",
|
||||||
title="Upload your shit here",
|
title="Upload your shit here",
|
||||||
|
files=uploads(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,5 +85,17 @@ def upload_file():
|
||||||
return "File uploaded successfully"
|
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__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
app.run()
|
||||||
|
|
|
@ -15,6 +15,28 @@
|
||||||
<button type="submit">Upload</button>
|
<button type="submit">Upload</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</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>
|
</body>
|
||||||
</p>
|
</p>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user