From 6592841558be714598052d3c9fbca4dfe320a74f Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Wed, 21 Aug 2019 00:28:24 +0200 Subject: [PATCH] Fix emoji caching --- utils/media.py | 15 +++++++++------ utils/template_filters.py | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/utils/media.py b/utils/media.py index 9b0cb81..789c668 100644 --- a/utils/media.py +++ b/utils/media.py @@ -196,17 +196,20 @@ class MediaCache(object): def cache_emoji(self, url: str, iri: str) -> None: if self.is_emoji_cached(url): return - src, content_type = _load(url, self.user_agent) - with BytesIO() as buf: - with GzipFile(mode="wb", fileobj=buf) as g: - copyfileobj(src, g) + i = load(url, self.user_agent) + for size in [25]: + t1 = i.copy() + t1.thumbnail((size, size)) + with BytesIO() as buf: + with GzipFile(mode="wb", fileobj=buf) as f1: + t1.save(f1, format=i.format) buf.seek(0) self.fs.put( buf, url=url, + size=size, remote_id=iri, - size=None, - content_type=content_type or mimetypes.guess_type(url)[0], + content_type=i.get_format_mimetype(), kind=Kind.EMOJI.value, ) diff --git a/utils/template_filters.py b/utils/template_filters.py index 93f3b88..11987d1 100644 --- a/utils/template_filters.py +++ b/utils/template_filters.py @@ -99,7 +99,7 @@ def replace_custom_emojis(content, note): for tag in note.get("tag", []): if tag.get("type") == "Emoji": # try: - idx[tag["name"]] = _get_file_url(tag["icon"]["url"], None, Kind.EMOJI) + idx[tag["name"]] = _get_file_url(tag["icon"]["url"], 25, Kind.EMOJI) for emoji_name, emoji_url in idx.items(): content = content.replace(