df
This commit is contained in:
parent
fdeb1e997b
commit
06669e9d4e
8 changed files with 32 additions and 40 deletions
|
@ -7,7 +7,7 @@ from .sanitize import *
|
||||||
from .const import *
|
from .const import *
|
||||||
|
|
||||||
|
|
||||||
def send_notification(vid, user, text, db=None):
|
def send_notification(vid, user, text):
|
||||||
|
|
||||||
# for when working outside request context
|
# for when working outside request context
|
||||||
if isinstance(user, int):
|
if isinstance(user, int):
|
||||||
|
@ -15,9 +15,6 @@ def send_notification(vid, user, text, db=None):
|
||||||
else:
|
else:
|
||||||
uid = user.id
|
uid = user.id
|
||||||
|
|
||||||
if not db:
|
|
||||||
db = g.db
|
|
||||||
|
|
||||||
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
|
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
|
||||||
text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
|
text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
|
||||||
text_html = CustomRenderer().render(mistletoe.Document(text))
|
text_html = CustomRenderer().render(mistletoe.Document(text))
|
||||||
|
@ -28,20 +25,20 @@ def send_notification(vid, user, text, db=None):
|
||||||
parent_submission=None,
|
parent_submission=None,
|
||||||
distinguish_level=6,
|
distinguish_level=6,
|
||||||
)
|
)
|
||||||
db.add(new_comment)
|
g.db.add(new_comment)
|
||||||
|
|
||||||
db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
new_aux = CommentAux(id=new_comment.id,
|
new_aux = CommentAux(id=new_comment.id,
|
||||||
body=text,
|
body=text,
|
||||||
body_html=text_html,
|
body_html=text_html,
|
||||||
)
|
)
|
||||||
db.add(new_aux)
|
g.db.add(new_aux)
|
||||||
|
|
||||||
notif = Notification(comment_id=new_comment.id,
|
notif = Notification(comment_id=new_comment.id,
|
||||||
user_id=uid)
|
user_id=uid)
|
||||||
db.add(notif)
|
g.db.add(notif)
|
||||||
db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
|
|
||||||
def send_follow_notif(vid, user, text):
|
def send_follow_notif(vid, user, text):
|
||||||
|
|
|
@ -92,15 +92,14 @@ def check_ban_evade(v):
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
g.db.flush()
|
|
||||||
try: abort(403)
|
try: abort(403)
|
||||||
except Exception as e: print(e)
|
except Exception as e: print(e)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
v.ban_evade +=1
|
v.ban_evade +=1
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
g.db.flush()
|
|
||||||
|
|
||||||
|
g.db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -96,5 +96,6 @@ def activate(v):
|
||||||
g.db.add(mail_badge)
|
g.db.add(mail_badge)
|
||||||
|
|
||||||
g.db.add(user)
|
g.db.add(user)
|
||||||
|
g.db.commit()
|
||||||
|
|
||||||
return render_template("message_success.html", v=v, title="Email verified.", message=f"Your email {email} has been verified. Thank you.")
|
return render_template("message_success.html", v=v, title="Email verified.", message=f"Your email {email} has been verified. Thank you.")
|
||||||
|
|
|
@ -42,7 +42,7 @@ def revert_actions(v, username):
|
||||||
for user in users:
|
for user in users:
|
||||||
user.unban()
|
user.unban()
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return {"message": "Admin actions reverted!"}
|
return {"message": "Admin actions reverted!"}
|
||||||
|
|
||||||
@app.post("/@<username>/club_allow")
|
@app.post("/@<username>/club_allow")
|
||||||
|
@ -97,7 +97,7 @@ def make_admin(v, username):
|
||||||
if not user: abort(404)
|
if not user: abort(404)
|
||||||
user.admin_level = 6
|
user.admin_level = 6
|
||||||
g.db.add(user)
|
g.db.add(user)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return {"message": "User has been made admin!"}
|
return {"message": "User has been made admin!"}
|
||||||
|
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ def remove_admin(v, username):
|
||||||
if not user: abort(404)
|
if not user: abort(404)
|
||||||
user.admin_level = 0
|
user.admin_level = 0
|
||||||
g.db.add(user)
|
g.db.add(user)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return {"message": "Admin removed!"}
|
return {"message": "Admin removed!"}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ def make_fake_admin(v, username):
|
||||||
if not user: abort(404)
|
if not user: abort(404)
|
||||||
user.admin_level = 1
|
user.admin_level = 1
|
||||||
g.db.add(user)
|
g.db.add(user)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return {"message": "User has been made fake admin!"}
|
return {"message": "User has been made fake admin!"}
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ def remove_fake_admin(v, username):
|
||||||
if not user: abort(404)
|
if not user: abort(404)
|
||||||
user.admin_level = 0
|
user.admin_level = 0
|
||||||
g.db.add(user)
|
g.db.add(user)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return {"message": "Fake admin removed!"}
|
return {"message": "Fake admin removed!"}
|
||||||
|
|
||||||
|
|
||||||
|
@ -436,7 +436,7 @@ def badge_grant_post(v):
|
||||||
|
|
||||||
g.db.add(user)
|
g.db.add(user)
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return redirect("/admin/badge_grant")
|
return redirect("/admin/badge_grant")
|
||||||
|
|
||||||
|
|
||||||
|
@ -720,7 +720,6 @@ def agendaposter(user_id, v):
|
||||||
note = note
|
note = note
|
||||||
)
|
)
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
g.db.flush()
|
|
||||||
|
|
||||||
if user.agendaposter:
|
if user.agendaposter:
|
||||||
if not user.has_badge(26):
|
if not user.has_badge(26):
|
||||||
|
@ -891,8 +890,6 @@ def ban_user(user_id, v):
|
||||||
)
|
)
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
|
|
||||||
g.db.commit()
|
|
||||||
|
|
||||||
if 'reason' in request.args:
|
if 'reason' in request.args:
|
||||||
if reason.startswith("/post/"):
|
if reason.startswith("/post/"):
|
||||||
post = reason.split("/post/")[1].split("/")[0]
|
post = reason.split("/post/")[1].split("/")[0]
|
||||||
|
@ -904,8 +901,11 @@ def ban_user(user_id, v):
|
||||||
comment = get_comment(comment)
|
comment = get_comment(comment)
|
||||||
comment.bannedfor = True
|
comment.bannedfor = True
|
||||||
g.db.add(comment)
|
g.db.add(comment)
|
||||||
|
g.db.commit()
|
||||||
return {"message": f"@{user.username} was banned!"}
|
return {"message": f"@{user.username} was banned!"}
|
||||||
else: return redirect(user.url)
|
else:
|
||||||
|
g.db.commit()
|
||||||
|
return redirect(user.url)
|
||||||
|
|
||||||
|
|
||||||
@app.post("/unban_user/<user_id>")
|
@app.post("/unban_user/<user_id>")
|
||||||
|
@ -937,10 +937,8 @@ def unban_user(user_id, v):
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
if "@" in request.referrer:
|
if "@" in request.referrer: return redirect(user.url)
|
||||||
return redirect(user.url)
|
else: return {"message": f"@{user.username} was unbanned!"}
|
||||||
else:
|
|
||||||
return {"message": f"@{user.username} was unbanned!"}
|
|
||||||
|
|
||||||
@app.post("/ban_post/<post_id>")
|
@app.post("/ban_post/<post_id>")
|
||||||
@admin_level_required(3)
|
@admin_level_required(3)
|
||||||
|
|
|
@ -252,8 +252,7 @@ def award_post(pid, v):
|
||||||
|
|
||||||
send_notification(NOTIFICATIONS_ACCOUNT, post.author, msg)
|
send_notification(NOTIFICATIONS_ACCOUNT, post.author, msg)
|
||||||
|
|
||||||
if kind in ACTIONS:
|
if kind in ACTIONS: ACTIONS[kind](post=post)
|
||||||
ACTIONS[kind](post=post)
|
|
||||||
|
|
||||||
post.author.received_award_count += 1
|
post.author.received_award_count += 1
|
||||||
g.db.add(post.author)
|
g.db.add(post.author)
|
||||||
|
|
|
@ -130,12 +130,11 @@ def admin_app_revoke(v, aid):
|
||||||
if app.id:
|
if app.id:
|
||||||
for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
|
for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
|
||||||
|
|
||||||
g.db.flush()
|
|
||||||
send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been revoked.")
|
send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been revoked.")
|
||||||
|
|
||||||
g.db.delete(app)
|
g.db.delete(app)
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
return {"message": f"App revoked"}
|
return {"message": f"App revoked"}
|
||||||
|
|
||||||
|
@ -149,7 +148,6 @@ def admin_app_reject(v, aid):
|
||||||
|
|
||||||
for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
|
for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
|
||||||
|
|
||||||
g.db.flush()
|
|
||||||
send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been rejected.")
|
send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been rejected.")
|
||||||
|
|
||||||
g.db.delete(app)
|
g.db.delete(app)
|
||||||
|
|
|
@ -448,7 +448,7 @@ def filter_title(title):
|
||||||
IMGUR_KEY = environ.get("IMGUR_KEY", "").strip()
|
IMGUR_KEY = environ.get("IMGUR_KEY", "").strip()
|
||||||
|
|
||||||
|
|
||||||
def check_processing_thread(v, post, link, db):
|
def check_processing_thread(v, post, link):
|
||||||
|
|
||||||
image_id = link.split('/')[-1].rstrip('.mp4')
|
image_id = link.split('/')[-1].rstrip('.mp4')
|
||||||
headers = {"Authorization": f"Client-ID {IMGUR_KEY}"}
|
headers = {"Authorization": f"Client-ID {IMGUR_KEY}"}
|
||||||
|
@ -463,16 +463,15 @@ def check_processing_thread(v, post, link, db):
|
||||||
status = req.json()['data']['processing']['status']
|
status = req.json()['data']['processing']['status']
|
||||||
if status == 'completed':
|
if status == 'completed':
|
||||||
post.processing = False
|
post.processing = False
|
||||||
db.add(post)
|
g.db.add(post)
|
||||||
|
|
||||||
send_notification(
|
send_notification(
|
||||||
NOTIFICATIONS_ACCOUNT,
|
NOTIFICATIONS_ACCOUNT,
|
||||||
v,
|
v,
|
||||||
f"Your video has finished processing and your [post](/post/{post.id}) is now live.",
|
f"Your video has finished processing and your [post](/post/{post.id}) is now live."
|
||||||
db=db
|
|
||||||
)
|
)
|
||||||
|
|
||||||
db.commit()
|
g.db.commit()
|
||||||
break
|
break
|
||||||
# just in case
|
# just in case
|
||||||
elif status == 'failed':
|
elif status == 'failed':
|
||||||
|
@ -933,7 +932,7 @@ def submit_post(v):
|
||||||
post_url += 'mp4'
|
post_url += 'mp4'
|
||||||
new_post.url = post_url
|
new_post.url = post_url
|
||||||
new_post.processing = True
|
new_post.processing = True
|
||||||
gevent.spawn(check_processing_thread, v.id, new_post, post_url, g.db)
|
gevent.spawn(check_processing_thread, v.id, new_post, post_url)
|
||||||
except UploadException as e:
|
except UploadException as e:
|
||||||
if request.headers.get("Authorization"):
|
if request.headers.get("Authorization"):
|
||||||
return {
|
return {
|
||||||
|
@ -1211,8 +1210,8 @@ def unsave_post(pid, v):
|
||||||
|
|
||||||
save=g.db.query(SaveRelationship).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post.id, type=1).first()
|
save=g.db.query(SaveRelationship).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post.id, type=1).first()
|
||||||
|
|
||||||
if save: g.db.delete(save)
|
if save:
|
||||||
|
g.db.delete(save)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
return {"message": "Post unsaved!"}
|
return {"message": "Post unsaved!"}
|
||||||
|
|
|
@ -131,11 +131,12 @@ def transfer_coins(v, username):
|
||||||
receiver.coins += amount
|
receiver.coins += amount
|
||||||
g.db.add(receiver)
|
g.db.add(receiver)
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
g.db.commit()
|
|
||||||
|
|
||||||
transfer_message = f"🤑 [@{v.username}]({v.url}) has gifted you {amount} {app.config['COINS_NAME']}!"
|
transfer_message = f"🤑 [@{v.username}]({v.url}) has gifted you {amount} {app.config['COINS_NAME']}!"
|
||||||
send_notification(NOTIFICATIONS_ACCOUNT, receiver, transfer_message)
|
send_notification(NOTIFICATIONS_ACCOUNT, receiver, transfer_message)
|
||||||
|
|
||||||
|
g.db.commit()
|
||||||
|
|
||||||
return {"message": f"{app.config['COINS_NAME']} transferred!"}
|
return {"message": f"{app.config['COINS_NAME']} transferred!"}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue