-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
54 lines (34 loc) · 1.27 KB
/
app.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from src.binqr import service
from flask import Flask, render_template, session, redirect, url_for, request, jsonify
app = Flask(__name__)
app.secret_key = 'anachnu tov'
app.config['MAX_CONTENT_LENGTH'] = 10 * 1024
@app.route("/", methods=['GET'])
def index():
session.clear()
return render_template('index.html')
@app.route("/success", methods=['GET'])
def success():
if 'dir' not in session:
return redirect(url_for('index'))
encoded_images = service.get_images(session['dir'])
session.clear()
return render_template('success.html', keys=sorted(encoded_images), images=encoded_images)
@app.route("/error", methods=['GET'])
def error():
return render_template('error.html')
@app.route("/about", methods=['GET'])
def about():
return render_template('error.html')
@app.route("/process", methods=['POST'])
def process():
if 'file' not in request.files:
return jsonify(error='No file part'), 400
request_file = request.files['file']
if request_file.filename == '':
return jsonify(error='No selected file'), 400
bytes_read = request_file.read()
session['dir'] = service.process(request_file.filename, bytes_read)
return '', 204
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000, debug=True)