chore: update regex pattern and file path in common.py

--bug=1061351 --user=刘瑞斌 【知识库】知识库导出zip没有图片 https://www.tapd.cn/62980211/s/1768275
This commit is contained in:
CaptainB 2025-09-05 11:46:02 +08:00
parent 689391384e
commit 383957abb3
3 changed files with 4 additions and 4 deletions

View File

@ -327,7 +327,7 @@ def flat_map(array: List[List]):
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]
return image_list

View File

@ -177,7 +177,7 @@ def write_image(zip_path: str, image_list: List[str]):
file = QuerySet(File).filter(id=r).first()
if file is None:
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)
if not os.path.exists(os.path.dirname(file_path)):
os.makedirs(os.path.dirname(file_path))

View File

@ -590,10 +590,10 @@ class DocumentSerializers(serializers.Serializer):
workbook = DocumentSerializers.Operate.get_workbook(data_dict, document_dict)
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()
with TemporaryDirectory() as tempdir:
knowledge_file = os.path.join(tempdir, 'knowledge.xlsx')
knowledge_file = os.path.join(tempdir, 'document.xlsx')
workbook.save(knowledge_file)
for r in res:
write_image(tempdir, r)