add health check and handle bad camera names

This commit is contained in:
Blake Blackshear 2019-12-08 09:40:00 -06:00
parent f148eb5a7b
commit 39d64f7ba7

View File

@ -66,8 +66,14 @@ def main():
# create a flask app that encodes frames a mjpeg on demand # create a flask app that encodes frames a mjpeg on demand
app = Flask(__name__) app = Flask(__name__)
@app.route('/')
def ishealthy():
# return a healh
return "Frigate is running. Alive and healthy!"
@app.route('/<camera_name>/best_person.jpg') @app.route('/<camera_name>/best_person.jpg')
def best_person(camera_name): def best_person(camera_name):
if camera_name in cameras:
best_person_frame = cameras[camera_name].get_best_person() best_person_frame = cameras[camera_name].get_best_person()
if best_person_frame is None: if best_person_frame is None:
best_person_frame = np.zeros((720,1280,3), np.uint8) best_person_frame = np.zeros((720,1280,3), np.uint8)
@ -75,12 +81,17 @@ def main():
response = make_response(jpg.tobytes()) response = make_response(jpg.tobytes())
response.headers['Content-Type'] = 'image/jpg' response.headers['Content-Type'] = 'image/jpg'
return response return response
else:
return f'Camera named {camera_name} not found', 404
@app.route('/<camera_name>') @app.route('/<camera_name>')
def mjpeg_feed(camera_name): def mjpeg_feed(camera_name):
if camera_name in cameras:
# return a multipart response # return a multipart response
return Response(imagestream(camera_name), return Response(imagestream(camera_name),
mimetype='multipart/x-mixed-replace; boundary=frame') mimetype='multipart/x-mixed-replace; boundary=frame')
else:
return f'Camera named {camera_name} not found', 404
def imagestream(camera_name): def imagestream(camera_name):
while True: while True: