Fix emoji caching

This commit is contained in:
Thomas Sileo 2019-08-21 00:28:24 +02:00
parent 6d0d1d6480
commit 6592841558
2 changed files with 10 additions and 7 deletions

View file

@ -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)
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 g:
copyfileobj(src, g)
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,
)

View file

@ -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(