Skip to content

Commit

Permalink
fix(backend): 修复获取sql内容的编码问题 #5409
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Jul 8, 2024
1 parent e211bd8 commit 7fa093f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dbm-ui/backend/core/storages/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import zipfile
from typing import Any, Dict, List

import chardet
from bkstorages.exceptions import RequestError as BKStorageError
from django.http import StreamingHttpResponse
from rest_framework.status import HTTP_200_OK
Expand Down Expand Up @@ -52,7 +53,9 @@ def batch_fetch_file_content(self, file_path_list: List[str]) -> List[Dict[str,
# 如果文件只有一个,则返回的是文件本身
if len(file_path_list) == 1:
file_path = file_path_list[0]
return [{"path": file_path, "content": zip_content.decode("utf-8"), "url": self.storage.url(file_path)}]
encoding = chardet.detect(zip_content)["encoding"]
zip_content = zip_content.decode(encoding, errors="replace")
return [{"path": file_path, "content": zip_content, "url": self.storage.url(file_path)}]

# 如果是有多个文件,则制品库会打包文件,返回一个zip流
file_stream = io.BytesIO(zip_content)
Expand Down

0 comments on commit 7fa093f

Please sign in to comment.