mirror of
https://github.com/Kakune55/ComiPy.git
synced 2025-09-16 04:09:41 +08:00
update:更新Router结构,和启动脚本文件
This commit is contained in:
95
router/page.py
Normal file
95
router/page.py
Normal file
@@ -0,0 +1,95 @@
|
||||
from flask import *
|
||||
from flask import Blueprint
|
||||
import time
|
||||
import db.comments, db.user, db.file, file, app_conf
|
||||
|
||||
page_bp = Blueprint("page_bp", __name__)
|
||||
|
||||
conf = app_conf.conf()
|
||||
|
||||
|
||||
@page_bp.route("/overview/<page>")
|
||||
def overview(page): # 概览
|
||||
page = int(page)
|
||||
if request.cookies.get("islogin") is None: # 验证登录状态
|
||||
return redirect("/")
|
||||
metaDataList = db.file.getMetadata(
|
||||
(page - 1) * 20, page * 20, request.args.get("search")
|
||||
)
|
||||
for item in metaDataList:
|
||||
item[2] = item[2][:-4] # 去除文件扩展名
|
||||
if page <= 3:
|
||||
lastPageList = range(1, page)
|
||||
else:
|
||||
lastPageList = range(page - 3, page)
|
||||
nextPageList = range(page + 1, page + 4)
|
||||
return render_template(
|
||||
"overview.html",
|
||||
list=metaDataList,
|
||||
lastPageList=lastPageList,
|
||||
pagenow=page,
|
||||
nextPageList=nextPageList,
|
||||
aftertime=int(time.time()) - 3 * 86400,
|
||||
username=request.cookies.get("islogin"),
|
||||
)
|
||||
|
||||
|
||||
@page_bp.route("/book/<bookid>")
|
||||
def book(bookid): # 接口
|
||||
if request.cookies.get("islogin") is None: # 验证登录状态
|
||||
return redirect("/")
|
||||
data = db.file.searchByid(bookid)
|
||||
if len(data) == 0:
|
||||
return abort(404)
|
||||
data[0] = list(data[0])
|
||||
data[0][2] = data[0][2][0:-4] # 把文件扩展名去掉
|
||||
local_time = time.localtime(float(data[0][4]))
|
||||
|
||||
raw_com = db.comments.listByBookid(bookid)
|
||||
comments = []
|
||||
for i in raw_com:
|
||||
print(request.cookies.get("islogin"))
|
||||
comments.append(
|
||||
{
|
||||
"id": i[0],
|
||||
"time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(float(i[1]))),
|
||||
"from": db.user.getUsername(i[3]),
|
||||
"socre":i[4],
|
||||
"text":i[5]
|
||||
}
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"book.html",
|
||||
id=bookid,
|
||||
data=data,
|
||||
time=time.strftime("%Y-%m-%d %H:%M:%S", local_time),
|
||||
socre=db.comments.getScore(bookid),
|
||||
comments=comments,
|
||||
islogin=request.cookies.get("islogin")
|
||||
)
|
||||
|
||||
|
||||
@page_bp.route("/view/<bookid>")
|
||||
def view(bookid): # 接口
|
||||
if request.cookies.get("islogin") is None: # 验证登录状态
|
||||
return redirect("/")
|
||||
data = db.file.searchByid(bookid)
|
||||
if len(data) == 0:
|
||||
return abort(404)
|
||||
return render_template("view.html.j2", id=bookid, index=range(1, data[0][3]))
|
||||
|
||||
|
||||
@page_bp.route("/upload", methods=["GET", "POST"]) # 文件上传
|
||||
def upload_file():
|
||||
if request.cookies.get("islogin") is None: # 验证登录状态
|
||||
return redirect("/")
|
||||
if request.method == "GET":
|
||||
return render_template("upload.html")
|
||||
uploaded_file = request.files.getlist("files[]") # 获取上传的文件列表
|
||||
print(uploaded_file)
|
||||
for fileitem in uploaded_file:
|
||||
if fileitem.filename != "":
|
||||
fileitem.save(conf.get("file", "inputdir") + "/" + fileitem.filename)
|
||||
file.auotLoadFile()
|
||||
return "success"
|
Reference in New Issue
Block a user