mirror of
https://github.com/Kakune55/ComiPy.git
synced 2025-09-16 04:09:41 +08:00
update:更新Router结构,和启动脚本文件
This commit is contained in:
27
router/admin_page.py
Normal file
27
router/admin_page.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from flask import *
|
||||
from flask import Blueprint
|
||||
import time
|
||||
import db.user
|
||||
import db.file, file, app_conf
|
||||
|
||||
admin_page_bp = Blueprint("admin_page_bp", __name__)
|
||||
|
||||
conf = app_conf.conf()
|
||||
|
||||
# 管理页
|
||||
|
||||
|
||||
@admin_page_bp.route("/", methods=["GET", "POST"])
|
||||
def login(): # 登录页面
|
||||
if request.method == "GET":
|
||||
if request.cookies.get("islogin") is not None:
|
||||
return redirect("/overview/1")
|
||||
return render_template("login.html")
|
||||
elif request.method == "POST":
|
||||
if db.user.check(request.form["username"], request.form["password"]):
|
||||
resp = make_response(redirect("/overview/1"))
|
||||
resp.set_cookie("islogin", request.form["username"])
|
||||
resp.set_cookie("uid", str(db.user.getUid(request.form["username"])))
|
||||
return resp
|
||||
else:
|
||||
return redirect("/")
|
31
router/api_Img.py
Normal file
31
router/api_Img.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from flask import *
|
||||
from flask import Blueprint
|
||||
import db.file , file, gc , app_conf
|
||||
|
||||
api_Img_bp = Blueprint("api_Img_bp", __name__)
|
||||
|
||||
conf = app_conf.conf()
|
||||
imgencode = conf.get("img", "encode")
|
||||
miniSize = conf.getint("img", "miniSize")
|
||||
fullSize = conf.getint("img", "fullSize")
|
||||
|
||||
@api_Img_bp.route("/api/img/<bookid>/<index>")
|
||||
def img(bookid, index): # 图片接口
|
||||
if request.cookies.get("islogin") is None:
|
||||
return abort(403)
|
||||
if len(db.file.searchByid(bookid)) == 0:
|
||||
return abort(404)
|
||||
# 设置响应类型为图片
|
||||
data, filename = file.raedZip(bookid, index)
|
||||
if isinstance(data, str):
|
||||
abort(404)
|
||||
if request.args.get("mini") == "yes":
|
||||
data = file.thumbnail(data,miniSize,encode=imgencode)
|
||||
else:
|
||||
data = file.thumbnail(data,fullSize,encode=imgencode)
|
||||
response = make_response(data) # 读取文件
|
||||
del data
|
||||
response.headers.set("Content-Type",f"image/{imgencode}")
|
||||
response.headers.set("Content-Disposition", "inline", filename=filename)
|
||||
gc.collect()
|
||||
return response
|
44
router/api_comment.py
Normal file
44
router/api_comment.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from flask import *
|
||||
from flask import Blueprint
|
||||
import time
|
||||
import db.comments, db.file, app_conf
|
||||
|
||||
comment_api_bp = Blueprint("comment_api_bp", __name__)
|
||||
|
||||
conf = app_conf.conf()
|
||||
|
||||
|
||||
@comment_api_bp.route("/api/comment/upload", methods=["POST"])
|
||||
def comment_api(): # 概览
|
||||
if request.cookies.get("islogin") is None: # 验证登录状态
|
||||
return redirect("/")
|
||||
if request.form["score"] != "none" and request.form["text"].isspace():
|
||||
return "评论不能为空"
|
||||
if len(request.form["text"]) > 200:
|
||||
return "评论过长(需要小于200字)"
|
||||
if db.comments.searchByAll(request.cookies.get("uid"), request.form["bookid"]):
|
||||
return "你已经完成了评论 不可重复提交"
|
||||
db.comments.new(
|
||||
request.form["bookid"],
|
||||
request.cookies.get("uid"),
|
||||
request.form["score"],
|
||||
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)
|
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