feat:添加评论删除功能

This commit is contained in:
2024-05-08 20:53:21 +08:00
parent c8bae04145
commit be5d9a8146
4 changed files with 98 additions and 34 deletions

View File

@@ -25,3 +25,20 @@ def comment_api(): # 概览
request.form["text"],
)
return redirect("/book/" + request.form["bookid"])
@comment_api_bp.route("/api/comment/remove")
def remove(): # 删除api
if request.cookies.get("islogin") is None: # 验证登录状态
return abort(403)
try:
id = int(request.args.get("id"))
except:
return abort(400)
commentInfo = db.comments.getById(id)
if commentInfo is None:
return abort(404)
if int(request.cookies.get("uid")) == commentInfo[3]:
if db.comments.remove(id):
return "OK"
return abort(404)
return abort(400)

View File

@@ -48,6 +48,7 @@ def book(bookid): # 接口
raw_com = db.comments.listByBookid(bookid)
comments = []
for i in raw_com:
print(request.cookies.get("islogin"))
comments.append(
{
"id": i[0],
@@ -65,6 +66,7 @@ def book(bookid): # 接口
time=time.strftime("%Y-%m-%d %H:%M:%S", local_time),
socre=db.comments.getScore(bookid),
comments=comments,
islogin=request.cookies.get("islogin")
)