chore: update regex pattern and file path in common.py
--bug=1061351 --user=刘瑞斌 【知识库】知识库导出zip没有图片 https://www.tapd.cn/62980211/s/1768275v3.2
parent
689391384e
commit
383957abb3
|
|
@ -327,7 +327,7 @@ def flat_map(array: List[List]):
|
||||||
|
|
||||||
|
|
||||||
def parse_image(content: str):
|
def parse_image(content: str):
|
||||||
matches = re.finditer("!\[.*?\]\(\/oss\/(image|file)\/.*?\)", content)
|
matches = re.finditer("!\[.*?\]\(\.\/oss\/(image|file)\/.*?\)", content)
|
||||||
image_list = [match.group() for match in matches]
|
image_list = [match.group() for match in matches]
|
||||||
return image_list
|
return image_list
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ def write_image(zip_path: str, image_list: List[str]):
|
||||||
file = QuerySet(File).filter(id=r).first()
|
file = QuerySet(File).filter(id=r).first()
|
||||||
if file is None:
|
if file is None:
|
||||||
break
|
break
|
||||||
zip_inner_path = os.path.join('api', 'file', r)
|
zip_inner_path = os.path.join('oss', 'file', r)
|
||||||
file_path = os.path.join(zip_path, zip_inner_path)
|
file_path = os.path.join(zip_path, zip_inner_path)
|
||||||
if not os.path.exists(os.path.dirname(file_path)):
|
if not os.path.exists(os.path.dirname(file_path)):
|
||||||
os.makedirs(os.path.dirname(file_path))
|
os.makedirs(os.path.dirname(file_path))
|
||||||
|
|
|
||||||
|
|
@ -590,10 +590,10 @@ class DocumentSerializers(serializers.Serializer):
|
||||||
|
|
||||||
workbook = DocumentSerializers.Operate.get_workbook(data_dict, document_dict)
|
workbook = DocumentSerializers.Operate.get_workbook(data_dict, document_dict)
|
||||||
response = HttpResponse(content_type='application/zip')
|
response = HttpResponse(content_type='application/zip')
|
||||||
response['Content-Disposition'] = 'attachment; filename="archive.zip"'
|
response['Content-Disposition'] = f'attachment; filename="{document.name}.zip"'
|
||||||
zip_buffer = io.BytesIO()
|
zip_buffer = io.BytesIO()
|
||||||
with TemporaryDirectory() as tempdir:
|
with TemporaryDirectory() as tempdir:
|
||||||
knowledge_file = os.path.join(tempdir, 'knowledge.xlsx')
|
knowledge_file = os.path.join(tempdir, 'document.xlsx')
|
||||||
workbook.save(knowledge_file)
|
workbook.save(knowledge_file)
|
||||||
for r in res:
|
for r in res:
|
||||||
write_image(tempdir, r)
|
write_image(tempdir, r)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue