check for existing subscription

master
Aevann1 2022-09-27 02:19:52 +02:00
parent 574040c3f5
commit 6b01467102
1 changed files with 7 additions and 5 deletions

View File

@ -720,8 +720,10 @@ def song(song):
@limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}') @limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}')
@auth_required @auth_required
def subscribe(v, post_id): def subscribe(v, post_id):
new_sub = Subscription(user_id=v.id, submission_id=post_id) existing = g.db.query(Subscription).filter_by(user_id=v.id, submission_id=post_id).one_or_none():
g.db.add(new_sub) if not existing:
new_sub = Subscription(user_id=v.id, submission_id=post_id)
g.db.add(new_sub)
return {"message": "Subscribed to post successfully!"} return {"message": "Subscribed to post successfully!"}
@app.post("/unsubscribe/<post_id>") @app.post("/unsubscribe/<post_id>")
@ -729,9 +731,9 @@ def subscribe(v, post_id):
@limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}') @limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}')
@auth_required @auth_required
def unsubscribe(v, post_id): def unsubscribe(v, post_id):
sub=g.db.query(Subscription).filter_by(user_id=v.id, submission_id=post_id).one_or_none() existing = g.db.query(Subscription).filter_by(user_id=v.id, submission_id=post_id).one_or_none()
if sub: if existing:
g.db.delete(sub) g.db.delete(existing)
return {"message": "Unsubscribed from post successfully!"} return {"message": "Unsubscribed from post successfully!"}
@app.post("/@<username>/message") @app.post("/@<username>/message")