mirror of
https://github.com/simon987/od-database.git
synced 2025-04-19 10:26:44 +00:00
API endpoint to cancel task
This commit is contained in:
parent
1d3318f6e2
commit
db26e851a4
18
app.py
18
app.py
@ -565,6 +565,23 @@ def api_get_task():
|
||||
return abort(403)
|
||||
|
||||
|
||||
@app.route("/api/task/cancel", methods=["POST"])
|
||||
def api_cancel_task():
|
||||
token = request.form.get("token")
|
||||
name = db.check_api_token(token)
|
||||
|
||||
if name:
|
||||
website_id = request.form.get("website_id") if "website_id" in request.form else None
|
||||
if website_id:
|
||||
db.delete_task(website_id)
|
||||
return Response("cancelled task")
|
||||
else:
|
||||
abort(400)
|
||||
|
||||
else:
|
||||
abort(403)
|
||||
|
||||
|
||||
@app.route("/api/task/complete", methods=["POST"])
|
||||
def api_complete_task():
|
||||
token = request.form.get("token")
|
||||
@ -765,5 +782,6 @@ def api_search():
|
||||
return abort(403)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run("0.0.0.0", port=12345, threaded=True)
|
||||
|
@ -400,6 +400,12 @@ class Database:
|
||||
else:
|
||||
return None
|
||||
|
||||
def delete_task(self, website_id):
|
||||
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("DELETE FROM Queue WHERE website_id=?", (website_id, ))
|
||||
|
||||
def complete_task(self, website_id: int, name: str) -> Task:
|
||||
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
|
Loading…
x
Reference in New Issue
Block a user