fdsfds
This commit is contained in:
parent
4009148ff1
commit
dd4fb5b411
10 changed files with 50 additions and 33 deletions
|
@ -42,6 +42,8 @@ class Comment(Base):
|
||||||
oauth_app = relationship("OauthApp", viewonly=True)
|
oauth_app = relationship("OauthApp", viewonly=True)
|
||||||
upvotes = Column(Integer, default=1)
|
upvotes = Column(Integer, default=1)
|
||||||
downvotes = Column(Integer, default=0)
|
downvotes = Column(Integer, default=0)
|
||||||
|
realupvotes = Column(Integer, default=1)
|
||||||
|
realdownvotes = Column(Integer, default=0)
|
||||||
body = Column(String)
|
body = Column(String)
|
||||||
body_html = Column(String)
|
body_html = Column(String)
|
||||||
ban_reason = Column(String)
|
ban_reason = Column(String)
|
||||||
|
|
|
@ -43,6 +43,8 @@ class Submission(Base):
|
||||||
is_bot = Column(Boolean, default=False)
|
is_bot = Column(Boolean, default=False)
|
||||||
upvotes = Column(Integer, default=1)
|
upvotes = Column(Integer, default=1)
|
||||||
downvotes = Column(Integer, default=0)
|
downvotes = Column(Integer, default=0)
|
||||||
|
realupvotes = Column(Integer, default=1)
|
||||||
|
realdownvotes = Column(Integer, default=0)
|
||||||
app_id=Column(Integer, ForeignKey("oauth_apps.id"))
|
app_id=Column(Integer, ForeignKey("oauth_apps.id"))
|
||||||
title = Column(String)
|
title = Column(String)
|
||||||
title_html = Column(String)
|
title_html = Column(String)
|
||||||
|
|
|
@ -251,11 +251,11 @@ class User(Base):
|
||||||
elif sort == "old":
|
elif sort == "old":
|
||||||
posts = posts.order_by(Submission.created_utc.asc())
|
posts = posts.order_by(Submission.created_utc.asc())
|
||||||
elif sort == "controversial":
|
elif sort == "controversial":
|
||||||
posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes * Submission.downvotes)
|
posts = posts.order_by(-1 * Submission.realupvotes * Submission.realdownvotes * Submission.downvotes)
|
||||||
elif sort == "top":
|
elif sort == "top":
|
||||||
posts = posts.order_by(Submission.downvotes - Submission.upvotes)
|
posts = posts.order_by(Submission.realdownvotes - Submission.realupvotes)
|
||||||
elif sort == "bottom":
|
elif sort == "bottom":
|
||||||
posts = posts.order_by(Submission.upvotes - Submission.downvotes)
|
posts = posts.order_by(Submission.realupvotes - Submission.realdownvotes)
|
||||||
elif sort == "comments":
|
elif sort == "comments":
|
||||||
posts = posts.order_by(Submission.comment_count.desc())
|
posts = posts.order_by(Submission.comment_count.desc())
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Vote(Base):
|
||||||
vote_type = Column(Integer)
|
vote_type = Column(Integer)
|
||||||
submission_id = Column(Integer, ForeignKey("submissions.id"))
|
submission_id = Column(Integer, ForeignKey("submissions.id"))
|
||||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||||
|
real = Column(Boolean)
|
||||||
|
|
||||||
user = relationship("User", lazy="subquery", viewonly=True)
|
user = relationship("User", lazy="subquery", viewonly=True)
|
||||||
post = relationship("Submission", lazy="subquery", viewonly=True)
|
post = relationship("Submission", lazy="subquery", viewonly=True)
|
||||||
|
@ -53,6 +54,7 @@ class CommentVote(Base):
|
||||||
vote_type = Column(Integer)
|
vote_type = Column(Integer)
|
||||||
comment_id = Column(Integer, ForeignKey("comments.id"))
|
comment_id = Column(Integer, ForeignKey("comments.id"))
|
||||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||||
|
real = Column(Boolean)
|
||||||
|
|
||||||
user = relationship("User", lazy="subquery", viewonly=True)
|
user = relationship("User", lazy="subquery", viewonly=True)
|
||||||
comment = relationship("Comment", lazy="subquery", viewonly=True)
|
comment = relationship("Comment", lazy="subquery", viewonly=True)
|
||||||
|
|
|
@ -401,7 +401,7 @@ def api_comment(v):
|
||||||
g.db.add(n)
|
g.db.add(n)
|
||||||
|
|
||||||
if v.id == PIZZA_SHILL_ID:
|
if v.id == PIZZA_SHILL_ID:
|
||||||
cratvote = CommentVote(user_id=TAX_RECEIVER_ID, comment_id=c.id, vote_type=1)
|
cratvote = CommentVote(user_id=TAX_RECEIVER_ID, comment_id=c.id, vote_type=1, real=True)
|
||||||
g.db.add(cratvote)
|
g.db.add(cratvote)
|
||||||
v.coins += 1
|
v.coins += 1
|
||||||
v.truecoins += 1
|
v.truecoins += 1
|
||||||
|
@ -584,7 +584,8 @@ def api_comment(v):
|
||||||
|
|
||||||
vote = CommentVote(user_id=v.id,
|
vote = CommentVote(user_id=v.id,
|
||||||
comment_id=c.id,
|
comment_id=c.id,
|
||||||
vote_type=1
|
vote_type=1,
|
||||||
|
real=True
|
||||||
)
|
)
|
||||||
|
|
||||||
g.db.add(vote)
|
g.db.add(vote)
|
||||||
|
|
|
@ -237,17 +237,17 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
|
||||||
|
|
||||||
if sort == "hot":
|
if sort == "hot":
|
||||||
ti = int(time.time()) + 3600
|
ti = int(time.time()) + 3600
|
||||||
posts = posts.order_by(-1000000*(Submission.upvotes + Submission.downvotes + 1 + Submission.comment_count/5)/(func.power(((ti - Submission.created_utc)/1000), 1.35)))
|
posts = posts.order_by(-1000000*(Submission.realupvotes + Submission.realdownvotes + 1 + Submission.comment_count/5)/(func.power(((ti - Submission.created_utc)/1000), 1.35)))
|
||||||
elif sort == "new":
|
elif sort == "new":
|
||||||
posts = posts.order_by(Submission.created_utc.desc())
|
posts = posts.order_by(Submission.created_utc.desc())
|
||||||
elif sort == "old":
|
elif sort == "old":
|
||||||
posts = posts.order_by(Submission.created_utc.asc())
|
posts = posts.order_by(Submission.created_utc.asc())
|
||||||
elif sort == "controversial":
|
elif sort == "controversial":
|
||||||
posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes * Submission.downvotes)
|
posts = posts.order_by(-1 * Submission.realupvotes * Submission.realdownvotes * Submission.downvotes)
|
||||||
elif sort == "top":
|
elif sort == "top":
|
||||||
posts = posts.order_by(Submission.downvotes - Submission.upvotes)
|
posts = posts.order_by(Submission.realdownvotes - Submission.realupvotes)
|
||||||
elif sort == "bottom":
|
elif sort == "bottom":
|
||||||
posts = posts.order_by(Submission.upvotes - Submission.downvotes)
|
posts = posts.order_by(Submission.realupvotes - Submission.realdownvotes)
|
||||||
elif sort == "comments":
|
elif sort == "comments":
|
||||||
posts = posts.order_by(Submission.comment_count.desc())
|
posts = posts.order_by(Submission.comment_count.desc())
|
||||||
|
|
||||||
|
@ -340,11 +340,11 @@ def changeloglist(v=None, sort="new", page=1 ,t="all"):
|
||||||
elif sort == "old":
|
elif sort == "old":
|
||||||
posts = posts.order_by(Submission.created_utc.asc())
|
posts = posts.order_by(Submission.created_utc.asc())
|
||||||
elif sort == "controversial":
|
elif sort == "controversial":
|
||||||
posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes * Submission.downvotes)
|
posts = posts.order_by(-1 * Submission.realupvotes * Submission.realdownvotes * Submission.downvotes)
|
||||||
elif sort == "top":
|
elif sort == "top":
|
||||||
posts = posts.order_by(Submission.downvotes - Submission.upvotes)
|
posts = posts.order_by(Submission.realdownvotes - Submission.realupvotes)
|
||||||
elif sort == "bottom":
|
elif sort == "bottom":
|
||||||
posts = posts.order_by(Submission.upvotes - Submission.downvotes)
|
posts = posts.order_by(Submission.realupvotes - Submission.realdownvotes)
|
||||||
elif sort == "comments":
|
elif sort == "comments":
|
||||||
posts = posts.order_by(Submission.comment_count.desc())
|
posts = posts.order_by(Submission.comment_count.desc())
|
||||||
|
|
||||||
|
@ -407,11 +407,11 @@ def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all"):
|
||||||
elif sort == "old":
|
elif sort == "old":
|
||||||
comments = comments.order_by(Comment.created_utc.asc())
|
comments = comments.order_by(Comment.created_utc.asc())
|
||||||
elif sort == "controversial":
|
elif sort == "controversial":
|
||||||
comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes)
|
comments = comments.order_by(-1 * Comment.realupvotes * Comment.realdownvotes * Comment.downvotes)
|
||||||
elif sort == "top":
|
elif sort == "top":
|
||||||
comments = comments.order_by(Comment.downvotes - Comment.upvotes)
|
comments = comments.order_by(Comment.realdownvotes - Comment.realupvotes)
|
||||||
elif sort == "bottom":
|
elif sort == "bottom":
|
||||||
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
|
comments = comments.order_by(Comment.realupvotes - Comment.realdownvotes)
|
||||||
|
|
||||||
comments = comments.offset(25 * (page - 1)).limit(26).all()
|
comments = comments.offset(25 * (page - 1)).limit(26).all()
|
||||||
return [x[0] for x in comments]
|
return [x[0] for x in comments]
|
||||||
|
|
|
@ -167,11 +167,11 @@ def post_id(pid, anything=None, v=None):
|
||||||
elif sort == "old":
|
elif sort == "old":
|
||||||
comments = comments.order_by(Comment.created_utc.asc())
|
comments = comments.order_by(Comment.created_utc.asc())
|
||||||
elif sort == "controversial":
|
elif sort == "controversial":
|
||||||
comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes)
|
comments = comments.order_by(-1 * Comment.realupvotes * Comment.realdownvotes * Comment.downvotes)
|
||||||
elif sort == "top":
|
elif sort == "top":
|
||||||
comments = comments.order_by(-Comment.upvotes - Comment.downvotes)
|
comments = comments.order_by(-Comment.realupvotes - Comment.realdownvotes)
|
||||||
elif sort == "bottom":
|
elif sort == "bottom":
|
||||||
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
|
comments = comments.order_by(Comment.realupvotes - Comment.realdownvotes)
|
||||||
|
|
||||||
output = []
|
output = []
|
||||||
for c in comments.all():
|
for c in comments.all():
|
||||||
|
@ -191,11 +191,11 @@ def post_id(pid, anything=None, v=None):
|
||||||
elif sort == "old":
|
elif sort == "old":
|
||||||
comments = comments.order_by(Comment.created_utc.asc())
|
comments = comments.order_by(Comment.created_utc.asc())
|
||||||
elif sort == "controversial":
|
elif sort == "controversial":
|
||||||
comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes)
|
comments = comments.order_by(-1 * Comment.realupvotes * Comment.realdownvotes * Comment.downvotes)
|
||||||
elif sort == "top":
|
elif sort == "top":
|
||||||
comments = comments.order_by(-Comment.upvotes - Comment.downvotes)
|
comments = comments.order_by(-Comment.realupvotes - Comment.realdownvotes)
|
||||||
elif sort == "bottom":
|
elif sort == "bottom":
|
||||||
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
|
comments = comments.order_by(Comment.realupvotes - Comment.realdownvotes)
|
||||||
|
|
||||||
post.replies = comments.filter(Comment.is_pinned != None).all() + comments.filter(Comment.level == 1, Comment.is_pinned == None).all()
|
post.replies = comments.filter(Comment.is_pinned != None).all() + comments.filter(Comment.level == 1, Comment.is_pinned == None).all()
|
||||||
|
|
||||||
|
|
|
@ -131,11 +131,11 @@ def searchposts(v):
|
||||||
elif sort == "old":
|
elif sort == "old":
|
||||||
posts = posts.order_by(Submission.created_utc.asc())
|
posts = posts.order_by(Submission.created_utc.asc())
|
||||||
elif sort == "controversial":
|
elif sort == "controversial":
|
||||||
posts = posts.order_by(-1 * Submission.upvotes * Submission.downvotes * Submission.downvotes)
|
posts = posts.order_by(-1 * Submission.realupvotes * Submission.realdownvotes * Submission.downvotes)
|
||||||
elif sort == "top":
|
elif sort == "top":
|
||||||
posts = posts.order_by(Submission.downvotes - Submission.upvotes)
|
posts = posts.order_by(Submission.realdownvotes - Submission.realupvotes)
|
||||||
elif sort == "bottom":
|
elif sort == "bottom":
|
||||||
posts = posts.order_by(Submission.upvotes - Submission.downvotes)
|
posts = posts.order_by(Submission.realupvotes - Submission.realdownvotes)
|
||||||
elif sort == "comments":
|
elif sort == "comments":
|
||||||
posts = posts.order_by(Submission.comment_count.desc())
|
posts = posts.order_by(Submission.comment_count.desc())
|
||||||
|
|
||||||
|
@ -230,11 +230,11 @@ def searchcomments(v):
|
||||||
elif sort == "old":
|
elif sort == "old":
|
||||||
comments = comments.order_by(Comment.created_utc.asc())
|
comments = comments.order_by(Comment.created_utc.asc())
|
||||||
elif sort == "controversial":
|
elif sort == "controversial":
|
||||||
comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes)
|
comments = comments.order_by(-1 * Comment.realupvotes * Comment.realdownvotes * Comment.downvotes)
|
||||||
elif sort == "top":
|
elif sort == "top":
|
||||||
comments = comments.order_by(Comment.downvotes - Comment.upvotes)
|
comments = comments.order_by(Comment.realdownvotes - Comment.realupvotes)
|
||||||
elif sort == "bottom":
|
elif sort == "bottom":
|
||||||
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
|
comments = comments.order_by(Comment.realupvotes - Comment.realdownvotes)
|
||||||
|
|
||||||
total = comments.count()
|
total = comments.count()
|
||||||
|
|
||||||
|
|
|
@ -690,11 +690,11 @@ def u_username_comments(username, v=None):
|
||||||
elif sort == "old":
|
elif sort == "old":
|
||||||
comments = comments.order_by(Comment.created_utc.asc())
|
comments = comments.order_by(Comment.created_utc.asc())
|
||||||
elif sort == "controversial":
|
elif sort == "controversial":
|
||||||
comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes)
|
comments = comments.order_by(-1 * Comment.realupvotes * Comment.realdownvotes * Comment.downvotes)
|
||||||
elif sort == "top":
|
elif sort == "top":
|
||||||
comments = comments.order_by(Comment.downvotes - Comment.upvotes)
|
comments = comments.order_by(Comment.realdownvotes - Comment.realupvotes)
|
||||||
elif sort == "bottom":
|
elif sort == "bottom":
|
||||||
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
|
comments = comments.order_by(Comment.realupvotes - Comment.realdownvotes)
|
||||||
|
|
||||||
comments = comments.offset(25 * (page - 1)).limit(26).all()
|
comments = comments.offset(25 * (page - 1)).limit(26).all()
|
||||||
ids = [x.id for x in comments]
|
ids = [x.id for x in comments]
|
||||||
|
|
|
@ -7,6 +7,8 @@ from files.__main__ import app, limiter, cache
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
from .front import frontlist
|
from .front import frontlist
|
||||||
|
|
||||||
|
defaultcolor = environ.get("DEFAULT_COLOR", "fff").strip()
|
||||||
|
|
||||||
@app.get("/votes")
|
@app.get("/votes")
|
||||||
@limiter.limit("5/second;60/minute;200/hour")
|
@limiter.limit("5/second;60/minute;200/hour")
|
||||||
@auth_desired
|
@auth_desired
|
||||||
|
@ -98,10 +100,12 @@ def api_vote_post(post_id, new, v):
|
||||||
post.author.coins += 1
|
post.author.coins += 1
|
||||||
post.author.truecoins += 1
|
post.author.truecoins += 1
|
||||||
g.db.add(post.author)
|
g.db.add(post.author)
|
||||||
|
real = v.profileurl or v.namecolor != defaultcolor or v.customtitle
|
||||||
vote = Vote(user_id=v.id,
|
vote = Vote(user_id=v.id,
|
||||||
vote_type=new,
|
vote_type=new,
|
||||||
submission_id=post_id,
|
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)
|
g.db.add(vote)
|
||||||
|
|
||||||
|
@ -114,6 +118,8 @@ def api_vote_post(post_id, new, v):
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
post.upvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=1).count()
|
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.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.add(post)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
except: g.db.rollback()
|
except: g.db.rollback()
|
||||||
|
@ -162,10 +168,12 @@ def api_vote_comment(comment_id, new, v):
|
||||||
comment.author.coins += 1
|
comment.author.coins += 1
|
||||||
comment.author.truecoins += 1
|
comment.author.truecoins += 1
|
||||||
g.db.add(comment.author)
|
g.db.add(comment.author)
|
||||||
|
real = v.profileurl or v.namecolor != defaultcolor or v.customtitle
|
||||||
vote = CommentVote(user_id=v.id,
|
vote = CommentVote(user_id=v.id,
|
||||||
vote_type=new,
|
vote_type=new,
|
||||||
comment_id=comment_id,
|
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)
|
g.db.add(vote)
|
||||||
|
@ -178,6 +186,8 @@ def api_vote_comment(comment_id, new, v):
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
comment.upvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=1).count()
|
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.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.add(comment)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
except: g.db.rollback()
|
except: g.db.rollback()
|
||||||
|
@ -206,7 +216,7 @@ def api_vote_poll(comment_id, v):
|
||||||
g.db.add(existing)
|
g.db.add(existing)
|
||||||
else: g.db.delete(existing)
|
else: g.db.delete(existing)
|
||||||
elif new == 1:
|
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)
|
g.db.add(vote)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue