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

@ -631,6 +631,9 @@ class Command(BaseCommand):
)
return
if game_obj.box_art_file is None:
return
game_obj.box_art_file.save(file_name, ContentFile(response.content), save=True)
def _get_or_create_channel(self, channel_info: ChannelInfoSchema) -> Channel:

View file

@ -11,8 +11,8 @@ from twitch.models import Game
from twitch.models import Organization
if TYPE_CHECKING:
from debug_toolbar.panels.templates.panel import QuerySet
from django.core.management.base import CommandParser
from django.db.models import QuerySet
class Command(BaseCommand):

View file

@ -38,7 +38,7 @@ class Command(BaseCommand):
help="Re-download even if a local box art file already exists.",
)
def handle(self, *_args: object, **options: object) -> None:
def handle(self, *_args: object, **options: object) -> None: # noqa: PLR0914
"""Download Twitch box art images for all games."""
limit_value: object | None = options.get("limit")
limit: int | None = limit_value if isinstance(limit_value, int) else None
@ -92,6 +92,10 @@ class Command(BaseCommand):
skipped += 1
continue
if game.box_art_file is None:
failed += 1
continue
game.box_art_file.save(
file_name,
ContentFile(response.content),
@ -99,7 +103,9 @@ class Command(BaseCommand):
)
# Auto-convert to WebP and AVIF
self._convert_to_modern_formats(game.box_art_file.path)
box_art_path: str | None = getattr(game.box_art_file, "path", None)
if box_art_path:
self._convert_to_modern_formats(box_art_path)
downloaded += 1

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"