Files
dify/api/dify_graph/file/constants.py
-LAN- 56593f20b0 refactor(api): continue decoupling dify_graph from API concerns (#33580)
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>
2026-03-25 20:32:24 +08:00

49 lines
1.4 KiB
Python

from collections.abc import Iterable
from typing import Any
# TODO(QuantumGhost): Refactor variable type identification. Instead of directly
# comparing `dify_model_identity` with constants throughout the codebase, extract
# this logic into a dedicated function. This would encapsulate the implementation
# details of how different variable types are identified.
FILE_MODEL_IDENTITY = "__dify__file__"
DEFAULT_MIME_TYPE = "application/octet-stream"
DEFAULT_EXTENSION = ".bin"
def _with_case_variants(extensions: Iterable[str]) -> frozenset[str]:
normalized = {extension.lower() for extension in extensions}
return frozenset(normalized | {extension.upper() for extension in normalized})
IMAGE_EXTENSIONS = _with_case_variants({"jpg", "jpeg", "png", "webp", "gif", "svg"})
VIDEO_EXTENSIONS = _with_case_variants({"mp4", "mov", "mpeg", "webm"})
AUDIO_EXTENSIONS = _with_case_variants({"mp3", "m4a", "wav", "amr", "mpga"})
DOCUMENT_EXTENSIONS = _with_case_variants(
{
"txt",
"markdown",
"md",
"mdx",
"pdf",
"html",
"htm",
"xlsx",
"xls",
"vtt",
"properties",
"doc",
"docx",
"csv",
"eml",
"msg",
"ppt",
"pptx",
"xml",
"epub",
}
)
def maybe_file_object(o: Any) -> bool:
return isinstance(o, dict) and o.get("dify_model_identity") == FILE_MODEL_IDENTITY