Skip to content

Commit 53c150c

Browse files
committed
fix: defect of incorrect document names after importing CSV and docx files into the knowledge base
--bug=1052039 --user=王孝刚 【知识库】-压缩文件中包含csv、docx文件时,导入到知识库后,文档名称包含文件夹名称 https://www.tapd.cn/57709429/s/1651752
1 parent 88718c7 commit 53c150c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

apps/common/handle/impl/csv_split_handle.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99
import csv
1010
import io
11+
import os
1112
from typing import List
1213

1314
from charset_normalizer import detect
@@ -28,7 +29,8 @@ class CsvSplitHandle(BaseSplitHandle):
2829
def handle(self, file, pattern_list: List, with_filter: bool, limit: int, get_buffer, save_image):
2930
buffer = get_buffer(file)
3031
paragraphs = []
31-
result = {'name': file.name, 'content': paragraphs}
32+
file_name = os.path.basename(file.name)
33+
result = {'name': file_name, 'content': paragraphs}
3234
try:
3335
reader = csv.reader(io.TextIOWrapper(io.BytesIO(buffer), encoding=detect(buffer)['encoding']))
3436
try:

apps/common/handle/impl/doc_split_handle.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@desc:
88
"""
99
import io
10+
import os
1011
import re
1112
import traceback
1213
import uuid
@@ -167,6 +168,7 @@ def to_md(self, doc, images_list, get_image_id):
167168
in elements])
168169

169170
def handle(self, file, pattern_list: List, with_filter: bool, limit: int, get_buffer, save_image):
171+
file_name = os.path.basename(file.name)
170172
try:
171173
image_list = []
172174
buffer = get_buffer(file)
@@ -180,9 +182,9 @@ def handle(self, file, pattern_list: List, with_filter: bool, limit: int, get_bu
180182
split_model = SplitModel(default_pattern_list, with_filter=with_filter, limit=limit)
181183
except BaseException as e:
182184
traceback.print_exception(e)
183-
return {'name': file.name,
185+
return {'name': file_name,
184186
'content': []}
185-
return {'name': file.name,
187+
return {'name': file_name,
186188
'content': split_model.parse(content)
187189
}
188190

0 commit comments

Comments
 (0)