pleroma-support #56
3 changed files with 7 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
Loading…
Add table
Reference in a new issue