actually use the abstracted type not just the id

This commit is contained in:
Moon 2025-06-12 11:10:18 +09:00
parent 2468ffa1f3
commit f4499f7afb
3 changed files with 7 additions and 7 deletions

View file

@ -1,6 +1,6 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import List, Optional, Union, BinaryIO from typing import List, Optional, Union, BinaryIO
from fediverse_types import FediverseNotification, FediversePost, Visibility from fediverse_types import FediverseNotification, FediversePost, FediverseFile, Visibility
class FediverseService(ABC): class FediverseService(ABC):
@ -57,7 +57,7 @@ class FediverseService(ABC):
pass pass
@abstractmethod @abstractmethod
def upload_file(self, file_data: Union[BinaryIO, bytes], filename: Optional[str] = None) -> str: def upload_file(self, file_data: Union[BinaryIO, bytes], filename: Optional[str] = None) -> FediverseFile:
""" """
Upload a file to the Fediverse instance. Upload a file to the Fediverse instance.
@ -66,7 +66,7 @@ class FediverseService(ABC):
filename: Optional filename for the uploaded file filename: Optional filename for the uploaded file
Returns: Returns:
File ID that can be used in posts FediverseFile object with ID, URL, and other metadata
Raises: Raises:
RuntimeError: If file upload fails RuntimeError: If file upload fails

View file

@ -140,13 +140,13 @@ class MisskeyService(FediverseService):
except Exception: except Exception:
return None return None
def upload_file(self, file_data: Union[BinaryIO, bytes], filename: Optional[str] = None) -> str: def upload_file(self, file_data: Union[BinaryIO, bytes], filename: Optional[str] = None) -> FediverseFile:
"""Upload a file to Misskey Drive""" """Upload a file to Misskey Drive"""
try: try:
from misskey.exceptions import MisskeyAPIException from misskey.exceptions import MisskeyAPIException
media = self.client.drive_files_create(file_data) media = self.client.drive_files_create(file_data)
return media["id"] return self._convert_misskey_file(media)
except MisskeyAPIException as e: except MisskeyAPIException as e:
raise RuntimeError(f"Failed to upload file to Misskey Drive: {e}") from e raise RuntimeError(f"Failed to upload file to Misskey Drive: {e}") from e
except Exception as e: except Exception as e:

View file

@ -154,10 +154,10 @@ class PleromaService(FediverseService):
except Exception: except Exception:
return None return None
def upload_file(self, file_data: Union[BinaryIO, bytes], filename: Optional[str] = None) -> str: def upload_file(self, file_data: Union[BinaryIO, bytes], filename: Optional[str] = None) -> FediverseFile:
"""Upload a file to Pleroma instance""" """Upload a file to Pleroma instance"""
try: try:
media = self.client.media_post(file_data, mime_type=None, description=filename) media = self.client.media_post(file_data, mime_type=None, description=filename)
return str(media["id"]) return self._convert_mastodon_file(media)
except Exception as e: except Exception as e:
raise RuntimeError(f"Failed to upload file to Pleroma: {e}") from e raise RuntimeError(f"Failed to upload file to Pleroma: {e}") from e