diff --git a/conf/app.ini b/conf/app.ini index 13defc9..1952951 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -1,7 +1,8 @@ [server] port=8080 -debug=True +debug=0 host=0.0.0.0 +threaded=0 [user] username=admin diff --git a/file.py b/file.py index a765022..cf950ab 100644 --- a/file.py +++ b/file.py @@ -71,22 +71,23 @@ def raedZip(bookid: str, index: int): def thumbnail(input,size=(400,800)): im = Image.open(io.BytesIO(input)) del input - im = im.convert('RGB') - im.thumbnail(size) - output_io = io.BytesIO() - im.save(output_io,format='WEBP') + newimg = im.convert('RGB') im.close() + newimg.thumbnail(size) + output_io = io.BytesIO() + newimg.save(output_io,format='WEBP') + newimg.close() output_io.seek(0) return output_io def imageToWebP(input): - im = Image.open(io.BytesIO(input)) - del input - im = im.convert('RGB') - output_io = io.BytesIO() - im.save(output_io,format='WEBP') - im.close() - output_io.seek(0) + with Image.open(io.BytesIO(input)) as img: + newimg = img.convert('RGB') + img.close() + output_io = io.BytesIO() + newimg.save(output_io,format='WEBP') + newimg.close() + output_io.seek(0) return output_io diff --git a/main.py b/main.py index c73c362..cecd6eb 100644 --- a/main.py +++ b/main.py @@ -24,7 +24,8 @@ app.register_blueprint(page_bp) if __name__ == "__main__": appinit() app.run( - debug=config.get("server", "debug"), + debug=config.getboolean("server", "debug"), host=config.get("server", "host"), port=config.get("server", "port"), + threaded=config.getboolean("server", "threaded"), ) diff --git a/web/api_Img.py b/web/api_Img.py index fa4fe9f..dfc0cdc 100644 --- a/web/api_Img.py +++ b/web/api_Img.py @@ -9,7 +9,7 @@ api_Img_bp = Blueprint("api_Img_bp", __name__) def img(bookid, index): # 图片接口 if request.cookies.get("islogin") is None: return abort(403) - if db.file.searchByid(bookid) == "": + if len(db.file.searchByid(bookid)) == 0: return abort(404) # 设置响应类型为图片 data, filename = file.raedZip(bookid, index) diff --git a/web/page.py b/web/page.py index 82043af..2e00f27 100644 --- a/web/page.py +++ b/web/page.py @@ -36,7 +36,7 @@ def book(bookid): # 接口 if request.cookies.get("islogin") is None: return abort(403) data = db.file.searchByid(bookid) - if data == "": + if len(data) == 0: return abort(404) data[0] = list(data[0]) data[0][2] = data[0][2][0:-4] # 把文件扩展名去掉 @@ -55,7 +55,7 @@ def view(bookid): # 接口 if request.cookies.get("islogin") is None: return abort(403) data = db.file.searchByid(bookid) - if data == "": + if len(data) == 0: return abort(404) return render_template("view.html", id=bookid, index=range(1, data[0][3]))