From 730cfb2e2ce42cb728e0ca1cce6f4627fc091b0e Mon Sep 17 00:00:00 2001 From: codefly67 Date: Mon, 4 Dec 2023 16:28:48 +0800 Subject: [PATCH 1/2] Supplement bug information, add data and response data to the post request in the description, and place request and response data in the attachment --- .../src/components/event/EventInspector.vue | 28 +++++++++++++++++-- lyrebird_bugit/attachment.py | 12 ++++---- setup.py | 2 +- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/event/EventInspector.vue b/frontend/src/components/event/EventInspector.vue index d516cfc..9338aaa 100644 --- a/frontend/src/components/event/EventInspector.vue +++ b/frontend/src/components/event/EventInspector.vue @@ -191,7 +191,7 @@ export default { if (eventObj.message) { this.$bus.$emit('addMessage', { channel: eventObj.channel, - message: eventObj.message, + message: this.get_event_message(eventObj), id: eventObj.id, sender: eventObj.sender }) @@ -210,7 +210,7 @@ export default { let fileName = `${eventObj.channel}_${eventObj.id}` this.$bus.$emit('addExportAttachments', { attachmentName: fileName, - attachmentObj: eventObj, + attachmentObj: this.getAttachmentObj(eventObj), // TODO: How to get other type's of file attachmentType: 'json' }) @@ -233,6 +233,30 @@ export default { onContextMenuShowAll () { this.$store.dispatch('showAll') this.isContextMenuShown = false + }, + get_event_message (eventObj) { + if (eventObj.channel !== 'flow') { + return eventObj.message + } + let url = eventObj.flow.request.url + let method = eventObj.flow.request.method + let requestData = JSON.stringify(eventObj.flow.request.data) + if (requestData === undefined) { + requestData = JSON.stringify({}) + } + let response = JSON.stringify(eventObj.flow.response) + let message = `URL: ${url}\nMethod: ${method}\nRequestData: ${requestData}\nResponse: ${response}` + return message + }, + getAttachmentObj (eventObj) { + if (eventObj.channel === 'flow') { + const newEventobj = { + 'request': eventObj.flow.request, + 'response': eventObj.flow.response + } + return newEventobj + } + return eventObj } } } diff --git a/lyrebird_bugit/attachment.py b/lyrebird_bugit/attachment.py index 31f14c4..92df33a 100644 --- a/lyrebird_bugit/attachment.py +++ b/lyrebird_bugit/attachment.py @@ -1,5 +1,6 @@ from pathlib import Path import os +import json import codecs import lyrebird import requests @@ -37,15 +38,16 @@ def export_snapshot(snapshot): def export_attachment_file(attachment_obj): _check_dir() full_name = f'{attachment_obj.get("name", "")}.{attachment_obj.get("attachmentType", "json")}' - res = requests.post(EVENT_EXPORT_URL, json=attachment_obj['eventObj'], stream=True) - if res.json().get('code', 1000) == 3000: + + try: + with open(str(ATTACHMENT_ROOT / full_name), 'w') as f: + json.dump(attachment_obj['eventObj'], f, indent=4) + except Exception: return { 'name': full_name, 'path': str(ATTACHMENT_ROOT / full_name) } - with codecs.open(str(ATTACHMENT_ROOT / full_name), 'wb') as f: - for chunk in res.iter_content(): - f.write(chunk) + return { 'id': str(uuid4()), 'name': full_name, diff --git a/setup.py b/setup.py index 751c58b..f672197 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='lyrebird-bugit', - version='1.15.0', + version='1.16.0', packages=['lyrebird_bugit'], url='https://github.com/Meituan-Dianping/lyrebird-bugit', author='HBQA', From 8ac324e8454d73216635ce2898def1a85c001b2c Mon Sep 17 00:00:00 2001 From: changfei Date: Thu, 7 Dec 2023 16:04:38 +0800 Subject: [PATCH 2/2] change file write method --- lyrebird_bugit/attachment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lyrebird_bugit/attachment.py b/lyrebird_bugit/attachment.py index 92df33a..9077ec5 100644 --- a/lyrebird_bugit/attachment.py +++ b/lyrebird_bugit/attachment.py @@ -40,7 +40,7 @@ def export_attachment_file(attachment_obj): full_name = f'{attachment_obj.get("name", "")}.{attachment_obj.get("attachmentType", "json")}' try: - with open(str(ATTACHMENT_ROOT / full_name), 'w') as f: + with codecs.open(str(ATTACHMENT_ROOT / full_name), 'w') as f: json.dump(attachment_obj['eventObj'], f, indent=4) except Exception: return {