2021-10-15 14:08:27 +00:00
|
|
|
from files.helpers.wrappers import *
|
|
|
|
from files.helpers.get import *
|
|
|
|
from flask import g
|
|
|
|
from files.__main__ import app, limiter
|
|
|
|
from os import path
|
2021-12-07 23:18:06 +00:00
|
|
|
from files.helpers.sanitize import filter_emojis_only
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2021-12-05 20:22:57 +00:00
|
|
|
@app.post("/report/post/<pid>")
|
2022-01-15 06:31:17 +00:00
|
|
|
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
2021-12-05 20:22:57 +00:00
|
|
|
@auth_required
|
2021-10-15 14:08:27 +00:00
|
|
|
def api_flag_post(pid, v):
|
|
|
|
|
|
|
|
post = get_post(pid)
|
|
|
|
|
2021-12-05 20:22:57 +00:00
|
|
|
if not v.shadowbanned:
|
2021-10-15 14:08:27 +00:00
|
|
|
reason = request.values.get("reason", "").strip()[:100]
|
|
|
|
|
2021-12-05 20:22:57 +00:00
|
|
|
if not reason.startswith('!'):
|
2022-02-16 01:16:01 +00:00
|
|
|
existing = g.db.query(Flag.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none()
|
2021-12-05 20:22:57 +00:00
|
|
|
if existing: return "", 409
|
|
|
|
|
2021-12-07 23:18:06 +00:00
|
|
|
reason = filter_emojis_only(reason)
|
2021-11-22 14:16:58 +00:00
|
|
|
|
2022-01-07 21:03:14 +00:00
|
|
|
if len(reason) > 350: return {"error": "Too long."}
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2021-12-05 20:22:57 +00:00
|
|
|
if reason.startswith('!') and v.admin_level > 1:
|
|
|
|
post.flair = reason[1:]
|
|
|
|
g.db.add(post)
|
2022-03-19 19:15:13 +00:00
|
|
|
ma=ModAction(
|
|
|
|
kind="flair_post",
|
|
|
|
user_id=v.id,
|
|
|
|
target_submission_id=post.id,
|
|
|
|
_note=f'"{post.flair}"'
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2021-12-05 20:22:57 +00:00
|
|
|
else:
|
|
|
|
flag = Flag(post_id=post.id, user_id=v.id, reason=reason)
|
|
|
|
g.db.add(flag)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
g.db.commit()
|
|
|
|
|
|
|
|
return {"message": "Post reported!"}
|
|
|
|
|
|
|
|
|
2021-12-05 20:22:57 +00:00
|
|
|
@app.post("/report/comment/<cid>")
|
2022-01-15 06:31:17 +00:00
|
|
|
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
2021-12-05 20:22:57 +00:00
|
|
|
@auth_required
|
2021-10-15 14:08:27 +00:00
|
|
|
def api_flag_comment(cid, v):
|
|
|
|
|
|
|
|
comment = get_comment(cid)
|
|
|
|
|
2021-12-05 20:22:57 +00:00
|
|
|
if not v.shadowbanned:
|
2022-02-16 01:16:01 +00:00
|
|
|
existing = g.db.query(CommentFlag.comment_id).filter_by( user_id=v.id, comment_id=comment.id).one_or_none()
|
2021-10-15 14:08:27 +00:00
|
|
|
if existing: return "", 409
|
|
|
|
|
2021-12-07 23:18:06 +00:00
|
|
|
reason = request.values.get("reason", "").strip()[:100]
|
|
|
|
reason = filter_emojis_only(reason)
|
2021-11-22 14:16:58 +00:00
|
|
|
|
2022-01-07 21:03:14 +00:00
|
|
|
if len(reason) > 350: return {"error": "Too long."}
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2021-12-07 23:18:06 +00:00
|
|
|
flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason)
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
g.db.add(flag)
|
|
|
|
g.db.commit()
|
|
|
|
|
|
|
|
return {"message": "Comment reported!"}
|
|
|
|
|
|
|
|
|
2022-02-18 09:39:12 +00:00
|
|
|
@app.post('/del_report/post/<pid>/<uid>')
|
2022-01-15 06:31:17 +00:00
|
|
|
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
2021-11-16 15:24:20 +00:00
|
|
|
@admin_level_required(2)
|
2022-02-18 09:39:12 +00:00
|
|
|
def remove_report_post(v, pid, uid):
|
|
|
|
|
|
|
|
pid = int(pid)
|
|
|
|
uid = int(uid)
|
|
|
|
|
|
|
|
report = g.db.query(Flag).filter_by(post_id=pid, user_id=uid).one()
|
|
|
|
|
|
|
|
g.db.delete(report)
|
|
|
|
|
|
|
|
ma=ModAction(
|
|
|
|
kind="delete_report",
|
|
|
|
user_id=v.id,
|
|
|
|
target_submission_id=pid
|
|
|
|
)
|
|
|
|
|
|
|
|
g.db.add(ma)
|
|
|
|
|
|
|
|
g.db.commit()
|
2021-10-15 14:08:27 +00:00
|
|
|
|
2022-02-18 12:01:24 +00:00
|
|
|
return {"message": "Report removed successfully!"}
|
2022-02-18 09:39:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.post('/del_report/comment/<cid>/<uid>')
|
|
|
|
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
|
|
|
@admin_level_required(2)
|
|
|
|
def remove_report_comment(v, cid, uid):
|
|
|
|
|
|
|
|
cid = int(cid)
|
|
|
|
uid = int(uid)
|
|
|
|
|
|
|
|
report = g.db.query(CommentFlag).filter_by(comment_id=cid, user_id=uid).one()
|
|
|
|
|
2021-10-15 14:08:27 +00:00
|
|
|
g.db.delete(report)
|
|
|
|
|
2022-02-18 09:39:12 +00:00
|
|
|
ma=ModAction(
|
|
|
|
kind="delete_report",
|
|
|
|
user_id=v.id,
|
|
|
|
target_comment_id=cid
|
|
|
|
)
|
|
|
|
|
2022-02-04 13:11:11 +00:00
|
|
|
g.db.add(ma)
|
|
|
|
|
2021-10-15 14:08:27 +00:00
|
|
|
g.db.commit()
|
|
|
|
|
2022-02-18 12:01:24 +00:00
|
|
|
return {"message": "Report removed successfully!"}
|