mirror of
https://github.com/langgenius/dify.git
synced 2026-04-11 12:06:50 +08:00
Signed-off-by: -LAN- <laipz8200@outlook.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: WH-2099 <wh2099@pm.me>
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
"""Validation helpers for workflow file inputs."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dify_graph.file import FileTransferMethod, FileType, FileUploadConfig
|
|
|
|
|
|
def is_file_valid_with_config(
|
|
*,
|
|
input_file_type: str,
|
|
file_extension: str,
|
|
file_transfer_method: FileTransferMethod,
|
|
config: FileUploadConfig,
|
|
) -> bool:
|
|
# FIXME(QIN2DIM): Always allow tool files (files generated by the assistant/model)
|
|
# These are internally generated and should bypass user upload restrictions
|
|
if file_transfer_method == FileTransferMethod.TOOL_FILE:
|
|
return True
|
|
|
|
if (
|
|
config.allowed_file_types
|
|
and input_file_type not in config.allowed_file_types
|
|
and input_file_type != FileType.CUSTOM
|
|
):
|
|
return False
|
|
|
|
if (
|
|
input_file_type == FileType.CUSTOM
|
|
and config.allowed_file_extensions is not None
|
|
and file_extension not in config.allowed_file_extensions
|
|
):
|
|
return False
|
|
|
|
if input_file_type == FileType.IMAGE:
|
|
if (
|
|
config.image_config
|
|
and config.image_config.transfer_methods
|
|
and file_transfer_method not in config.image_config.transfer_methods
|
|
):
|
|
return False
|
|
elif config.allowed_file_upload_methods and file_transfer_method not in config.allowed_file_upload_methods:
|
|
return False
|
|
|
|
return True
|