Files
gsfdc/demo-dify/dify/api/factories/file_factory/common.py
T
wuzilongandCursor 6519682885 chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 13:59:25 +08:00

28 lines
1.0 KiB
Python

"""Shared helpers for workflow file factory modules."""
from __future__ import annotations
from collections.abc import Mapping
from typing import Any
from core.workflow.file_reference import resolve_file_record_id
def resolve_mapping_file_id(mapping: Mapping[str, Any], *keys: str) -> str | None:
"""Resolve historical file identifiers from persisted mapping payloads.
Workflow and model payloads can outlive file schema changes. Older rows may
still carry concrete identifiers in legacy fields such as ``related_id``,
while newer payloads use opaque references. Keep this compatibility lookup in
the factory layer so historical data remains readable without reintroducing
storage details into graph-layer ``File`` values.
"""
for key in (*keys, "reference", "related_id"):
raw_value = mapping.get(key)
if isinstance(raw_value, str) and raw_value:
resolved_value = resolve_file_record_id(raw_value)
if resolved_value:
return resolved_value
return None