mirror of
https://github.com/Kakune55/ComiPy.git
synced 2025-05-06 18:29:26 +08:00
优化内存消耗 添加·单线程模式
This commit is contained in:
parent
0d68d58e3f
commit
30d99c1f08
@ -1,7 +1,8 @@
|
|||||||
[server]
|
[server]
|
||||||
port=8080
|
port=8080
|
||||||
debug=True
|
debug=0
|
||||||
host=0.0.0.0
|
host=0.0.0.0
|
||||||
|
threaded=0
|
||||||
|
|
||||||
[user]
|
[user]
|
||||||
username=admin
|
username=admin
|
||||||
|
19
file.py
19
file.py
@ -71,21 +71,22 @@ def raedZip(bookid: str, index: int):
|
|||||||
def thumbnail(input,size=(400,800)):
|
def thumbnail(input,size=(400,800)):
|
||||||
im = Image.open(io.BytesIO(input))
|
im = Image.open(io.BytesIO(input))
|
||||||
del input
|
del input
|
||||||
im = im.convert('RGB')
|
newimg = im.convert('RGB')
|
||||||
im.thumbnail(size)
|
|
||||||
output_io = io.BytesIO()
|
|
||||||
im.save(output_io,format='WEBP')
|
|
||||||
im.close()
|
im.close()
|
||||||
|
newimg.thumbnail(size)
|
||||||
|
output_io = io.BytesIO()
|
||||||
|
newimg.save(output_io,format='WEBP')
|
||||||
|
newimg.close()
|
||||||
output_io.seek(0)
|
output_io.seek(0)
|
||||||
return output_io
|
return output_io
|
||||||
|
|
||||||
def imageToWebP(input):
|
def imageToWebP(input):
|
||||||
im = Image.open(io.BytesIO(input))
|
with Image.open(io.BytesIO(input)) as img:
|
||||||
del input
|
newimg = img.convert('RGB')
|
||||||
im = im.convert('RGB')
|
img.close()
|
||||||
output_io = io.BytesIO()
|
output_io = io.BytesIO()
|
||||||
im.save(output_io,format='WEBP')
|
newimg.save(output_io,format='WEBP')
|
||||||
im.close()
|
newimg.close()
|
||||||
output_io.seek(0)
|
output_io.seek(0)
|
||||||
return output_io
|
return output_io
|
||||||
|
|
||||||
|
3
main.py
3
main.py
@ -24,7 +24,8 @@ app.register_blueprint(page_bp)
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
appinit()
|
appinit()
|
||||||
app.run(
|
app.run(
|
||||||
debug=config.get("server", "debug"),
|
debug=config.getboolean("server", "debug"),
|
||||||
host=config.get("server", "host"),
|
host=config.get("server", "host"),
|
||||||
port=config.get("server", "port"),
|
port=config.get("server", "port"),
|
||||||
|
threaded=config.getboolean("server", "threaded"),
|
||||||
)
|
)
|
||||||
|
@ -9,7 +9,7 @@ api_Img_bp = Blueprint("api_Img_bp", __name__)
|
|||||||
def img(bookid, index): # 图片接口
|
def img(bookid, index): # 图片接口
|
||||||
if request.cookies.get("islogin") is None:
|
if request.cookies.get("islogin") is None:
|
||||||
return abort(403)
|
return abort(403)
|
||||||
if db.file.searchByid(bookid) == "":
|
if len(db.file.searchByid(bookid)) == 0:
|
||||||
return abort(404)
|
return abort(404)
|
||||||
# 设置响应类型为图片
|
# 设置响应类型为图片
|
||||||
data, filename = file.raedZip(bookid, index)
|
data, filename = file.raedZip(bookid, index)
|
||||||
|
@ -36,7 +36,7 @@ def book(bookid): # 接口
|
|||||||
if request.cookies.get("islogin") is None:
|
if request.cookies.get("islogin") is None:
|
||||||
return abort(403)
|
return abort(403)
|
||||||
data = db.file.searchByid(bookid)
|
data = db.file.searchByid(bookid)
|
||||||
if data == "":
|
if len(data) == 0:
|
||||||
return abort(404)
|
return abort(404)
|
||||||
data[0] = list(data[0])
|
data[0] = list(data[0])
|
||||||
data[0][2] = data[0][2][0:-4] # 把文件扩展名去掉
|
data[0][2] = data[0][2][0:-4] # 把文件扩展名去掉
|
||||||
@ -55,7 +55,7 @@ def view(bookid): # 接口
|
|||||||
if request.cookies.get("islogin") is None:
|
if request.cookies.get("islogin") is None:
|
||||||
return abort(403)
|
return abort(403)
|
||||||
data = db.file.searchByid(bookid)
|
data = db.file.searchByid(bookid)
|
||||||
if data == "":
|
if len(data) == 0:
|
||||||
return abort(404)
|
return abort(404)
|
||||||
return render_template("view.html", id=bookid, index=range(1, data[0][3]))
|
return render_template("view.html", id=bookid, index=range(1, data[0][3]))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user