fix wishlist additions
This commit is contained in:
parent
8feffd156b
commit
079ac5c81d
2 changed files with 101 additions and 2 deletions
|
|
@ -3526,6 +3526,23 @@ def start_wishlist_missing_downloads():
|
|||
print(f"Error starting wishlist download process: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
@app.route('/api/wishlist/clear', methods=['POST'])
|
||||
def clear_wishlist():
|
||||
"""Endpoint to clear all tracks from the wishlist."""
|
||||
try:
|
||||
from core.wishlist_service import get_wishlist_service
|
||||
wishlist_service = get_wishlist_service()
|
||||
success = wishlist_service.clear_wishlist()
|
||||
|
||||
if success:
|
||||
return jsonify({"success": True, "message": "Wishlist cleared successfully"})
|
||||
else:
|
||||
return jsonify({"success": False, "error": "Failed to clear wishlist"}), 500
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error clearing wishlist: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
@app.route('/api/database/update', methods=['POST'])
|
||||
def start_database_update():
|
||||
"""Endpoint to start the database update process."""
|
||||
|
|
@ -4348,11 +4365,33 @@ def cancel_download_task():
|
|||
track_info = task.get('track_info', {})
|
||||
|
||||
# The wishlist service expects a dictionary with specific keys
|
||||
# We can construct it from the track_info
|
||||
# We need to properly format the artists to avoid nested structures
|
||||
artists_data = track_info.get('artists', [])
|
||||
formatted_artists = []
|
||||
|
||||
for artist in artists_data:
|
||||
if isinstance(artist, str):
|
||||
# Already a string, use as-is
|
||||
formatted_artists.append({'name': artist})
|
||||
elif isinstance(artist, dict):
|
||||
# Check if it's already in the correct format
|
||||
if 'name' in artist and isinstance(artist['name'], str):
|
||||
# Already properly formatted
|
||||
formatted_artists.append(artist)
|
||||
elif 'name' in artist and isinstance(artist['name'], dict) and 'name' in artist['name']:
|
||||
# Nested structure, extract the inner name
|
||||
formatted_artists.append({'name': artist['name']['name']})
|
||||
else:
|
||||
# Fallback: convert to string
|
||||
formatted_artists.append({'name': str(artist)})
|
||||
else:
|
||||
# Fallback for any other type
|
||||
formatted_artists.append({'name': str(artist)})
|
||||
|
||||
spotify_track_data = {
|
||||
'id': track_info.get('id'),
|
||||
'name': track_info.get('name'),
|
||||
'artists': [{'name': artist} for artist in track_info.get('artists', [])],
|
||||
'artists': formatted_artists,
|
||||
'album': {'name': track_info.get('album')},
|
||||
'duration_ms': track_info.get('duration_ms')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2466,6 +2466,9 @@ async function openDownloadMissingWishlistModal() {
|
|||
<button class="download-control-btn danger" id="cancel-all-btn-${playlistId}" onclick="cancelAllOperations('${playlistId}')" style="display: none;">
|
||||
Cancel All
|
||||
</button>
|
||||
<button class="download-control-btn danger" id="clear-wishlist-btn-${playlistId}" onclick="clearWishlist('${playlistId}')" style="margin-left: 10px;">
|
||||
🗑️ Clear Wishlist
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-close-section">
|
||||
<button class="download-control-btn secondary" onclick="closeDownloadMissingModal('${playlistId}')">Close</button>
|
||||
|
|
@ -5520,4 +5523,61 @@ async function handleWishlistButtonClick() {
|
|||
console.error('Error handling wishlist button click:', error);
|
||||
showToast(`Error opening wishlist: ${error.message}`, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function clearWishlist(playlistId) {
|
||||
try {
|
||||
// Show confirmation dialog
|
||||
const confirmed = confirm(
|
||||
"Clear Wishlist\n\n" +
|
||||
"Are you sure you want to clear the entire wishlist?\n\n" +
|
||||
"This will permanently remove all failed tracks from the wishlist. " +
|
||||
"This action cannot be undone."
|
||||
);
|
||||
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable the clear button during the operation
|
||||
const clearBtn = document.getElementById(`clear-wishlist-btn-${playlistId}`);
|
||||
if (clearBtn) {
|
||||
clearBtn.disabled = true;
|
||||
clearBtn.textContent = 'Clearing...';
|
||||
}
|
||||
|
||||
// Call the clear API endpoint
|
||||
const response = await fetch('/api/wishlist/clear', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showToast('Wishlist cleared successfully', 'success');
|
||||
|
||||
// Close the modal since there are no more tracks
|
||||
closeDownloadMissingModal(playlistId);
|
||||
|
||||
// Update the wishlist count in the main dashboard
|
||||
await updateWishlistCount();
|
||||
|
||||
} else {
|
||||
showToast(`Failed to clear wishlist: ${result.error || 'Unknown error'}`, 'error');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error clearing wishlist:', error);
|
||||
showToast(`Error clearing wishlist: ${error.message}`, 'error');
|
||||
} finally {
|
||||
// Re-enable the clear button
|
||||
const clearBtn = document.getElementById(`clear-wishlist-btn-${playlistId}`);
|
||||
if (clearBtn) {
|
||||
clearBtn.disabled = false;
|
||||
clearBtn.textContent = '🗑️ Clear Wishlist';
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue