Add status API route

master
Tanner Collin 3 years ago
parent b213f4cb18
commit d5cfbafbde
  1. 22
      server/main.py

@ -12,6 +12,12 @@ output_folder = Path('./output')
app = Flask(__name__, static_folder=str(build_folder), static_url_path='')
CORS(app)
status = 'Standby'
@app.route('/api/status', methods=['GET'])
def status_get():
return {'status': status}
@app.route('/api/clients', methods=['POST'])
def clients_post():
content = request.json
@ -61,7 +67,7 @@ def session_get(cid):
photo_glob = path.glob('*.jpg')
res = {}
res['photos'] = [x.name for x in photo_glob]
res['photos'] = sorted([x.name for x in photo_glob])
return res
@ -82,6 +88,8 @@ def session_delete(cid):
@app.route('/api/clients/<cid>/session', methods=['POST'])
def session_post(cid):
global status
folder = cid
path = output_folder / cid
@ -89,6 +97,7 @@ def session_post(cid):
abort(404)
# go through the photo taking process
status = 'Warming up'
# warmup
power.lights_on()
@ -96,6 +105,8 @@ def session_post(cid):
power.lights_off()
time.sleep(0.5)
status = 'Capturing'
# capture
power.lights_on()
time.sleep(0.25)
@ -108,14 +119,23 @@ def session_post(cid):
power.grid_off()
power.lights_off()
status = 'Writing to files'
time.sleep(3)
status = 'Downloading'
download.download_all_photos(path)
status = 'Standby'
return ''
@app.route('/')
def index():
return app.send_static_file('index.html')
@app.errorhandler(404)
def not_found(e):
return app.send_static_file('index.html')
@app.route('/output/<path:filename>')
def output(filename):
return send_from_directory('output/', filename)

Loading…
Cancel
Save