Improve/fix non-media attachment display

This commit is contained in:
Thomas Sileo 2022-09-30 09:07:07 +02:00
parent 58b383ba4e
commit cf6a891349
2 changed files with 17 additions and 3 deletions

View file

@ -1,4 +1,5 @@
import hashlib
import mimetypes
from datetime import datetime
from functools import cached_property
from typing import Any
@ -276,6 +277,17 @@ class Attachment(BaseModel):
proxied_url: str | None = None
resized_url: str | None = None
@property
def mimetype(self) -> str:
mimetype = self.media_type
if not mimetype:
mimetype, _ = mimetypes.guess_type(self.url)
if not mimetype:
return "unknown"
return mimetype.split("/")[-1]
class RemoteObject(Object):
def __init__(self, raw_object: ap.RawObject, actor: Actor):