Update comment pagination and ignore data files
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 239 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 280 KiB |
21
back/main.py
21
back/main.py
@@ -340,14 +340,23 @@ def get_comments():
|
||||
if not submission or submission.status != "Pass":
|
||||
return jsonify({"code": 2002, "data": "投稿不存在"})
|
||||
|
||||
page = request.args.get("page", 1, type=int)
|
||||
if page < 1:
|
||||
page = 1
|
||||
|
||||
per_page = 5
|
||||
pagination = Comment.query.filter_by(submission_id=submission_id)\
|
||||
.order_by(Comment.id.asc())\
|
||||
.paginate(page=page, per_page=per_page, error_out=False)
|
||||
|
||||
data = [{
|
||||
"id": c.id,
|
||||
"nickname": c.nickname,
|
||||
"content": c.content,
|
||||
"parent_comment_id": c.parent_comment_id if c.parent_comment_id is not None else 0
|
||||
} for c in submission.comments]
|
||||
} for c in pagination.items]
|
||||
|
||||
return jsonify({"code": 1000, "data": data})
|
||||
return jsonify({"code": 1000, "data": {"comments": data, "total_pages": pagination.pages}})
|
||||
except Exception as e:
|
||||
return jsonify({"code": 2003, "data": str(e)})
|
||||
|
||||
@@ -469,8 +478,8 @@ def get_statics():
|
||||
except Exception as e:
|
||||
return jsonify({"code": 2003, "data": str(e)})
|
||||
|
||||
@app.route('/api/10_info', methods=['GET'])
|
||||
def get_10_info():
|
||||
@app.route('/api/posts_info', methods=['GET'])
|
||||
def get_posts_info():
|
||||
try:
|
||||
page = request.args.get("page", 1, type=int)
|
||||
if page < 1:
|
||||
@@ -503,8 +512,8 @@ def get_10_info():
|
||||
except Exception as e:
|
||||
return jsonify({"code": 2003, "data": str(e)})
|
||||
|
||||
# --- 菜单 ---
|
||||
@app.route('/get/teapot', methods=['GET'])
|
||||
# --- 彩蛋 ---
|
||||
@app.route('/api/teapot', methods=['GET'])
|
||||
def return_418():
|
||||
abort(418)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user