### What problem does this PR solve? Change filename length limit from 128 to 256 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Signed-off-by: Jin Hai <haijin.chn@gmail.com>tags/v0.19.1
| @@ -47,7 +47,7 @@ def create(): | |||
| return get_data_error_result(message="Dataset name must be string.") | |||
| if dataset_name == "": | |||
| return get_data_error_result(message="Dataset name can't be empty.") | |||
| if len(dataset_name) >= DATASET_NAME_LIMIT: | |||
| if len(dataset_name.encode("utf-8")) >= DATASET_NAME_LIMIT: | |||
| return get_data_error_result( | |||
| message=f"Dataset name length is {len(dataset_name)} which is large than {DATASET_NAME_LIMIT}") | |||
| @@ -25,3 +25,4 @@ REQUEST_WAIT_SEC = 2 | |||
| REQUEST_MAX_WAIT_SEC = 300 | |||
| DATASET_NAME_LIMIT = 128 | |||
| FILE_NAME_LEN_LIMIT = 256 | |||
| @@ -30,7 +30,7 @@ from api.db.services.file2document_service import File2DocumentService | |||
| from api.utils import get_uuid | |||
| from api.utils.file_utils import filename_type, read_potential_broken_pdf, thumbnail_img | |||
| from rag.utils.storage_factory import STORAGE_IMPL | |||
| from api.constants import FILE_NAME_LEN_LIMIT | |||
| class FileService(CommonService): | |||
| # Service class for managing file operations and storage | |||
| @@ -412,7 +412,7 @@ class FileService(CommonService): | |||
| MAX_FILE_NUM_PER_USER = int(os.environ.get("MAX_FILE_NUM_PER_USER", 0)) | |||
| if MAX_FILE_NUM_PER_USER > 0 and DocumentService.get_doc_count(kb.tenant_id) >= MAX_FILE_NUM_PER_USER: | |||
| raise RuntimeError("Exceed the maximum file number of a free user!") | |||
| if len(file.filename.encode("utf-8")) >= 128: | |||
| if len(file.filename.encode("utf-8")) >= FILE_NAME_LEN_LIMIT: | |||
| raise RuntimeError("Exceed the maximum length of file name!") | |||
| filename = duplicate_name(DocumentService.query, name=file.filename, kb_id=kb.id) | |||
| @@ -108,7 +108,7 @@ def test_invalid_name_dataset(get_auth): | |||
| long_string = "" | |||
| while len(long_string) <= DATASET_NAME_LIMIT: | |||
| while len(long_string.encode("utf-8")) <= DATASET_NAME_LIMIT: | |||
| long_string += random.choice(string.ascii_letters + string.digits) | |||
| res = create_dataset(get_auth, long_string) | |||