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: def cache_emoji(self, url: str, iri: str) -> None:
if self.is_emoji_cached(url): if self.is_emoji_cached(url):
return return
src, content_type = _load(url, self.user_agent) i = load(url, self.user_agent)
with BytesIO() as buf: for size in [25]:
with GzipFile(mode="wb", fileobj=buf) as g: t1 = i.copy()
copyfileobj(src, g) 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) buf.seek(0)
self.fs.put( self.fs.put(
buf, buf,
url=url, url=url,
size=size,
remote_id=iri, remote_id=iri,
size=None, content_type=i.get_format_mimetype(),
content_type=content_type or mimetypes.guess_type(url)[0],
kind=Kind.EMOJI.value, kind=Kind.EMOJI.value,
) )

View file

@ -99,7 +99,7 @@ def replace_custom_emojis(content, note):
for tag in note.get("tag", []): for tag in note.get("tag", []):
if tag.get("type") == "Emoji": if tag.get("type") == "Emoji":
# try: # 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(): for emoji_name, emoji_url in idx.items():
content = content.replace( content = content.replace(