From ff2e56dd59b40b69f1b29e03b5e40ebde362f64d Mon Sep 17 00:00:00 2001 From: yumiguan Date: Thu, 28 Oct 2021 19:11:11 +0800 Subject: [PATCH 1/3] Update snapshot export --- lyrebird_bugit/apis.py | 3 --- lyrebird_bugit/attachment.py | 12 +++++++++--- setup.py | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lyrebird_bugit/apis.py b/lyrebird_bugit/apis.py index 0db1cca..9ff5f65 100644 --- a/lyrebird_bugit/apis.py +++ b/lyrebird_bugit/apis.py @@ -201,9 +201,6 @@ def ui_cache(template_key): del field['extraMsg'] all_drafts = cache.get_draft_list(template_key) - for draft in all_drafts: - if draft.get('cacheName') == cache_name: - return application.make_fail_response('Duplicated draft name!') draft_name = cache.get_filename(template_path, cache_name) cache.put(draft_name, template_detail) diff --git a/lyrebird_bugit/attachment.py b/lyrebird_bugit/attachment.py index 1e32c5f..9a55b7c 100644 --- a/lyrebird_bugit/attachment.py +++ b/lyrebird_bugit/attachment.py @@ -16,11 +16,17 @@ def _check_dir(): def export_snapshot(snapshot): _check_dir() - file_content = requests.post(EXPORT_URL,json=snapshot['eventObj'],stream=True).content + res = requests.post(EXPORT_URL, json=snapshot['eventObj'], stream=True) + file_content = res.content + # SnapshotId is unique id of snapshot + id_ = res.headers.get('SnapshotId') with codecs.open(str(ATTACHMENT_ROOT / snapshot['name'])+'.lb', 'wb') as f: f.write(file_content) - return {'id':snapshot['eventObj']['id'],'name':snapshot['name']+'.lb', - 'path':str(ATTACHMENT_ROOT / snapshot['name'])+'.lb'} + return { + 'id': id_, + 'name': snapshot['name']+'.lb', + 'path': str(ATTACHMENT_ROOT / snapshot['name'])+'.lb', + } def remove_attach(): if not ATTACHMENT_ROOT.exists(): diff --git a/setup.py b/setup.py index 607867f..184b6f4 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='lyrebird-bugit', - version='1.8.0', + version='1.8.1', packages=['lyrebird_bugit'], url='https://github.com/Meituan-Dianping/lyrebird-bugit', author='HBQA', From f667e61531d6b37b9d1d5c8aef9e8eefb7398b55 Mon Sep 17 00:00:00 2001 From: yumiguan Date: Thu, 28 Oct 2021 20:03:28 +0800 Subject: [PATCH 2/3] Add file chunck --- lyrebird_bugit/attachment.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lyrebird_bugit/attachment.py b/lyrebird_bugit/attachment.py index 9a55b7c..033efb0 100644 --- a/lyrebird_bugit/attachment.py +++ b/lyrebird_bugit/attachment.py @@ -21,7 +21,8 @@ def export_snapshot(snapshot): # SnapshotId is unique id of snapshot id_ = res.headers.get('SnapshotId') with codecs.open(str(ATTACHMENT_ROOT / snapshot['name'])+'.lb', 'wb') as f: - f.write(file_content) + for chunck in res.iter_content(): + f.write(chunck) return { 'id': id_, 'name': snapshot['name']+'.lb', From 7b8da454d01503dc1bc176d705b4209be9042f5b Mon Sep 17 00:00:00 2001 From: yumiguan Date: Thu, 28 Oct 2021 20:21:12 +0800 Subject: [PATCH 3/3] remove unused variable --- lyrebird_bugit/apis.py | 2 -- lyrebird_bugit/attachment.py | 1 - 2 files changed, 3 deletions(-) diff --git a/lyrebird_bugit/apis.py b/lyrebird_bugit/apis.py index 9ff5f65..9b7ccac 100644 --- a/lyrebird_bugit/apis.py +++ b/lyrebird_bugit/apis.py @@ -200,8 +200,6 @@ def ui_cache(template_key): if 'extraMsg' in field: del field['extraMsg'] - all_drafts = cache.get_draft_list(template_key) - draft_name = cache.get_filename(template_path, cache_name) cache.put(draft_name, template_detail) cache.put(f'{draft_name}{cache.DRAFT_INFO_FILE_SUFFIX}', {'cache_name': cache_name}) diff --git a/lyrebird_bugit/attachment.py b/lyrebird_bugit/attachment.py index 033efb0..d69670c 100644 --- a/lyrebird_bugit/attachment.py +++ b/lyrebird_bugit/attachment.py @@ -17,7 +17,6 @@ def _check_dir(): def export_snapshot(snapshot): _check_dir() res = requests.post(EXPORT_URL, json=snapshot['eventObj'], stream=True) - file_content = res.content # SnapshotId is unique id of snapshot id_ = res.headers.get('SnapshotId') with codecs.open(str(ATTACHMENT_ROOT / snapshot['name'])+'.lb', 'wb') as f: