Skip to content

Commit

Permalink
fix(file_factory): convert tool file correctly. (#11167)
Browse files Browse the repository at this point in the history
Signed-off-by: -LAN- <[email protected]>
  • Loading branch information
laipz8200 authored Nov 27, 2024
1 parent 40fc6f5 commit 787285d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions api/factories/file_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 787285d

Please sign in to comment.