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 typing import List, Optional, Union, BinaryIO
from fediverse_types import FediverseNotification, FediversePost, Visibility
from fediverse_types import FediverseNotification, FediversePost, FediverseFile, Visibility
class FediverseService(ABC):
@ -57,7 +57,7 @@ class FediverseService(ABC):
pass
@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.
@ -66,7 +66,7 @@ class FediverseService(ABC):
filename: Optional filename for the uploaded file
Returns:
File ID that can be used in posts
FediverseFile object with ID, URL, and other metadata
Raises:
RuntimeError: If file upload fails

View file

@ -140,13 +140,13 @@ class MisskeyService(FediverseService):
except Exception:
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"""
try:
from misskey.exceptions import MisskeyAPIException
media = self.client.drive_files_create(file_data)
return media["id"]
return self._convert_misskey_file(media)
except MisskeyAPIException as e:
raise RuntimeError(f"Failed to upload file to Misskey Drive: {e}") from e
except Exception as e:

View file

@ -154,10 +154,10 @@ class PleromaService(FediverseService):
except Exception:
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"""
try:
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:
raise RuntimeError(f"Failed to upload file to Pleroma: {e}") from e