Fix types

This commit is contained in:
Joakim Hellsén 2026-03-16 18:40:04 +01:00
commit c092d3089f
Signed by: Joakim Hellsén
SSH key fingerprint: SHA256:/9h/CsExpFp+PRhsfA0xznFx2CGfTT5R/kpuFfUgEQk
13 changed files with 48 additions and 18 deletions

View file

@ -264,7 +264,7 @@ class Command(BaseCommand):
client: httpx.Client,
image_url: str,
twitch_id: str,
file_field: FieldFile,
file_field: FieldFile | None,
) -> str:
"""Download a single image and save it to the file field.
@ -281,6 +281,9 @@ class Command(BaseCommand):
suffix: str = Path(parsed_url.path).suffix or ".jpg"
file_name: str = f"{twitch_id}{suffix}"
if file_field is None:
return "failed"
try:
response: httpx.Response = client.get(image_url)
response.raise_for_status()
@ -299,7 +302,9 @@ class Command(BaseCommand):
file_field.save(file_name, ContentFile(response.content), save=True)
# Auto-convert to WebP and AVIF
self._convert_to_modern_formats(file_field.path)
image_path: str | None = getattr(file_field, "path", None)
if image_path:
self._convert_to_modern_formats(image_path)
return "downloaded"