From f4499f7afbf4e44cb20bac323a1183613a320913 Mon Sep 17 00:00:00 2001 From: Moon Date: Thu, 12 Jun 2025 11:10:18 +0900 Subject: [PATCH] actually use the abstracted type not just the id --- bot/fediverse_service.py | 6 +++--- bot/misskey_service.py | 4 ++-- bot/pleroma_service.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bot/fediverse_service.py b/bot/fediverse_service.py index d4e32fe..1292d63 100644 --- a/bot/fediverse_service.py +++ b/bot/fediverse_service.py @@ -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 diff --git a/bot/misskey_service.py b/bot/misskey_service.py index e8bd396..3a16cd4 100644 --- a/bot/misskey_service.py +++ b/bot/misskey_service.py @@ -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: diff --git a/bot/pleroma_service.py b/bot/pleroma_service.py index 7333df0..753b1dc 100644 --- a/bot/pleroma_service.py +++ b/bot/pleroma_service.py @@ -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 \ No newline at end of file