fdfd
parent
8a2a34c659
commit
94aa924445
|
@ -30,22 +30,6 @@ class Vote(Base):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Vote(id={self.id})>"
|
return f"<Vote(id={self.id})>"
|
||||||
|
|
||||||
def change_to(self, x):
|
|
||||||
"""
|
|
||||||
1 - upvote
|
|
||||||
0 - novote
|
|
||||||
-1 - downvote
|
|
||||||
"""
|
|
||||||
if x in ["-1", "0", "1"]:
|
|
||||||
x = int(x)
|
|
||||||
elif x not in [-1, 0, 1]:
|
|
||||||
abort(400)
|
|
||||||
|
|
||||||
self.vote_type = x
|
|
||||||
self.created_utc = int(time())
|
|
||||||
|
|
||||||
g.db.add(self)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def json_core(self):
|
def json_core(self):
|
||||||
data={
|
data={
|
||||||
|
@ -73,7 +57,6 @@ class CommentVote(Base):
|
||||||
user_id = Column(Integer, ForeignKey("users.id"))
|
user_id = Column(Integer, ForeignKey("users.id"))
|
||||||
vote_type = Column(Integer)
|
vote_type = Column(Integer)
|
||||||
comment_id = Column(Integer, ForeignKey("comments.id"))
|
comment_id = Column(Integer, ForeignKey("comments.id"))
|
||||||
created_utc = Column(Integer, default=0)
|
|
||||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||||
|
|
||||||
user = relationship("User", lazy="subquery")
|
user = relationship("User", lazy="subquery")
|
||||||
|
@ -89,22 +72,6 @@ class CommentVote(Base):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<CommentVote(id={self.id})>"
|
return f"<CommentVote(id={self.id})>"
|
||||||
|
|
||||||
def change_to(self, x):
|
|
||||||
"""
|
|
||||||
1 - upvote
|
|
||||||
0 - novote
|
|
||||||
-1 - downvote
|
|
||||||
"""
|
|
||||||
if x in ["-1", "0", "1"]:
|
|
||||||
x = int(x)
|
|
||||||
elif x not in [-1, 0, 1]:
|
|
||||||
abort(400)
|
|
||||||
|
|
||||||
self.vote_type = x
|
|
||||||
self.created_utc = int(time())
|
|
||||||
|
|
||||||
g.db.add(self)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def json_core(self):
|
def json_core(self):
|
||||||
data={
|
data={
|
||||||
|
|
|
@ -62,21 +62,21 @@ def admin_vote_info_get(v):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/v1/vote/post/<post_id>/<x>", methods=["POST"])
|
@app.route("/api/v1/vote/post/<post_id>/<new>", methods=["POST"])
|
||||||
@app.route("/api/vote/post/<post_id>/<x>", methods=["POST"])
|
@app.route("/api/vote/post/<post_id>/<new>", methods=["POST"])
|
||||||
@is_not_banned
|
@is_not_banned
|
||||||
@api("vote")
|
@api("vote")
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def api_vote_post(post_id, x, v):
|
def api_vote_post(post_id, new, v):
|
||||||
|
|
||||||
if x not in ["-1", "0", "1"]: abort(400)
|
if new not in ["-1", "0", "1"]: abort(400)
|
||||||
|
|
||||||
# disallow bots
|
# disallow bots
|
||||||
if request.headers.get("X-User-Type","") == "Bot": abort(403)
|
if request.headers.get("X-User-Type","") == "Bot": abort(403)
|
||||||
|
|
||||||
x = int(x)
|
new = int(new)
|
||||||
|
|
||||||
if x==-1:
|
if new==-1:
|
||||||
count=g.db.query(Vote).filter(
|
count=g.db.query(Vote).filter(
|
||||||
Vote.user_id.in_(
|
Vote.user_id.in_(
|
||||||
tuple(
|
tuple(
|
||||||
|
@ -95,20 +95,24 @@ def api_vote_post(post_id, x, v):
|
||||||
existing = g.db.query(Vote).filter_by(user_id=v.id, submission_id=post.id).first()
|
existing = g.db.query(Vote).filter_by(user_id=v.id, submission_id=post.id).first()
|
||||||
|
|
||||||
if existing:
|
if existing:
|
||||||
if existing == 0 and x != 0:
|
if v.id == 1:
|
||||||
|
print(existing)
|
||||||
|
print(new)
|
||||||
|
if existing == 0 and new != 0:
|
||||||
|
print('sex')
|
||||||
post.author.dramacoins += 1
|
post.author.dramacoins += 1
|
||||||
g.db.add(post.author)
|
g.db.add(post.author)
|
||||||
elif existing != 0 and x == 0:
|
elif existing != 0 and new == 0:
|
||||||
post.author.dramacoins -= 1
|
post.author.dramacoins -= 1
|
||||||
g.db.add(post.author)
|
g.db.add(post.author)
|
||||||
existing.change_to(x)
|
existing.vote_type = new
|
||||||
g.db.add(existing)
|
g.db.add(existing)
|
||||||
else:
|
else:
|
||||||
if x != 0:
|
if new != 0:
|
||||||
post.author.dramacoins += 1
|
post.author.dramacoins += 1
|
||||||
g.db.add(post.author)
|
g.db.add(post.author)
|
||||||
vote = Vote(user_id=v.id,
|
vote = Vote(user_id=v.id,
|
||||||
vote_type=x,
|
vote_type=new,
|
||||||
submission_id=base36decode(post_id),
|
submission_id=base36decode(post_id),
|
||||||
app_id=v.client.application.id if v.client else None
|
app_id=v.client.application.id if v.client else None
|
||||||
)
|
)
|
||||||
|
@ -122,21 +126,21 @@ def api_vote_post(post_id, x, v):
|
||||||
g.db.add(post)
|
g.db.add(post)
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
@app.route("/api/v1/vote/comment/<comment_id>/<x>", methods=["POST"])
|
@app.route("/api/v1/vote/comment/<comment_id>/<new>", methods=["POST"])
|
||||||
@app.route("/api/vote/comment/<comment_id>/<x>", methods=["POST"])
|
@app.route("/api/vote/comment/<comment_id>/<new>", methods=["POST"])
|
||||||
@is_not_banned
|
@is_not_banned
|
||||||
@api("vote")
|
@api("vote")
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def api_vote_comment(comment_id, x, v):
|
def api_vote_comment(comment_id, new, v):
|
||||||
|
|
||||||
if x not in ["-1", "0", "1"]:
|
if new not in ["-1", "0", "1"]:
|
||||||
abort(400)
|
abort(400)
|
||||||
|
|
||||||
# disallow bots
|
# disallow bots
|
||||||
if request.headers.get("X-User-Type","") == "Bot":
|
if request.headers.get("X-User-Type","") == "Bot":
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
||||||
x = int(x)
|
new = int(new)
|
||||||
|
|
||||||
comment = get_comment(comment_id)
|
comment = get_comment(comment_id)
|
||||||
|
|
||||||
|
@ -144,16 +148,16 @@ def api_vote_comment(comment_id, x, v):
|
||||||
existing = g.db.query(CommentVote).filter_by(
|
existing = g.db.query(CommentVote).filter_by(
|
||||||
user_id=v.id, comment_id=comment.id).first()
|
user_id=v.id, comment_id=comment.id).first()
|
||||||
if existing:
|
if existing:
|
||||||
if existing == 0 and x != 0:
|
if existing == 0 and new != 0:
|
||||||
comment.author.dramacoins += 1
|
comment.author.dramacoins += 1
|
||||||
g.db.add(comment.author)
|
g.db.add(comment.author)
|
||||||
elif existing != 0 and x == 0:
|
elif existing != 0 and new == 0:
|
||||||
comment.author.dramacoins -= 1
|
comment.author.dramacoins -= 1
|
||||||
g.db.add(comment.author)
|
g.db.add(comment.author)
|
||||||
existing.change_to(x)
|
existing.change_to(new)
|
||||||
g.db.add(existing)
|
g.db.add(existing)
|
||||||
else:
|
else:
|
||||||
if x != 0:
|
if new != 0:
|
||||||
comment.author.dramacoins += 1
|
comment.author.dramacoins += 1
|
||||||
g.db.add(comment.author)
|
g.db.add(comment.author)
|
||||||
vote = CommentVote(user_id=v.id,
|
vote = CommentVote(user_id=v.id,
|
||||||
|
|
Loading…
Reference in New Issue