diff --git a/templates/twitch/dashboard.html b/templates/twitch/dashboard.html index 2f672a7..405bb29 100644 --- a/templates/twitch/dashboard.html +++ b/templates/twitch/dashboard.html @@ -5,35 +5,64 @@ {% endblock title %} {% block content %}
+

Twitch Drops Dashboard

+

Track active campaigns and upcoming drops

{% if campaigns_by_org_game %} {% for org_id, org_data in campaigns_by_org_game.items %} - {% for game_id, game_data in org_data.games.items %} -
-
-

- {{ game_data.name }} -

-
-
- {% for campaign in game_data.campaigns %} -
- - Image for {{ campaign.name }} - -

{{ campaign.clean_name }}

- -
- {% endfor %} -
-
- {% endfor %} +
+

+ {% if org_data.name %} + {{ org_data.name }} + {% else %} + Organization {{ org_id }} + {% endif %} +

+ {% for game_id, game_data in org_data.games.items %} + + {% endfor %} +
{% endfor %} {% else %}

No active campaigns at the moment.

diff --git a/twitch/models.py b/twitch/models.py index 2059b89..a6926e6 100644 --- a/twitch/models.py +++ b/twitch/models.py @@ -1,6 +1,7 @@ from __future__ import annotations import logging +import re from typing import TYPE_CHECKING, ClassVar from django.db import models @@ -47,6 +48,23 @@ class Game(models.Model): """Return all organizations that have drop campaigns for this game.""" return Organization.objects.filter(drop_campaigns__game=self).distinct() + @property + def box_art_base_url(self) -> str: + """Return the base box art URL without size suffix. + + Twitch box art URLs often include size suffixes like '-120x160.jpg'. + This property returns the base URL without the size suffix. + + Examples: + 'https://static-cdn.jtvnw.net/ttv-boxart/512710-120x160.jpg' + -> 'https://static-cdn.jtvnw.net/ttv-boxart/512710.jpg' + """ + if not self.box_art: + return "" + + # Remove size suffix pattern like '-120x160' from the filename + return re.sub(r"-\d+x\d+(\.jpg|\.png|\.jpeg|\.gif|\.webp)$", r"\1", self.box_art) + class Organization(models.Model): """Represents an organization on Twitch that can own drop campaigns.""" diff --git a/twitch/views.py b/twitch/views.py index e0dc409..321fdc3 100644 --- a/twitch/views.py +++ b/twitch/views.py @@ -337,6 +337,7 @@ def dashboard(request: HttpRequest) -> HttpResponse: if game_id not in campaigns_by_org_game[org_id]["games"]: campaigns_by_org_game[org_id]["games"][game_id] = { "name": game_name, + "box_art": campaign.game.box_art_base_url, "campaigns": [], }