|
|
|
@@ -169,32 +169,44 @@ class HttpRequestNode(BaseNode[HttpRequestNodeData]): |
|
|
|
""" |
|
|
|
Extract files from response by checking both Content-Type header and URL |
|
|
|
""" |
|
|
|
files = [] |
|
|
|
files: list[File] = [] |
|
|
|
is_file = response.is_file |
|
|
|
content_type = response.content_type |
|
|
|
content = response.content |
|
|
|
|
|
|
|
if is_file: |
|
|
|
# Guess file extension from URL or Content-Type header |
|
|
|
filename = url.split("?")[0].split("/")[-1] or "" |
|
|
|
mime_type = content_type or mimetypes.guess_type(filename)[0] or "application/octet-stream" |
|
|
|
|
|
|
|
tool_file = ToolFileManager.create_file_by_raw( |
|
|
|
user_id=self.user_id, |
|
|
|
tenant_id=self.tenant_id, |
|
|
|
conversation_id=None, |
|
|
|
file_binary=content, |
|
|
|
mimetype=mime_type, |
|
|
|
) |
|
|
|
|
|
|
|
mapping = { |
|
|
|
"tool_file_id": tool_file.id, |
|
|
|
"transfer_method": FileTransferMethod.TOOL_FILE.value, |
|
|
|
} |
|
|
|
file = file_factory.build_from_mapping( |
|
|
|
mapping=mapping, |
|
|
|
tenant_id=self.tenant_id, |
|
|
|
) |
|
|
|
files.append(file) |
|
|
|
parsed_content_disposition = response.parsed_content_disposition |
|
|
|
content_disposition_type = None |
|
|
|
|
|
|
|
if not is_file: |
|
|
|
return files |
|
|
|
|
|
|
|
if parsed_content_disposition: |
|
|
|
content_disposition_filename = parsed_content_disposition.get_filename() |
|
|
|
if content_disposition_filename: |
|
|
|
# If filename is available from content-disposition, use it to guess the content type |
|
|
|
content_disposition_type = mimetypes.guess_type(content_disposition_filename)[0] |
|
|
|
|
|
|
|
# Guess file extension from URL or Content-Type header |
|
|
|
filename = url.split("?")[0].split("/")[-1] or "" |
|
|
|
mime_type = ( |
|
|
|
content_disposition_type or content_type or mimetypes.guess_type(filename)[0] or "application/octet-stream" |
|
|
|
) |
|
|
|
|
|
|
|
tool_file = ToolFileManager.create_file_by_raw( |
|
|
|
user_id=self.user_id, |
|
|
|
tenant_id=self.tenant_id, |
|
|
|
conversation_id=None, |
|
|
|
file_binary=content, |
|
|
|
mimetype=mime_type, |
|
|
|
) |
|
|
|
|
|
|
|
mapping = { |
|
|
|
"tool_file_id": tool_file.id, |
|
|
|
"transfer_method": FileTransferMethod.TOOL_FILE.value, |
|
|
|
} |
|
|
|
file = file_factory.build_from_mapping( |
|
|
|
mapping=mapping, |
|
|
|
tenant_id=self.tenant_id, |
|
|
|
) |
|
|
|
files.append(file) |
|
|
|
|
|
|
|
return files |