dify/api/services/account_avatar_service.py

20 lines
720 B
Python

"""Application service for resolving a current account avatar URL."""
from machinery.context import RequestContext
from services.account_errors import AvatarFileNotFoundError
from services.account_ports import AccountAvatarFileGateway
class AccountAvatarService:
def __init__(self, *, files: AccountAvatarFileGateway) -> None:
self._files = files
def resolve(self, context: RequestContext, avatar: str) -> str:
if avatar.startswith(("http://", "https://")):
return avatar
avatar_url = self._files.get_owned_signed_url(account_id=context.account_id, upload_file_id=avatar)
if avatar_url is None:
raise AvatarFileNotFoundError
return avatar_url