More work for cleaning up old activities
This commit is contained in:
@@ -60,6 +60,25 @@ class MediaCache(object):
|
||||
kind=Kind.OG_IMAGE.value,
|
||||
)
|
||||
|
||||
def cache_og_image2(self, url: str, remote_id: str) -> None:
|
||||
if self.fs.find_one({"url": url, "kind": Kind.OG_IMAGE.value}):
|
||||
return
|
||||
i = load(url, self.user_agent)
|
||||
# Save the original attachment (gzipped)
|
||||
i.thumbnail((100, 100))
|
||||
with BytesIO() as buf:
|
||||
with GzipFile(mode="wb", fileobj=buf) as f1:
|
||||
i.save(f1, format=i.format)
|
||||
buf.seek(0)
|
||||
self.fs.put(
|
||||
buf,
|
||||
url=url,
|
||||
size=100,
|
||||
content_type=i.get_format_mimetype(),
|
||||
kind=Kind.OG_IMAGE.value,
|
||||
remote_id=remote_id,
|
||||
)
|
||||
|
||||
def cache_attachment(self, url: str) -> None:
|
||||
if self.fs.find_one({"url": url, "kind": Kind.ATTACHMENT.value}):
|
||||
return
|
||||
@@ -98,6 +117,46 @@ class MediaCache(object):
|
||||
)
|
||||
return
|
||||
|
||||
def cache_attachment2(self, url: str, remote_id: str) -> None:
|
||||
if self.fs.find_one({"url": url, "kind": Kind.ATTACHMENT.value}):
|
||||
return
|
||||
if (
|
||||
url.endswith(".png")
|
||||
or url.endswith(".jpg")
|
||||
or url.endswith(".jpeg")
|
||||
or url.endswith(".gif")
|
||||
):
|
||||
i = load(url, self.user_agent)
|
||||
# Save the original attachment (gzipped)
|
||||
with BytesIO() as buf:
|
||||
f1 = GzipFile(mode="wb", fileobj=buf)
|
||||
i.save(f1, format=i.format)
|
||||
f1.close()
|
||||
buf.seek(0)
|
||||
self.fs.put(
|
||||
buf,
|
||||
url=url,
|
||||
size=None,
|
||||
content_type=i.get_format_mimetype(),
|
||||
kind=Kind.ATTACHMENT.value,
|
||||
remote_id=remote_id,
|
||||
)
|
||||
# Save a thumbnail (gzipped)
|
||||
i.thumbnail((720, 720))
|
||||
with BytesIO() as buf:
|
||||
with GzipFile(mode="wb", fileobj=buf) as f1:
|
||||
i.save(f1, format=i.format)
|
||||
buf.seek(0)
|
||||
self.fs.put(
|
||||
buf,
|
||||
url=url,
|
||||
size=720,
|
||||
content_type=i.get_format_mimetype(),
|
||||
kind=Kind.ATTACHMENT.value,
|
||||
remote_id=remote_id,
|
||||
)
|
||||
return
|
||||
|
||||
# The attachment is not an image, download and save it anyway
|
||||
with requests.get(
|
||||
url, stream=True, headers={"User-Agent": self.user_agent}
|
||||
@@ -115,6 +174,7 @@ class MediaCache(object):
|
||||
size=None,
|
||||
content_type=mimetypes.guess_type(url)[0],
|
||||
kind=Kind.ATTACHMENT.value,
|
||||
remote_id=remote_id,
|
||||
)
|
||||
|
||||
def cache_actor_icon(self, url: str) -> None:
|
||||
|
Reference in New Issue
Block a user