mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
fix plus active check and add logging
This commit is contained in:
parent
691ed6a4c7
commit
358d0521a1
@ -141,12 +141,14 @@ def set_retain(id):
|
|||||||
|
|
||||||
@bp.route("/events/<id>/plus", methods=("POST",))
|
@bp.route("/events/<id>/plus", methods=("POST",))
|
||||||
def send_to_plus(id):
|
def send_to_plus(id):
|
||||||
if current_app.plus_api.is_active():
|
if not current_app.plus_api.is_active():
|
||||||
|
message = "PLUS_API_KEY environment variable is not set"
|
||||||
|
logger.error(message)
|
||||||
return make_response(
|
return make_response(
|
||||||
jsonify(
|
jsonify(
|
||||||
{
|
{
|
||||||
"success": False,
|
"success": False,
|
||||||
"message": "PLUS_API_KEY environment variable is not set",
|
"message": message,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
400,
|
400,
|
||||||
@ -155,14 +157,14 @@ def send_to_plus(id):
|
|||||||
try:
|
try:
|
||||||
event = Event.get(Event.id == id)
|
event = Event.get(Event.id == id)
|
||||||
except DoesNotExist:
|
except DoesNotExist:
|
||||||
return make_response(
|
message = f"Event {id} not found"
|
||||||
jsonify({"success": False, "message": "Event" + id + " not found"}), 404
|
logger.error(message)
|
||||||
)
|
return make_response(jsonify({"success": False, "message": message}), 404)
|
||||||
|
|
||||||
if event.plus_id:
|
if event.plus_id:
|
||||||
return make_response(
|
message = "Already submitted to plus"
|
||||||
jsonify({"success": False, "message": "Already submitted to plus"}), 400
|
logger.error(message)
|
||||||
)
|
return make_response(jsonify({"success": False, "message": message}), 400)
|
||||||
|
|
||||||
# load clean.png
|
# load clean.png
|
||||||
try:
|
try:
|
||||||
@ -180,6 +182,7 @@ def send_to_plus(id):
|
|||||||
try:
|
try:
|
||||||
plus_id = current_app.plus_api.upload_image(image, event.camera)
|
plus_id = current_app.plus_api.upload_image(image, event.camera)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
logger.exception(ex)
|
||||||
return make_response(
|
return make_response(
|
||||||
jsonify({"success": False, "message": str(ex)}),
|
jsonify({"success": False, "message": str(ex)}),
|
||||||
400,
|
400,
|
||||||
|
@ -44,6 +44,8 @@ class PlusApi:
|
|||||||
raise Exception("Plus API not activated")
|
raise Exception("Plus API not activated")
|
||||||
parts = self.key.split(":")
|
parts = self.key.split(":")
|
||||||
r = requests.get(f"{self.host}/v1/auth/token", auth=(parts[0], parts[1]))
|
r = requests.get(f"{self.host}/v1/auth/token", auth=(parts[0], parts[1]))
|
||||||
|
if not r.ok:
|
||||||
|
raise Exception("Unable to refresh API token")
|
||||||
self._token_data = r.json()
|
self._token_data = r.json()
|
||||||
|
|
||||||
def _get_authorization_header(self) -> dict:
|
def _get_authorization_header(self) -> dict:
|
||||||
|
Loading…
Reference in New Issue
Block a user