mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
73 lines
1.8 KiB
Python
73 lines
1.8 KiB
Python
"""Framework-neutral values used by Notion import use cases."""
|
|
|
|
from collections.abc import Mapping
|
|
from dataclasses import dataclass
|
|
from enum import StrEnum
|
|
|
|
|
|
class NotionPageType(StrEnum):
|
|
PAGE = "page"
|
|
DATABASE = "database"
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class NotionPageIcon:
|
|
type: str | None = None
|
|
url: str | None = None
|
|
emoji: str | None = None
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class AuthorizedNotionPage:
|
|
page_id: str
|
|
page_name: str
|
|
page_icon: NotionPageIcon | None
|
|
parent_id: str | None
|
|
page_type: NotionPageType
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class NotionImportPage:
|
|
page_id: str
|
|
page_name: str
|
|
page_icon: NotionPageIcon | None
|
|
parent_id: str | None
|
|
page_type: NotionPageType
|
|
is_bound: bool
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class NotionWorkspace:
|
|
workspace_id: str | None
|
|
workspace_name: str | None
|
|
workspace_icon: str | None
|
|
pages: tuple[AuthorizedNotionPage, ...]
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class NotionImportWorkspace:
|
|
workspace_id: str | None
|
|
workspace_name: str | None
|
|
workspace_icon: str | None
|
|
pages: tuple[NotionImportPage, ...]
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class NotionImportResult:
|
|
workspaces: tuple[NotionImportWorkspace, ...]
|
|
|
|
|
|
def notion_page_icon(value: Mapping[str, object] | None) -> NotionPageIcon | None:
|
|
"""Map a plugin icon payload without leaking the plugin entity type."""
|
|
|
|
if value is None:
|
|
return None
|
|
icon_type = value.get("type")
|
|
url = value.get("url")
|
|
emoji = value.get("emoji")
|
|
return NotionPageIcon(
|
|
type=icon_type if isinstance(icon_type, str) else None,
|
|
url=url if isinstance(url, str) else None,
|
|
emoji=emoji if isinstance(emoji, str) else None,
|
|
)
|