From 544ec6a08a256878074d3cdeeb5bb70e9e739edb Mon Sep 17 00:00:00 2001 From: Kakune55 Date: Wed, 10 Apr 2024 15:24:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E8=A7=88=E5=8A=9F=E8=83=BD=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db.py | 11 ++++--- file.py | 6 +++- main.py | 6 ++-- templates/view.html | 78 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 templates/view.html diff --git a/db.py b/db.py index 10d3e40..7486c31 100644 --- a/db.py +++ b/db.py @@ -16,7 +16,8 @@ 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 ); """ ) @@ -49,18 +50,18 @@ def searchByFilename(filename: str): # 在数据库中添加一个新的文件记录 -def newFile(filename: str): +def newFile(filename: str, pagenumber:int): suuid = shortuuid.random(8) conn = getConn() c = conn.cursor() c.execute( """ INSERT INTO Metadata - (id, filename) + (id, filename, pagenumber) VALUES - (?, ?); + (?, ?, ?); """, - (suuid, filename), + (suuid, filename, pagenumber), ) conn.commit() conn.close() diff --git a/file.py b/file.py index c51fe91..e188499 100644 --- a/file.py +++ b/file.py @@ -20,7 +20,8 @@ def auotLoadFile(): if zipfile.is_zipfile( config.get("file", "inputdir") + "/" + item ): # 判断是否为压缩包 - db.newFile(item) # 添加数据库记录 移动到存储 + with zipfile.ZipFile(config.get("file", "inputdir") + "/" + item, "r") as zip_ref: + db.newFile(item, len(zip_ref.namelist())) # 添加数据库记录 移动到存储 shutil.move( config.get("file", "inputdir") + "/" + item, config.get("file", "storedir") + "/" + item, @@ -46,6 +47,9 @@ def raedZip(bookid: str, index: int): if not image_files: return "not imgfile in zip", "" + + if int(index) > len(image_files): + return "404 not found", "" # 假设我们只提取图片文件 image_filename = image_files[int(index)] diff --git a/main.py b/main.py index 78d2cb9..cec4a37 100644 --- a/main.py +++ b/main.py @@ -60,8 +60,8 @@ def img(bookid, index): # 图片接口 return jsonify({'message': 'No ZIP file part'}), 400 # 设置响应类型为图片 data, filename = file.raedZip(bookid,index) - if data is str: - return data + if isinstance(data, str): + abort(404) response = make_response(data) #读取文件 response.headers.set('Content-Type', 'image/{}'.format(filename.split('.')[-1])) response.headers.set('Content-Disposition', 'inline', filename=filename) @@ -72,7 +72,7 @@ def img(bookid, index): # 图片接口 def book(bookid): # 接口 if request.cookies.get("islogin") is None: return abort(403) - return bookid + return render_template("view.html",data = bookid) @app.route("/view/") diff --git a/templates/view.html b/templates/view.html new file mode 100644 index 0000000..81e25e6 --- /dev/null +++ b/templates/view.html @@ -0,0 +1,78 @@ + + + + + + 漫画详情页 + + + +
+ + + +