Don't display inlined images twice
This commit is contained in:
parent
6395a75b6e
commit
342f708ce9
2 changed files with 22 additions and 2 deletions
|
@ -4,6 +4,7 @@ from functools import cached_property
|
|||
from typing import Any
|
||||
|
||||
import pydantic
|
||||
from bs4 import BeautifulSoup # type: ignore
|
||||
from markdown import markdown
|
||||
|
||||
from app import activitypub as ap
|
||||
|
@ -73,6 +74,23 @@ class Object:
|
|||
def tags(self) -> list[ap.RawObject]:
|
||||
return ap.as_list(self.ap_object.get("tag", []))
|
||||
|
||||
@cached_property
|
||||
def inlined_images(self) -> set[str]:
|
||||
image_urls: set[str] = set()
|
||||
if not self.content:
|
||||
return image_urls
|
||||
|
||||
soup = BeautifulSoup(self.content, "html5lib")
|
||||
imgs = soup.find_all("img")
|
||||
|
||||
for img in imgs:
|
||||
if not img.attrs.get("src"):
|
||||
continue
|
||||
|
||||
image_urls.add(img.attrs["src"])
|
||||
|
||||
return image_urls
|
||||
|
||||
@cached_property
|
||||
def attachments(self) -> list["Attachment"]:
|
||||
attachments = []
|
||||
|
@ -97,7 +115,7 @@ class Object:
|
|||
{
|
||||
"proxiedUrl": proxied_url,
|
||||
"resizedUrl": proxied_url + "/740"
|
||||
if obj["mediaType"].startswith("image")
|
||||
if obj.get("mediaType", "").startswith("image")
|
||||
else None,
|
||||
**obj,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue