This commit is contained in:
Aevann1 2021-11-30 16:18:16 +02:00
parent 4009148ff1
commit dd4fb5b411
10 changed files with 50 additions and 33 deletions

View file

@ -7,6 +7,8 @@ from files.__main__ import app, limiter, cache
from sqlalchemy.orm import joinedload
from .front import frontlist
defaultcolor = environ.get("DEFAULT_COLOR", "fff").strip()
@app.get("/votes")
@limiter.limit("5/second;60/minute;200/hour")
@auth_desired
@ -98,10 +100,12 @@ def api_vote_post(post_id, new, v):
post.author.coins += 1
post.author.truecoins += 1
g.db.add(post.author)
real = v.profileurl or v.namecolor != defaultcolor or v.customtitle
vote = Vote(user_id=v.id,
vote_type=new,
submission_id=post_id,
app_id=v.client.application.id if v.client else None
app_id=v.client.application.id if v.client else None,
real = real
)
g.db.add(vote)
@ -114,6 +118,8 @@ def api_vote_post(post_id, new, v):
g.db.flush()
post.upvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=1).count()
post.downvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=-1).count()
post.realupvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=1, real=True).count()
post.realdownvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=-1, real=True).count()
g.db.add(post)
g.db.commit()
except: g.db.rollback()
@ -162,10 +168,12 @@ def api_vote_comment(comment_id, new, v):
comment.author.coins += 1
comment.author.truecoins += 1
g.db.add(comment.author)
real = v.profileurl or v.namecolor != defaultcolor or v.customtitle
vote = CommentVote(user_id=v.id,
vote_type=new,
comment_id=comment_id,
app_id=v.client.application.id if v.client else None
app_id=v.client.application.id if v.client else None,
real=real
)
g.db.add(vote)
@ -178,6 +186,8 @@ def api_vote_comment(comment_id, new, v):
g.db.flush()
comment.upvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=1).count()
comment.downvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=-1).count()
comment.realupvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=1, real=True).count()
comment.realdownvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=-1, real=True).count()
g.db.add(comment)
g.db.commit()
except: g.db.rollback()
@ -206,7 +216,7 @@ def api_vote_poll(comment_id, v):
g.db.add(existing)
else: g.db.delete(existing)
elif new == 1:
vote = CommentVote(user_id=v.id, vote_type=new, comment_id=comment.id)
vote = CommentVote(user_id=v.id, vote_type=new, comment_id=comment.id, real=True)
g.db.add(vote)
try: