feat: downtime status information

This commit is contained in:
2024-11-14 22:02:00 +01:00
parent 7fa965a92c
commit acf88ffa6e

View File

@@ -169,7 +169,7 @@ def webhooks():
db.session.commit() db.session.commit()
return ("", 204) return ("", 204)
@app.route('/downtime', methods=["DELETE","POST"]) @app.route('/downtime', methods=["GET", "DELETE","POST"])
def downtime(): def downtime():
# check static access token # # check static access token #
@@ -179,11 +179,18 @@ def downtime():
if flask.request.method == "DELETE": if flask.request.method == "DELETE":
app.config["DOWNTIME"] = datetime.datetime.now() app.config["DOWNTIME"] = datetime.datetime.now()
return ('Downtime successfully disabled', 200)
elif flask.request.method == "POST": elif flask.request.method == "POST":
minutes = int(flask.request.args.get("minutes") or 5) minutes = int(flask.request.args.get("minutes") or 5)
app.config["DOWNTIME"] = datetime.datetime.now() + datetime.timedelta(minutes=minutes) app.config["DOWNTIME"] = datetime.datetime.now() + datetime.timedelta(minutes=minutes)
return ('Downtime set to {}'.format(app.config["DOWNTIME"].isoformat(), 204))
return ('', 204) elif flask.request.method == "GET":
dt = app.config["DOWNTIME"]
if dt < datetime.datetime.now():
return ("No Downtime set at the moment", 200)
else:
delta = int((dt - datetime.datetime.now()).total_seconds()/60)
return ("Downtime set for {}m until {}".format(delta, dt.isoformat()))
@app.route('/settings', methods=["GET", "POST"]) @app.route('/settings', methods=["GET", "POST"])