diff --git a/db/file.py b/db/file.py index 549a10e..28df532 100644 --- a/db/file.py +++ b/db/file.py @@ -1,4 +1,4 @@ -import shortuuid +import shortuuid, time import db.util as util @@ -27,18 +27,18 @@ def searchByname(filename: str): # 在数据库中添加一个新的文件记录 -def new(filename: str): +def new(filename: str, pagenumber:int): suuid = shortuuid.random(8) conn = util.getConn() c = conn.cursor() c.execute( """ INSERT INTO Metadata - (id, filename) + (id, filename, pagenumber, inputtime) VALUES - (?, ?, ?); + (?, ?, ?, ?); """, - (suuid, filename), + (suuid, filename, pagenumber, int(time.time())), ) conn.commit() conn.close() diff --git a/db/util.py b/db/util.py index d47471c..d5219c1 100644 --- a/db/util.py +++ b/db/util.py @@ -16,7 +16,9 @@ def init(): CREATE TABLE IF NOT EXISTS Metadata ( num INTEGER PRIMARY KEY AUTOINCREMENT, id TEXT NOT NULL, - filename TEXT NOT NULL + filename TEXT NOT NULL, + pagenumber INT NOT NULL, + inputtime INT NOT NULL ); """ ) diff --git a/file.py b/file.py index 976dc34..a765022 100644 --- a/file.py +++ b/file.py @@ -24,7 +24,7 @@ def auotLoadFile(): with zipfile.ZipFile( config.get("file", "inputdir") + "/" + item, "r" ) as zip_ref: - db.file.new(item) # 添加数据库记录 移动到存储 + db.file.new(item, len(zip_ref.namelist())) # 添加数据库记录 移动到存储 shutil.move( config.get("file", "inputdir") + "/" + item, config.get("file", "storedir") + "/" + item, diff --git a/templates/book.html b/templates/book.html new file mode 100644 index 0000000..7e259ad --- /dev/null +++ b/templates/book.html @@ -0,0 +1,82 @@ + + + + + + +详情页面 + + + +
+
+
+ + 封面 +
+
+ +

{{ data[0][2] }}

+

时间: {{time}}

+

暂无评价

+ +
+
+
+

评论区

+ +
+

用户A:Lorem ipsum dolor sit amet consectetur adipisicing elit. Nobis, quam!

+
+
+

用户B:Lorem, ipsum dolor sit amet consectetur adipisicing elit. Aut sunt tempore architecto minus, cum mollitia voluptatibus repellendus aliquid id reprehenderit.

+
+ +
+
+ + diff --git a/templates/upload.html b/templates/upload.html index 5de5c49..3c73f44 100644 --- a/templates/upload.html +++ b/templates/upload.html @@ -27,6 +27,7 @@ diff --git a/web/page.py b/web/page.py index 3f84324..82043af 100644 --- a/web/page.py +++ b/web/page.py @@ -1,7 +1,7 @@ from flask import * from flask import Blueprint -import configparser -import db.file , file +import configparser, time +import db.file, file page_bp = Blueprint("page_bp", __name__) @@ -15,6 +15,8 @@ def overview(page): # 概览 if request.cookies.get("islogin") is None: return redirect("/") metaDataList = db.file.getMetadata((page - 1) * 20, page * 20) + for item in metaDataList: + item[2] = item[2][:-4] #去除文件扩展名 if page <= 3: lastPageList = range(1, page) else: @@ -36,14 +38,26 @@ def book(bookid): # 接口 data = db.file.searchByid(bookid) if data == "": return abort(404) - return render_template("view.html", id=bookid, index=range(1, data[0][3])) + data[0] = list(data[0]) + data[0][2] = data[0][2][0:-4] # 把文件扩展名去掉 + local_time = time.localtime(float(data[0][4])) + + return render_template( + "book.html", + id=bookid, + data=data, + time=time.strftime("%Y-%m-%d %H:%M:%S",local_time), + ) @page_bp.route("/view/") def view(bookid): # 接口 if request.cookies.get("islogin") is None: return abort(403) - return bookid + data = db.file.searchByid(bookid) + if data == "": + return abort(404) + return render_template("view.html", id=bookid, index=range(1, data[0][3])) @page_bp.route("/upload", methods=["GET", "POST"]) # 文件上传