2021-08-04 15:35:10 +00:00
|
|
|
from files.helpers.wrappers import *
|
|
|
|
from files.helpers.get import *
|
2021-07-21 01:12:26 +00:00
|
|
|
from flask import g
|
2021-08-04 15:35:10 +00:00
|
|
|
from files.__main__ import app
|
|
|
|
from files.helpers.sanitize import sanitize
|
2021-08-15 03:17:45 +00:00
|
|
|
from os import path
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/flag/post/<pid>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@auth_desired
|
|
|
|
def api_flag_post(pid, v):
|
|
|
|
|
|
|
|
post = get_post(pid)
|
|
|
|
|
|
|
|
if v:
|
2021-08-05 14:58:25 +00:00
|
|
|
existing = g.db.query(Flag).filter_by(user_id=v.id, post_id=post.id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-08-02 14:39:59 +00:00
|
|
|
if existing: return "", 409
|
2021-08-15 03:17:45 +00:00
|
|
|
|
|
|
|
reason = request.form.get("reason", "").strip()[:100]
|
|
|
|
|
|
|
|
for i in re.finditer(':(.{1,30}?):', reason):
|
|
|
|
if path.isfile(f'./files/assets/images/emojis/{i.group(1)}.gif'):
|
|
|
|
reason = reason.replace(f':{i.group(1)}:', f'<img data-toggle="tooltip" title="{i.group(1)}" delay="0" height=20 src="https://{site}/assets/images/emojis/{i.group(1)}.gif"<span>')
|
2021-08-02 14:39:59 +00:00
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
flag = Flag(post_id=post.id,
|
|
|
|
user_id=v.id,
|
2021-07-24 18:15:26 +00:00
|
|
|
reason=reason,
|
2021-07-21 01:12:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
g.db.add(flag)
|
|
|
|
|
|
|
|
return "", 204
|
|
|
|
|
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/flag/comment/<cid>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@auth_desired
|
|
|
|
def api_flag_comment(cid, v):
|
|
|
|
|
|
|
|
comment = get_comment(cid)
|
|
|
|
|
|
|
|
if v:
|
|
|
|
existing = g.db.query(CommentFlag).filter_by(
|
2021-08-01 04:25:26 +00:00
|
|
|
user_id=v.id, comment_id=comment.id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-08-02 14:39:59 +00:00
|
|
|
if existing: return "", 409
|
2021-08-15 03:17:45 +00:00
|
|
|
reason = request.form.get("reason", "").strip()[:100]
|
|
|
|
|
|
|
|
for i in re.finditer(':(.{1,30}?):', reason):
|
|
|
|
if path.isfile(f'./files/assets/images/emojis/{i.group(1)}.gif'):
|
|
|
|
reason = reason.replace(f':{i.group(1)}:', f'<img data-toggle="tooltip" title="{i.group(1)}" delay="0" height=20 src="https://{site}/assets/images/emojis/{i.group(1)}.gif"<span>')
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-08-15 22:37:35 +00:00
|
|
|
flag = CommentFlag(comment_id=comment.id,
|
2021-08-15 22:35:54 +00:00
|
|
|
user_id=v.id,
|
|
|
|
reason=reason,
|
|
|
|
)
|
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
g.db.add(flag)
|
|
|
|
|
|
|
|
return "", 204
|