From 4b0abf32d0d3e6588c8092c6d6868c954bce036a Mon Sep 17 00:00:00 2001 From: xaoyaoo Date: Tue, 20 Feb 2024 15:15:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E8=B7=AF=E5=BE=84=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E8=AF=B7=E6=B1=82=EF=BC=8C=E6=97=A0=E9=9C=80=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E4=BD=BF=E7=94=A8=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pywxdump/api/api.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/pywxdump/api/api.py b/pywxdump/api/api.py index 7f6f3a0..38cef9f 100644 --- a/pywxdump/api/api.py +++ b/pywxdump/api/api.py @@ -319,23 +319,40 @@ def get_real_time_msg(): @api.route('/api/img', methods=["GET", 'POST']) -@error9999 +# @error9999 def get_img(): """ 获取图片 :return: """ - img_path = request.args.get("img_path") - img_path = request.json.get("img_path", img_path) + if request.method == "GET": + img_path = request.args.get("img_path") + elif request.method == "POST": + img_path = request.json.get("img_path") + else: + return ReJson(1003, msg="Unsupported method") if not img_path: return ReJson(1002) + print(img_path) wx_path = read_session(g.sf, "wx_path") + img_tmp_path = os.path.join(g.tmp_path, "img") img_path_all = os.path.join(wx_path, img_path) + + print(img_path_all) + print(os.path.exists(img_path_all)) + + if os.path.exists(img_path_all): fomt, md5, out_bytes = read_img_dat(img_path_all) - out_bytes = base64.b64encode(out_bytes).decode("utf-8") - out_bytes = f"data:{fomt};base64,{out_bytes}" - return ReJson(0, out_bytes) + imgsavepath = os.path.join(img_tmp_path, img_path+"_"+".".join([md5, fomt])) + if not os.path.exists(os.path.dirname(imgsavepath)): + os.makedirs(os.path.dirname(imgsavepath)) + with open(imgsavepath, "wb") as f: + f.write(out_bytes) + # out_bytes = base64.b64encode(out_bytes).decode("utf-8") + # out_bytes = f"data:{fomt};base64,{out_bytes}" + # return ReJson(0, out_bytes) + return send_file(imgsavepath) else: return ReJson(1001, body=img_path_all)