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:
@ -137,15 +137,16 @@
|
|||||||
/* Cover Image Styles */
|
/* Cover Image Styles */
|
||||||
.cover-container {
|
.cover-container {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cover-image {
|
.cover-image {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
max-height: 200px;
|
max-height: 180px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
background: rgba(0, 0, 0, 0.2);
|
background: rgba(0, 0, 0, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.cover-placeholder {
|
.cover-placeholder {
|
||||||
@ -158,11 +159,27 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
color: #666;
|
color: #666;
|
||||||
font-size: 1.5rem;
|
font-size: 3rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.audiobook-info {
|
.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;
|
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>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@ -291,34 +308,40 @@
|
|||||||
|
|
||||||
let html = '';
|
let html = '';
|
||||||
|
|
||||||
|
// Always show cover placeholder or image
|
||||||
|
html += '<div class="cover-container">';
|
||||||
|
|
||||||
if (coverUrl) {
|
if (coverUrl) {
|
||||||
html = `
|
// Add timestamp to prevent caching
|
||||||
<div class="cover-container">
|
const coverUrlWithCache = coverUrl.includes('?')
|
||||||
<img src="${coverUrl}" alt="${title}" class="cover-image"
|
? `${coverUrl}&t=${Date.now()}`
|
||||||
onerror="this.style.display='none'; document.getElementById('cover-fallback-${Date.now()}').style.display='block';">
|
: `${coverUrl}?t=${Date.now()}`;
|
||||||
<div id="cover-fallback-${Date.now()}" class="cover-placeholder" style="display: none;">
|
|
||||||
${mediaIcon}
|
html += `
|
||||||
</div>
|
<img src="${coverUrlWithCache}" alt="${title}" class="cover-image"
|
||||||
</div>
|
onerror="this.style.display='none'; this.nextElementSibling.style.display='block';">
|
||||||
<div class="audiobook-info">
|
<div class="cover-placeholder" style="display: none;">${mediaIcon}</div>
|
||||||
<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>
|
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
html = `
|
html += `<div class="cover-placeholder">${mediaIcon}</div>`;
|
||||||
<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>';
|
||||||
|
|
||||||
|
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;
|
document.getElementById('audiobook').innerHTML = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,8 +9,9 @@ Access: http://localhost:5000/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from flask import Flask, jsonify, Response
|
from flask import Flask, jsonify, Response, send_file
|
||||||
import os
|
import os
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@ -51,6 +52,11 @@ WEATHER_CODES = {
|
|||||||
99: {"icon": "⛈️", "text": "Gewitter mit starkem Hagel"},
|
99: {"icon": "⛈️", "text": "Gewitter mit starkem Hagel"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ABS_HEADERS = {
|
||||||
|
"Authorization": f"Bearer {ABS_TOKEN}",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def format_duration(seconds):
|
def format_duration(seconds):
|
||||||
"""Format seconds to HH:MM:SS or MM:SS"""
|
"""Format seconds to HH:MM:SS or MM:SS"""
|
||||||
@ -90,15 +96,10 @@ def fetch_weather():
|
|||||||
|
|
||||||
|
|
||||||
def fetch_abs_data():
|
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:
|
try:
|
||||||
headers = {
|
|
||||||
"Authorization": f"Bearer {ABS_TOKEN}",
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get user data with progress
|
# 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()
|
response.raise_for_status()
|
||||||
user_data = response.json()
|
user_data = response.json()
|
||||||
|
|
||||||
@ -115,7 +116,7 @@ def fetch_abs_data():
|
|||||||
# Get item details
|
# Get item details
|
||||||
item_response = requests.get(
|
item_response = requests.get(
|
||||||
f"{ABS_BASE_URL}/api/items/{library_item_id}",
|
f"{ABS_BASE_URL}/api/items/{library_item_id}",
|
||||||
headers=headers,
|
headers=ABS_HEADERS,
|
||||||
timeout=10,
|
timeout=10,
|
||||||
)
|
)
|
||||||
item_response.raise_for_status()
|
item_response.raise_for_status()
|
||||||
@ -126,18 +127,15 @@ def fetch_abs_data():
|
|||||||
author = metadata.get("author", "")
|
author = metadata.get("author", "")
|
||||||
media_type = item_data.get("mediaType", "item")
|
media_type = item_data.get("mediaType", "item")
|
||||||
|
|
||||||
# Get cover URL - construct full URL from coverPath
|
# Use proxy URL for cover to avoid CORS issues
|
||||||
cover_path = item_data.get("coverPath", "")
|
# The proxy endpoint will fetch the actual cover from ABS
|
||||||
cover_url = None
|
cover_proxy_url = f"/api/cover/{library_item_id}"
|
||||||
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}"
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"title": title,
|
"title": title,
|
||||||
"author": author,
|
"author": author,
|
||||||
"mediaType": media_type,
|
"mediaType": media_type,
|
||||||
"coverUrl": cover_url,
|
"coverUrl": cover_proxy_url,
|
||||||
"progress": round(latest.get("progress", 0) * 100),
|
"progress": round(latest.get("progress", 0) * 100),
|
||||||
"currentTime": format_duration(latest.get("currentTime", 0)),
|
"currentTime": format_duration(latest.get("currentTime", 0)),
|
||||||
"duration": format_duration(latest.get("duration", 0)),
|
"duration": format_duration(latest.get("duration", 0)),
|
||||||
@ -149,6 +147,52 @@ def fetch_abs_data():
|
|||||||
return None
|
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")
|
@app.route("/api/dashboard")
|
||||||
def get_dashboard_data():
|
def get_dashboard_data():
|
||||||
"""Return combined dashboard data"""
|
"""Return combined dashboard data"""
|
||||||
|
|||||||
Reference in New Issue
Block a user