From 59df4edf773305bc7018fe4c7bb86675be74fafb Mon Sep 17 00:00:00 2001 From: Kakune55 Date: Wed, 17 Apr 2024 11:43:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E8=BF=9B=E5=BA=A6=E6=9D=A1=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20=E6=94=AF=E6=8C=81=E5=A4=9A=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file.py | 12 ++--- main.py | 2 + templates/upload.html | 116 +++++++++++++++++++++++------------------- web/admin_page.py | 26 ++++++++++ web/page.py | 19 ++----- 5 files changed, 101 insertions(+), 74 deletions(-) create mode 100644 web/admin_page.py diff --git a/file.py b/file.py index d144d57..4dcd617 100644 --- a/file.py +++ b/file.py @@ -5,12 +5,12 @@ from PIL import Image app_conf = app_conf.conf() def init(): - try: - os.makedirs(app_conf.get("file", "inputdir")) - os.makedirs(app_conf.get("file", "storedir")) - os.makedirs(app_conf.get("file", "tmpdir")) - except: - pass + paths = ("inputdir","storedir","tmpdir") + for path in paths: + try: + os.makedirs(app_conf.get("file", path)) + except Exception as e: + print(e) def auotLoadFile(): diff --git a/main.py b/main.py index 2e2cde3..2c6fed3 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ from flask import * from web.api_Img import api_Img_bp from web.page import page_bp +from web.admin_page import admin_page_bp app = Flask(__name__) @@ -18,6 +19,7 @@ def appinit(): app.register_blueprint(api_Img_bp) app.register_blueprint(page_bp) +app.register_blueprint(admin_page_bp) if __name__ == "__main__": appinit() diff --git a/templates/upload.html b/templates/upload.html index 3c73f44..dba7366 100644 --- a/templates/upload.html +++ b/templates/upload.html @@ -3,75 +3,87 @@ - 文件上传 + + 上传文件 +
-

文件上传

-
-
- +

文件上传

+
+
+ +
+
+
- - - -
-
-
- - +
+
+
+
上传进度0%
+ + + + + diff --git a/web/admin_page.py b/web/admin_page.py new file mode 100644 index 0000000..03ae53c --- /dev/null +++ b/web/admin_page.py @@ -0,0 +1,26 @@ +from flask import * +from flask import Blueprint +import time +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 request.form["username"] == conf.get("user", "username") and request.form[ + "password" + ] == conf.get("user", "password"): + resp = make_response(redirect("/overview/1")) + resp.set_cookie("islogin", "True") + return resp + else: + return redirect("/") \ No newline at end of file diff --git a/web/page.py b/web/page.py index 43daa57..ee3301c 100644 --- a/web/page.py +++ b/web/page.py @@ -63,25 +63,12 @@ def upload_file(): 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 redirect("/") + return "success" + -@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 request.form["username"] == conf.get("user", "username") and request.form[ - "password" - ] == conf.get("user", "password"): - resp = make_response(redirect("/overview/1")) - resp.set_cookie("islogin", "True") - return resp - else: - return redirect("/")