Guess emoji mimetype if not provided in tag (#298)
This commit is contained in:
parent
efe6864418
commit
26f64bfc06
|
@ -1,3 +1,4 @@
|
||||||
|
import mimetypes
|
||||||
import re
|
import re
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import ClassVar
|
from typing import ClassVar
|
||||||
|
@ -225,16 +226,23 @@ class Emoji(StatorModel):
|
||||||
else:
|
else:
|
||||||
raise ValueError("No name on emoji JSON")
|
raise ValueError("No name on emoji JSON")
|
||||||
|
|
||||||
|
icon = data["icon"]
|
||||||
|
|
||||||
|
mimetype = icon.get("mediaType")
|
||||||
|
if not mimetype:
|
||||||
|
mimetype, _ = mimetypes.guess_type(icon["url"])
|
||||||
|
if mimetype is None:
|
||||||
|
raise ValueError("No mimetype on emoji JSON")
|
||||||
|
|
||||||
# create
|
# create
|
||||||
shortcode = name.lower().strip(":")
|
shortcode = name.lower().strip(":")
|
||||||
icon = data["icon"]
|
|
||||||
category = (icon.get("category") or "")[:100]
|
category = (icon.get("category") or "")[:100]
|
||||||
emoji = cls.objects.create(
|
emoji = cls.objects.create(
|
||||||
shortcode=shortcode,
|
shortcode=shortcode,
|
||||||
domain=None if domain.local else domain,
|
domain=None if domain.local else domain,
|
||||||
local=domain.local,
|
local=domain.local,
|
||||||
object_uri=data["id"],
|
object_uri=data["id"],
|
||||||
mimetype=icon["mediaType"],
|
mimetype=mimetype,
|
||||||
category=category,
|
category=category,
|
||||||
remote_url=icon["url"],
|
remote_url=icon["url"],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue