Handle timeouts on image fetch
This commit is contained in:
parent
64f113dd8d
commit
d08324e159
|
@ -2,6 +2,7 @@ import re
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import ClassVar, cast
|
from typing import ClassVar, cast
|
||||||
|
|
||||||
|
import httpx
|
||||||
import urlman
|
import urlman
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -30,11 +31,14 @@ class EmojiStates(StateGraph):
|
||||||
Fetches remote emoji and uploads to file for local caching
|
Fetches remote emoji and uploads to file for local caching
|
||||||
"""
|
"""
|
||||||
if instance.remote_url and not instance.file:
|
if instance.remote_url and not instance.file:
|
||||||
file, mimetype = await get_remote_file(
|
try:
|
||||||
instance.remote_url,
|
file, mimetype = await get_remote_file(
|
||||||
timeout=settings.SETUP.REMOTE_TIMEOUT,
|
instance.remote_url,
|
||||||
max_size=settings.SETUP.EMOJI_MAX_IMAGE_FILESIZE_KB * 1024,
|
timeout=settings.SETUP.REMOTE_TIMEOUT,
|
||||||
)
|
max_size=settings.SETUP.EMOJI_MAX_IMAGE_FILESIZE_KB * 1024,
|
||||||
|
)
|
||||||
|
except httpx.RequestError:
|
||||||
|
return
|
||||||
if file:
|
if file:
|
||||||
instance.file = file
|
instance.file = file
|
||||||
instance.mimetype = mimetype
|
instance.mimetype = mimetype
|
||||||
|
|
|
@ -46,11 +46,15 @@ class IdentityStates(StateGraph):
|
||||||
if await identity.fetch_actor():
|
if await identity.fetch_actor():
|
||||||
# Also stash their icon if we can
|
# Also stash their icon if we can
|
||||||
if identity.icon_uri:
|
if identity.icon_uri:
|
||||||
file, mimetype = await get_remote_file(
|
try:
|
||||||
identity.icon_uri,
|
file, mimetype = await get_remote_file(
|
||||||
timeout=settings.SETUP.REMOTE_TIMEOUT,
|
identity.icon_uri,
|
||||||
max_size=settings.SETUP.AVATAR_MAX_IMAGE_FILESIZE_KB * 1024,
|
timeout=settings.SETUP.REMOTE_TIMEOUT,
|
||||||
)
|
max_size=settings.SETUP.AVATAR_MAX_IMAGE_FILESIZE_KB * 1024,
|
||||||
|
)
|
||||||
|
except httpx.RequestError:
|
||||||
|
# We've still got enough info to consider ourselves updated
|
||||||
|
return cls.updated
|
||||||
if file:
|
if file:
|
||||||
identity.icon = file
|
identity.icon = file
|
||||||
await sync_to_async(identity.save)()
|
await sync_to_async(identity.save)()
|
||||||
|
|
Loading…
Reference in New Issue