feat: implement iTunes API for release year detection and bulk refresh

This commit is contained in:
Hördle Bot
2025-11-24 14:23:07 +01:00
parent cd30476349
commit 3309b5c5ee
6 changed files with 242 additions and 10 deletions

View File

@@ -1604,6 +1604,74 @@ export default function AdminPage() {
>
☢️ Rebuild Database
</button>
<div style={{ marginTop: '1rem', borderTop: '1px solid #eee', paddingTop: '1rem' }}>
<p style={{ marginBottom: '1rem', color: '#666' }}>
Update release years for all songs using the iTunes API. This will overwrite existing years.
</p>
<button
onClick={async () => {
if (window.confirm('This will scan all songs and overwrite their release years using data from iTunes. This process may take a while.\n\nContinue?')) {
try {
let offset = 0;
let hasMore = true;
let totalUpdated = 0;
let totalSkipped = 0;
let totalFailed = 0;
let totalProcessed = 0;
let totalSongs = 0;
setMessage('Initializing release year refresh...');
while (hasMore) {
const res = await fetch('/api/admin/refresh-years', {
method: 'POST',
headers: getAuthHeaders(),
body: JSON.stringify({ offset, limit: 10 }) // Process 10 at a time
});
if (!res.ok) {
throw new Error('Batch request failed');
}
const data = await res.json();
totalUpdated += data.updated;
totalSkipped += data.skipped;
totalFailed += data.failed;
totalProcessed += data.processed;
totalSongs = data.total;
hasMore = data.hasMore;
offset = data.nextOffset;
setMessage(`Processing... ${totalProcessed} / ${totalSongs} songs.\nUpdated: ${totalUpdated} | Skipped: ${totalSkipped} | Failed: ${totalFailed}`);
}
const finalMsg = `✅ Completed!\nTotal Processed: ${totalProcessed}\nUpdated: ${totalUpdated}\nSkipped: ${totalSkipped}\nFailed: ${totalFailed}`;
alert(finalMsg);
setMessage(finalMsg);
fetchSongs(); // Refresh the table
} catch (e) {
console.error(e);
alert('Process failed due to network error or timeout.');
setMessage('Refresh failed.');
}
}
}}
style={{
padding: '0.75rem 1.5rem',
background: '#f59e0b',
color: 'white',
border: 'none',
borderRadius: '0.25rem',
cursor: 'pointer',
fontWeight: 'bold'
}}
>
🔄 Refresh Release Years (iTunes)
</button>
</div>
</div>
</div>
);