Просмотр исходного кода

Update upload filename length limit from 128 to 256, which is aligned with os (#7971)

### 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
Jin Hai 5 месяцев назад
Родитель
Сommit
31f4d44c73
Аккаунт пользователя с таким Email не найден

+ 1
- 1
api/apps/kb_app.py Просмотреть файл

@@ -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}")


+ 1
- 0
api/constants.py Просмотреть файл

@@ -25,3 +25,4 @@ REQUEST_WAIT_SEC = 2
REQUEST_MAX_WAIT_SEC = 300

DATASET_NAME_LIMIT = 128
FILE_NAME_LEN_LIMIT = 256

+ 2
- 2
api/db/services/file_service.py Просмотреть файл

@@ -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)

+ 1
- 1
sdk/python/test/test_frontend_api/test_dataset.py Просмотреть файл

@@ -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)

Загрузка…
Отмена
Сохранить