mirror of
https://github.com/langgenius/dify.git
synced 2026-01-06 06:26:00 +00:00
feat: add display status filtering to document list and API (#28342)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
This commit is contained in:
@@ -1082,6 +1082,62 @@ class DocumentService:
|
||||
},
|
||||
}
|
||||
|
||||
DISPLAY_STATUS_ALIASES: dict[str, str] = {
|
||||
"active": "available",
|
||||
"enabled": "available",
|
||||
}
|
||||
|
||||
_INDEXING_STATUSES: tuple[str, ...] = ("parsing", "cleaning", "splitting", "indexing")
|
||||
|
||||
DISPLAY_STATUS_FILTERS: dict[str, tuple[Any, ...]] = {
|
||||
"queuing": (Document.indexing_status == "waiting",),
|
||||
"indexing": (
|
||||
Document.indexing_status.in_(_INDEXING_STATUSES),
|
||||
Document.is_paused.is_not(True),
|
||||
),
|
||||
"paused": (
|
||||
Document.indexing_status.in_(_INDEXING_STATUSES),
|
||||
Document.is_paused.is_(True),
|
||||
),
|
||||
"error": (Document.indexing_status == "error",),
|
||||
"available": (
|
||||
Document.indexing_status == "completed",
|
||||
Document.archived.is_(False),
|
||||
Document.enabled.is_(True),
|
||||
),
|
||||
"disabled": (
|
||||
Document.indexing_status == "completed",
|
||||
Document.archived.is_(False),
|
||||
Document.enabled.is_(False),
|
||||
),
|
||||
"archived": (
|
||||
Document.indexing_status == "completed",
|
||||
Document.archived.is_(True),
|
||||
),
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def normalize_display_status(cls, status: str | None) -> str | None:
|
||||
if not status:
|
||||
return None
|
||||
normalized = status.lower()
|
||||
normalized = cls.DISPLAY_STATUS_ALIASES.get(normalized, normalized)
|
||||
return normalized if normalized in cls.DISPLAY_STATUS_FILTERS else None
|
||||
|
||||
@classmethod
|
||||
def build_display_status_filters(cls, status: str | None) -> tuple[Any, ...]:
|
||||
normalized = cls.normalize_display_status(status)
|
||||
if not normalized:
|
||||
return ()
|
||||
return cls.DISPLAY_STATUS_FILTERS[normalized]
|
||||
|
||||
@classmethod
|
||||
def apply_display_status_filter(cls, query, status: str | None):
|
||||
filters = cls.build_display_status_filters(status)
|
||||
if not filters:
|
||||
return query
|
||||
return query.where(*filters)
|
||||
|
||||
DOCUMENT_METADATA_SCHEMA: dict[str, Any] = {
|
||||
"book": {
|
||||
"title": str,
|
||||
|
||||
Reference in New Issue
Block a user