From ec0d4ec24e51f2b222f22e40ef8abf50710e3a04 Mon Sep 17 00:00:00 2001 From: xaoyaoo Date: Sat, 22 Jun 2024 19:40:55 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E9=83=A8=E5=88=86=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pywxdump/api/api.py | 69 +++++++++++++++-------------- pywxdump/dbpreprocess/parsingMSG.py | 4 ++ 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/pywxdump/api/api.py b/pywxdump/api/api.py index a9dac43..df70730 100644 --- a/pywxdump/api/api.py +++ b/pywxdump/api/api.py @@ -45,6 +45,7 @@ def init_last_local_wxid(): return ReJson(0, {"local_wxids": local_wxid}) return ReJson(0, {"local_wxids": []}) + @api.route('/api/init_last', methods=["GET", 'POST']) @error9999 def init_last(): @@ -322,8 +323,11 @@ def get_imgsrc(imgsrc): if not imgsrc: return ReJson(1002) + if imgsrc.startswith("FileStorage"): # 如果是本地图片文件则调用get_img + return get_img(imgsrc) + # 将?后面的参数连接到imgsrc - imgsrc = imgsrc + "?" + request.query_string.decode("utf-8") + imgsrc = imgsrc + "?" + request.query_string.decode("utf-8") if request.query_string else imgsrc my_wxid = read_session(g.sf, "test", "last") if not my_wxid: return ReJson(1001, body="my_wxid is required") @@ -348,6 +352,37 @@ def get_imgsrc(imgsrc): return ReJson(4004, body=imgsrc) +@api.route('/api/img/', methods=["GET", 'POST']) +@error9999 +def get_img(img_path): + """ + 获取图片 + :return: + """ + + if not img_path: + return ReJson(1002) + + my_wxid = read_session(g.sf, "test", "last") + if not my_wxid: return ReJson(1001, body="my_wxid is required") + wx_path = read_session(g.sf, my_wxid, "wx_path") + + img_path = img_path.replace("\\\\", "\\") + + img_tmp_path = os.path.join(g.tmp_path, my_wxid, "img") + original_img_path = os.path.join(wx_path, img_path) + if os.path.exists(original_img_path): + fomt, md5, out_bytes = dat2img(original_img_path) + 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) + return send_file(imgsavepath) + else: + return ReJson(1001, body=original_img_path) + + @api.route('/api/msgs', methods=["GET", 'POST']) @error9999 def get_msgs(): @@ -377,38 +412,6 @@ def get_msgs(): return ReJson(0, {"msg_list": msgs, "user_list": user_list}) -@api.route('/api/img/', methods=["GET", 'POST']) -@error9999 -def get_img(img_path): - """ - 获取图片 - :return: - """ - - if not img_path: - return ReJson(1002) - - my_wxid = read_session(g.sf, "test", "last") - if not my_wxid: return ReJson(1001, body="my_wxid is required") - wx_path = read_session(g.sf, my_wxid, "wx_path") - - img_path = img_path.replace("\\\\", "\\") - - img_tmp_path = os.path.join(g.tmp_path, my_wxid, "img") - original_img_path = os.path.join(wx_path, img_path) - - if os.path.exists(original_img_path): - fomt, md5, out_bytes = dat2img(original_img_path) - 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) - return send_file(imgsavepath) - else: - return ReJson(1001, body=original_img_path) - - @api.route('/api/video/', methods=["GET", 'POST']) def get_video(videoPath): my_wxid = read_session(g.sf, "test", "last") diff --git a/pywxdump/dbpreprocess/parsingMSG.py b/pywxdump/dbpreprocess/parsingMSG.py index a5959aa..0ccf456 100644 --- a/pywxdump/dbpreprocess/parsingMSG.py +++ b/pywxdump/dbpreprocess/parsingMSG.py @@ -395,8 +395,12 @@ class ParsingMSG(DatabaseBase): elif type_id == (47, 0): # 动画表情 content_tmp = xml2dict(StrContent) cdnurl = content_tmp.get("emoji", {}).get("cdnurl", "") + if not cdnurl: + DictExtra = self.get_BytesExtra(BytesExtra) + cdnurl = match_BytesExtra(DictExtra) if cdnurl: content = {"src": cdnurl, "msg": "表情"} + elif type_id == (48, 0): # 地图信息 content_tmp = xml2dict(StrContent) location = content_tmp.get("location", {})