-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy_backend.py
36 lines (28 loc) · 842 Bytes
/
dummy_backend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from flask import abort, Flask, jsonify, send_file
app = Flask(__name__)
DUMMY_FILES = dict({
"File1": {
"summary": "Summary text of file 1"
},
"File2": {
"summary": "Summary text of file 2"
},
"File3": {
"summary": "Summary text of file 3"
}
})
@app.route("/api/files")
def list_files():
return jsonify(DUMMY_FILES)
@app.route("/api/download/file/<variant>")
def download_file(variant=None):
if not variant in DUMMY_FILES:
abort(404)
return send_file(
f"./dummy_files/{variant}.txt",
as_attachment=True
)
if __name__ == "__main__":
# debug=True will cause flask to send detailed exception traceback in
# the response body. this is useful when trying out requests from a browser
app.run(host="0.0.0.0", port=3000, debug=True)