Change archive listing to return JSON

This commit is contained in:
Luke Murphy 2020-02-07 11:52:07 +01:00
parent abcb47aa6a
commit 83018a963f
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

View File

@ -3,7 +3,7 @@
import os.path
from pathlib import Path
from flask import Flask, render_template, request, send_from_directory
from flask import Flask, render_template, request, send_from_directory, jsonify
from flask_cors import CORS
from werkzeug.utils import secure_filename
@ -58,5 +58,8 @@ def uploaded_file(filename):
def archive():
"""Serve the archive listing."""
listing = os.listdir(UPLOAD_DIRECTORY)
files = filter(lambda f: f.endswith(".wav"), listing)
return render_template("archive.html", files=files)
filenames = filter(lambda f: f.endswith(".wav"), listing)
return jsonify([
"{}{}".format(request.url_root, filename)
for filename in filenames
])