fdfd
This commit is contained in:
parent
bcb877aaf8
commit
aebe6b9cb4
2 changed files with 57 additions and 7 deletions
|
@ -262,3 +262,48 @@ def no_cors(f):
|
||||||
|
|
||||||
wrapper.__name__ = f.__name__
|
wrapper.__name__ = f.__name__
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def api(*scopes, no_ban=False):
|
||||||
|
|
||||||
|
def wrapper_maker(f):
|
||||||
|
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
|
||||||
|
if request.path.startswith(('/api/v1','/api/v2')):
|
||||||
|
|
||||||
|
v = kwargs.get('v')
|
||||||
|
|
||||||
|
result = f(*args, **kwargs)
|
||||||
|
|
||||||
|
if isinstance(result, dict):
|
||||||
|
resp = result['api']()
|
||||||
|
else:
|
||||||
|
resp = result
|
||||||
|
|
||||||
|
if not isinstance(resp, RespObj):
|
||||||
|
resp = make_response(resp)
|
||||||
|
|
||||||
|
return resp
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
result = f(*args, **kwargs)
|
||||||
|
|
||||||
|
if not isinstance(result, dict):
|
||||||
|
return result
|
||||||
|
|
||||||
|
try:
|
||||||
|
if request.path.startswith('/inpage/'):
|
||||||
|
return result['inpage']()
|
||||||
|
elif request.path.startswith(('/api/vue/','/test/')):
|
||||||
|
return result['api']()
|
||||||
|
else:
|
||||||
|
return result['html']()
|
||||||
|
except KeyError:
|
||||||
|
return result
|
||||||
|
|
||||||
|
wrapper.__name__ = f.__name__
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
return wrapper_maker
|
|
@ -159,9 +159,11 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/comment")
|
@app.post("/api/comment")
|
||||||
|
@app.post("/api/v1/comment")
|
||||||
@limiter.limit("6/minute")
|
@limiter.limit("6/minute")
|
||||||
@is_not_banned
|
@is_not_banned
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
|
@api("create")
|
||||||
def api_comment(v):
|
def api_comment(v):
|
||||||
|
|
||||||
parent_submission = request.form.get("submission")
|
parent_submission = request.form.get("submission")
|
||||||
|
@ -548,12 +550,15 @@ def api_comment(v):
|
||||||
|
|
||||||
v.comment_count = v.comments.filter(Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
|
v.comment_count = v.comments.filter(Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
if request.headers.get("Authorization"): return c.json
|
|
||||||
else: return render_template("comments.html",
|
return {"html": lambda: jsonify({"html": render_template("comments.html",
|
||||||
v=v,
|
v=v,
|
||||||
comments=[c],
|
comments=[c],
|
||||||
render_replies=False,
|
render_replies=False,
|
||||||
)
|
)}),
|
||||||
|
"api": lambda: c.json
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue