Add Steam library import via OpenID
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

- Steam OpenID flow: user authenticates with Steam, we get their Steam ID
- Server-side API key fetches their owned games with playtime
- Import page shows full library, marks already-imported games
- Imported games land in backlog as GAMES items with hours_played set
- STEAM_API_KEY env var plumbed into both prod and dev containers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-31 22:38:28 +03:00
parent 8f34d9388f
commit a4c31bf40b
6 changed files with 382 additions and 1 deletions

View File

@@ -164,7 +164,13 @@
<div class="container">
<div class="top-bar">
<h1>Backlogger <span class="count">{{ items|length }}</span></h1>
<a href="{% url 'backlogger:add' %}" class="btn btn-primary">+ Add item</a>
<div style="display:flex;gap:0.5rem;align-items:center">
{% if request.GET.imported %}
<span style="font-size:0.82rem;color:#34d399">&#10003; {{ request.GET.imported }} game{{ request.GET.imported|pluralize }} imported</span>
{% endif %}
<a href="{% url 'backlogger:steam_login' %}" class="btn btn-outline" style="font-size:0.82rem">&#9654; Steam</a>
<a href="{% url 'backlogger:add' %}" class="btn btn-primary">+ Add item</a>
</div>
</div>
<div class="filter-bar">

View File

@@ -0,0 +1,248 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Import from Steam — Backlogger</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: #0f172a;
color: #e2e8f0;
min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
.site-header {
background: #0a0f1e;
border-bottom: 1px solid #1e293b;
padding: 0.75rem 2rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.site-header .brand { color: #38bdf8; font-weight: 600; font-size: 0.95rem; }
.site-header nav a { color: #64748b; font-size: 0.85rem; }
.site-header nav a:hover { color: #e2e8f0; }
.container { max-width: 860px; margin: 0 auto; padding: 2rem; }
.top-bar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.75rem;
}
.top-bar h1 { font-size: 1.5rem; letter-spacing: -0.03em; }
.top-bar .count { color: #64748b; font-size: 1rem; font-weight: 400; margin-left: 0.5rem; }
.error-banner {
background: #450a0a;
border: 1px solid #f87171;
border-radius: 8px;
color: #fca5a5;
padding: 0.85rem 1.1rem;
margin-bottom: 1.5rem;
}
.toolbar {
display: flex;
gap: 0.75rem;
align-items: center;
margin-bottom: 1rem;
}
.btn {
display: inline-block;
padding: 0.45rem 1rem;
border-radius: 6px;
font-size: 0.85rem;
cursor: pointer;
border: none;
transition: opacity 0.15s;
font-family: inherit;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: #38bdf8; color: #0f172a; font-weight: 600; }
.btn-outline { background: transparent; color: #94a3b8; border: 1px solid #334155; }
.btn-text { background: none; border: none; color: #64748b; font-size: 0.8rem; cursor: pointer; font-family: inherit; padding: 0; }
.btn-text:hover { color: #e2e8f0; }
.game-table {
width: 100%;
border-collapse: collapse;
}
.game-table thead th {
text-align: left;
font-size: 0.72rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: #475569;
padding: 0 0.75rem 0.6rem;
border-bottom: 1px solid #1e293b;
}
.game-table thead th:first-child { padding-left: 0; width: 2rem; }
.game-table tbody tr {
border-bottom: 1px solid #1a2235;
transition: background 0.1s;
}
.game-table tbody tr:hover:not(.already-imported) { background: #0d1526; }
.game-table td {
padding: 0.6rem 0.75rem;
font-size: 0.88rem;
}
.game-table td:first-child { padding-left: 0; }
.already-imported td { opacity: 0.38; }
.already-imported .tag {
font-size: 0.68rem;
color: #475569;
border: 1px solid #1e293b;
border-radius: 4px;
padding: 0.1rem 0.4rem;
margin-left: 0.5rem;
vertical-align: middle;
}
.hours { color: #38bdf8; font-variant-numeric: tabular-nums; }
.hours-zero { color: #334155; }
input[type="checkbox"] { accent-color: #38bdf8; width: 1rem; height: 1rem; cursor: pointer; }
.sticky-footer {
position: sticky;
bottom: 0;
background: #0a0f1e;
border-top: 1px solid #1e293b;
padding: 1rem 2rem;
display: flex;
align-items: center;
gap: 1.25rem;
}
.sticky-footer .summary { font-size: 0.85rem; color: #64748b; }
.sticky-footer .summary strong { color: #e2e8f0; }
.empty { text-align: center; padding: 4rem 2rem; color: #475569; }
.steam-btn {
display: inline-flex;
align-items: center;
gap: 0.6rem;
background: #1b2838;
border: 1px solid #2a475e;
color: #c7d5e0;
font-weight: 600;
border-radius: 6px;
padding: 0.6rem 1.1rem;
font-size: 0.9rem;
cursor: pointer;
text-decoration: none;
transition: background 0.15s;
}
.steam-btn:hover { background: #2a475e; }
.steam-logo { width: 20px; height: 20px; }
</style>
</head>
<body>
<header class="site-header">
<a class="brand" href="/">killmybacklog.com</a>
<nav><a href="{% url 'backlogger:list' %}">← Back to backlog</a></nav>
</header>
<div class="container">
{% if error %}
<div class="error-banner">{{ error }}</div>
<div class="empty">
<p style="margin-bottom:1.25rem">Want to try again?</p>
<a href="{% url 'backlogger:steam_login' %}" class="steam-btn">
<svg class="steam-logo" viewBox="0 0 233 233" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M116.5 0C52.1 0 0 52.1 0 116.5c0 55.4 38.6 101.8 90.4 113.7l34.2-84.2c-1.2.1-2.4.1-3.6.1-22.1 0-40-17.9-40-40s17.9-40 40-40 40 17.9 40 40c0 19.1-13.4 35.1-31.4 39l-33.8 83.3C147.5 222 185 179.5 185 128c0-1.6-.1-3.1-.2-4.7l-31.5-13c.4 2.2.7 4.5.7 6.8 0 19.9-16.1 36-36 36s-36-16.1-36-36 16.1-36 36-36 36 16.1 36 36" fill="#c7d5e0"/>
</svg>
Connect with Steam
</a>
</div>
{% elif games %}
<div class="top-bar">
<h1>Import from Steam <span class="count">{{ games|length }} games</span></h1>
</div>
<form method="post" action="{% url 'backlogger:steam_import' %}">
{% csrf_token %}
<div class="toolbar">
<button type="submit" class="btn btn-primary">Import selected</button>
<button type="button" class="btn-text" onclick="toggleAll(true)">Select all</button>
<button type="button" class="btn-text" onclick="toggleAll(false)">Deselect all</button>
</div>
<table class="game-table">
<thead>
<tr>
<th></th>
<th>Game</th>
<th>Hours played</th>
</tr>
</thead>
<tbody>
{% for game in games %}
<tr class="{% if game.already_imported %}already-imported{% endif %}">
<td>
{% if game.already_imported %}
<input type="checkbox" disabled>
{% else %}
<input type="checkbox" name="appids" value="{{ game.appid }}" checked>
{% endif %}
</td>
<td>
{{ game.name }}
{% if game.already_imported %}<span class="tag">already in backlog</span>{% endif %}
</td>
<td class="{% if game.hours == 0 %}hours-zero{% else %}hours{% endif %}">
{{ game.hours }}h
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="sticky-footer">
<button type="submit" class="btn btn-primary">Import selected</button>
<span class="summary">
<strong id="sel-count">{{ games|length }}</strong> selected
</span>
<a href="{% url 'backlogger:list' %}" class="btn btn-outline">Cancel</a>
</div>
</form>
{% else %}
<div class="top-bar"><h1>Import from Steam</h1></div>
<div class="empty">
<p style="margin-bottom:1.25rem; color:#64748b">Connect your Steam account to import your library.</p>
<a href="{% url 'backlogger:steam_login' %}" class="steam-btn">
<svg class="steam-logo" viewBox="0 0 233 233" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M116.5 0C52.1 0 0 52.1 0 116.5c0 55.4 38.6 101.8 90.4 113.7l34.2-84.2c-1.2.1-2.4.1-3.6.1-22.1 0-40-17.9-40-40s17.9-40 40-40 40 17.9 40 40c0 19.1-13.4 35.1-31.4 39l-33.8 83.3C147.5 222 185 179.5 185 128c0-1.6-.1-3.1-.2-4.7l-31.5-13c.4 2.2.7 4.5.7 6.8 0 19.9-16.1 36-36 36s-36-16.1-36-36 16.1-36 36-36 36 16.1 36 36" fill="#c7d5e0"/>
</svg>
Connect with Steam
</a>
</div>
{% endif %}
</div>
<script>
function toggleAll(check) {
document.querySelectorAll('input[name="appids"]').forEach(cb => cb.checked = check);
updateCount();
}
function updateCount() {
const n = document.querySelectorAll('input[name="appids"]:checked').length;
const el = document.getElementById('sel-count');
if (el) el.textContent = n;
}
document.querySelectorAll('input[name="appids"]').forEach(cb => cb.addEventListener('change', updateCount));
updateCount();
</script>
</body>
</html>