fix(file_factory): convert tool file correctly. (#11167)

Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
-LAN- 2024-11-27 17:28:01 +08:00 committed by GitHub
parent 40fc6f529e
commit 787285d58f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -52,8 +52,6 @@ def build_from_mapping(
tenant_id: str,
config: FileUploadConfig | None = None,
) -> File:
config = config or FileUploadConfig()
transfer_method = FileTransferMethod.value_of(mapping.get("transfer_method"))
build_functions: dict[FileTransferMethod, Callable] = {
@ -72,7 +70,7 @@ def build_from_mapping(
transfer_method=transfer_method,
)
if not _is_file_valid_with_config(
if config and not _is_file_valid_with_config(
input_file_type=mapping.get("type", FileType.CUSTOM),
file_extension=file.extension,
file_transfer_method=file.transfer_method,
@ -127,7 +125,7 @@ def _build_from_local_file(
if row is None:
raise ValueError("Invalid upload file")
file_type = FileType(mapping.get("type"))
file_type = FileType(mapping.get("type", "custom"))
file_type = _standardize_file_type(file_type, extension="." + row.extension, mime_type=row.mime_type)
return File(
@ -157,7 +155,7 @@ def _build_from_remote_url(
mime_type, filename, file_size = _get_remote_file_info(url)
extension = mimetypes.guess_extension(mime_type) or "." + filename.split(".")[-1] if "." in filename else ".bin"
file_type = FileType(mapping.get("type"))
file_type = FileType(mapping.get("type", "custom"))
file_type = _standardize_file_type(file_type, extension=extension, mime_type=mime_type)
return File(
@ -208,7 +206,7 @@ def _build_from_tool_file(
raise ValueError(f"ToolFile {mapping.get('tool_file_id')} not found")
extension = "." + tool_file.file_key.split(".")[-1] if "." in tool_file.file_key else ".bin"
file_type = FileType(mapping.get("type"))
file_type = FileType(mapping.get("type", "custom"))
file_type = _standardize_file_type(file_type, extension=extension, mime_type=tool_file.mimetype)
return File(