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>")
|
2021-10-15 14:08:27 +00:00
|
|
|
@limiter.limit("1/second")
|
2021-12-05 20:22:57 +00:00
|
|
|
@auth_required
|
2021-12-09 21:21:52 +00:00
|
|
|
@validate_formkey
|
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-01-02 00:06:46 +00:00
|
|
|
existing = g.db.query(Flag.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
|
|
|
|
|
|
|
if len(reason) > 350: return {"error": f"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)
|
|
|
|
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>")
|
2021-10-15 14:08:27 +00:00
|
|
|
@limiter.limit("1/second")
|
2021-12-05 20:22:57 +00:00
|
|
|
@auth_required
|
2021-12-09 21:21:52 +00:00
|
|
|
@validate_formkey
|
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-01-02 00:06:46 +00:00
|
|
|
existing = g.db.query(CommentFlag.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
|
|
|
|
|
|
|
if len(reason) > 350: return {"error": f"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!"}
|
|
|
|
|
|
|
|
|
|
|
|
@app.post('/del_report/<report_fn>')
|
|
|
|
@limiter.limit("1/second")
|
2021-11-16 15:24:20 +00:00
|
|
|
@admin_level_required(2)
|
2021-10-15 14:08:27 +00:00
|
|
|
@validate_formkey
|
|
|
|
def remove_report(report_fn, v):
|
|
|
|
|
|
|
|
if report_fn.startswith('c'):
|
2022-01-02 00:06:46 +00:00
|
|
|
report = g.db.query(CommentFlag).filter_by(id=int(report_fn.lstrip('c'))).one_or_none()
|
2021-10-15 14:08:27 +00:00
|
|
|
elif report_fn.startswith('p'):
|
2022-01-02 00:06:46 +00:00
|
|
|
report = g.db.query(Flag).filter_by(id=int(report_fn.lstrip('p'))).one_or_none()
|
2021-10-15 14:08:27 +00:00
|
|
|
else:
|
|
|
|
return {"error": "Invalid report ID"}, 400
|
|
|
|
|
|
|
|
g.db.delete(report)
|
|
|
|
|
|
|
|
g.db.commit()
|
|
|
|
|
2021-09-03 13:52:37 +00:00
|
|
|
return {"message": "Removed report"}
|