feat: add cover proxy endpoint and progress bar to dashboard

- Add /api/cover/<library_item_id> endpoint to proxy cover images from ABS
- Return cover proxy URL instead of direct ABS URL to avoid CORS issues
- Add visual progress bar to audiobook card
- Add cache-busting timestamp to cover image URLs
- Improve cover image error handling with fallback placeholder

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
wralto-user-1
2026-11-02 23:02:07 +01:00
parent f4fe00d15b
commit 031e5b7b03
2 changed files with 109 additions and 42 deletions

View File

@ -137,15 +137,16 @@
/* Cover Image Styles */
.cover-container {
text-align: center;
margin-bottom: 0.75rem;
}
.cover-image {
max-width: 100%;
max-height: 200px;
max-height: 180px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
object-fit: contain;
background: rgba(0, 0, 0, 0.2);
background: rgba(0, 0, 0, 0.3);
}
.cover-placeholder {
@ -158,11 +159,27 @@
align-items: center;
justify-content: center;
color: #666;
font-size: 1.5rem;
font-size: 3rem;
}
.audiobook-info {
text-align: center;
}
.progress-bar-container {
width: 100%;
background: rgba(255, 255, 255, 0.1);
border-radius: 4px;
height: 6px;
margin-top: 0.75rem;
overflow: hidden;
}
.progress-bar {
height: 100%;
background: linear-gradient(90deg, #4f46e5, #7c3aed);
border-radius: 4px;
transition: width 0.3s ease;
}
</style>
</head>
@ -291,34 +308,40 @@
let html = '';
// Always show cover placeholder or image
html += '<div class="cover-container">';
if (coverUrl) {
html = `
<div class="cover-container">
<img src="${coverUrl}" alt="${title}" class="cover-image"
onerror="this.style.display='none'; document.getElementById('cover-fallback-${Date.now()}').style.display='block';">
<div id="cover-fallback-${Date.now()}" class="cover-placeholder" style="display: none;">
${mediaIcon}
</div>
</div>
<div class="audiobook-info">
<div class="card-value" style="font-size: 1.25rem; margin-top: 0.5rem;">${title}</div>
${author ? `<div class="card-subvalue">von ${author}</div>` : ''}
<div class="card-subvalue">${progressPercent}% (${currentTime}/${duration})</div>
</div>
// Add timestamp to prevent caching
const coverUrlWithCache = coverUrl.includes('?')
? `${coverUrl}&t=${Date.now()}`
: `${coverUrl}?t=${Date.now()}`;
html += `
<img src="${coverUrlWithCache}" alt="${title}" class="cover-image"
onerror="this.style.display='none'; this.nextElementSibling.style.display='block';">
<div class="cover-placeholder" style="display: none;">${mediaIcon}</div>
`;
} else {
html = `
<div class="cover-container">
<div class="cover-placeholder">${mediaIcon}</div>
</div>
<div class="audiobook-info">
<div class="card-value" style="font-size: 1.25rem; margin-top: 0.5rem;">${title}</div>
${author ? `<div class="card-subvalue">von ${author}</div>` : ''}
<div class="card-subvalue">${progressPercent}% (${currentTime}/${duration})</div>
</div>
`;
html += `<div class="cover-placeholder">${mediaIcon}</div>`;
}
html += '</div>';
html += '<div class="audiobook-info">';
html += `<div class="card-value" style="font-size: 1.25rem; margin-top: 0.5rem;">${title}</div>`;
if (author) {
html += `<div class="card-subvalue">von ${author}</div>`;
}
html += `<div class="card-subvalue">${currentTime}/${duration}</div>`;
// Progress bar
html += '<div class="progress-bar-container">';
html += `<div class="progress-bar" style="width: ${progressPercent}%"></div>`;
html += '</div>';
html += `</div>`;
document.getElementById('audiobook').innerHTML = html;
}

View File

@ -9,8 +9,9 @@ Access: http://localhost:5000/
"""
import requests
from flask import Flask, jsonify, Response
from flask import Flask, jsonify, Response, send_file
import os
from io import BytesIO
app = Flask(__name__)
@ -51,6 +52,11 @@ WEATHER_CODES = {
99: {"icon": "⛈️", "text": "Gewitter mit starkem Hagel"},
}
ABS_HEADERS = {
"Authorization": f"Bearer {ABS_TOKEN}",
"Content-Type": "application/json",
}
def format_duration(seconds):
"""Format seconds to HH:MM:SS or MM:SS"""
@ -90,15 +96,10 @@ def fetch_weather():
def fetch_abs_data():
"""Fetch ABS user data and latest audiobook with cover"""
"""Fetch ABS user data and latest audiobook with cover proxy URL"""
try:
headers = {
"Authorization": f"Bearer {ABS_TOKEN}",
"Content-Type": "application/json",
}
# Get user data with progress
response = requests.get(f"{ABS_BASE_URL}/api/me", headers=headers, timeout=10)
response = requests.get(f"{ABS_BASE_URL}/api/me", headers=ABS_HEADERS, timeout=10)
response.raise_for_status()
user_data = response.json()
@ -115,7 +116,7 @@ def fetch_abs_data():
# Get item details
item_response = requests.get(
f"{ABS_BASE_URL}/api/items/{library_item_id}",
headers=headers,
headers=ABS_HEADERS,
timeout=10,
)
item_response.raise_for_status()
@ -126,18 +127,15 @@ def fetch_abs_data():
author = metadata.get("author", "")
media_type = item_data.get("mediaType", "item")
# Get cover URL - construct full URL from coverPath
cover_path = item_data.get("coverPath", "")
cover_url = None
if cover_path:
# Remove leading slash if present and construct full URL
cover_url = f"{ABS_BASE_URL}{cover_path}" if cover_path.startswith("/") else f"{ABS_BASE_URL}/{cover_path}"
# Use proxy URL for cover to avoid CORS issues
# The proxy endpoint will fetch the actual cover from ABS
cover_proxy_url = f"/api/cover/{library_item_id}"
return {
"title": title,
"author": author,
"mediaType": media_type,
"coverUrl": cover_url,
"coverUrl": cover_proxy_url,
"progress": round(latest.get("progress", 0) * 100),
"currentTime": format_duration(latest.get("currentTime", 0)),
"duration": format_duration(latest.get("duration", 0)),
@ -149,6 +147,52 @@ def fetch_abs_data():
return None
@app.route("/api/cover/<library_item_id>")
def get_cover(library_item_id):
"""Proxy endpoint to fetch cover image from ABS and return it"""
try:
# Try to get cover from ABS API
cover_response = requests.get(
f"{ABS_BASE_URL}/api/items/{library_item_id}/cover",
headers=ABS_HEADERS,
timeout=10,
)
if cover_response.ok and cover_response.content:
# Return the image directly
return Response(
cover_response.content,
mimetype=cover_response.headers.get('Content-Type', 'image/jpeg')
)
# Fallback: try static path
cover_response = requests.get(
f"{ABS_BASE_URL}/metadata/items/{library_item_id}/cover.jpg",
headers=ABS_HEADERS,
timeout=5,
)
if cover_response.ok and cover_response.content:
return Response(
cover_response.content,
mimetype='image/jpeg'
)
# If no cover found, return a transparent pixel
return Response(
bytes([0x89, 0x50, 0x4E, 0x47]), # Tiny transparent PNG
mimetype='image/png'
)
except Exception as e:
print(f"Cover fetch error for {library_item_id}: {e}")
# Return transparent pixel on error
return Response(
bytes([0x89, 0x50, 0x4E, 0x47]),
mimetype='image/png'
)
@app.route("/api/dashboard")
def get_dashboard_data():
"""Return combined dashboard data"""