2021-07-22 19:19:49 +00:00
|
|
|
from drama.helpers.wrappers import *
|
|
|
|
from drama.helpers.get import *
|
2021-07-21 01:12:26 +00:00
|
|
|
from flask import g
|
2021-07-22 19:19:49 +00:00
|
|
|
from drama.__main__ import app
|
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:
|
|
|
|
existing = g.db.query(Flag).filter_by(
|
2021-08-01 04:25:26 +00:00
|
|
|
user_id=v.id, post_id=post.id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
if existing:
|
|
|
|
return "", 409
|
2021-07-24 18:15:26 +00:00
|
|
|
reason = request.form.get("reason", "")[:100].strip()
|
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
|
|
|
|
|
|
|
if existing:
|
|
|
|
return "", 409
|
|
|
|
|
2021-07-24 18:15:26 +00:00
|
|
|
reason = request.form.get("reason", "")[:100].strip()
|
2021-07-21 01:12:26 +00:00
|
|
|
flag = CommentFlag(comment_id=comment.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
|