Reworked agent UI. Artist management form.
All checks were successful
Publish Metadata Agent Image (dev) / build-and-push-image (push) Successful in 1m8s
Publish Web Player Image (dev) / build-and-push-image (push) Successful in 1m9s
Publish Metadata Agent Image / build-and-push-image (push) Successful in 1m7s
Publish Web Player Image / build-and-push-image (push) Successful in 1m10s
Publish Server Image / build-and-push-image (push) Successful in 2m23s
All checks were successful
Publish Metadata Agent Image (dev) / build-and-push-image (push) Successful in 1m8s
Publish Web Player Image (dev) / build-and-push-image (push) Successful in 1m9s
Publish Metadata Agent Image / build-and-push-image (push) Successful in 1m7s
Publish Web Player Image / build-and-push-image (push) Successful in 1m10s
Publish Server Image / build-and-push-image (push) Successful in 2m23s
This commit is contained in:
@@ -162,6 +162,37 @@ details.llm-expand pre { background: var(--bg-card); border: 1px solid var(--bor
|
||||
.pagination button:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
|
||||
.pagination button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
|
||||
.pagination button:disabled { opacity: 0.3; cursor: default; }
|
||||
|
||||
/* Release type badges */
|
||||
.release-badge { font-size: 9px; font-weight: 700; text-transform: uppercase; padding: 1px 5px; border-radius: 3px; letter-spacing: 0.04em; }
|
||||
.rb-album { background: #1e2740; color: var(--text-dim); }
|
||||
.rb-single { background: #1e3a2e; color: #6ee7b7; }
|
||||
.rb-ep { background: #2e1e3a; color: #c4b5fd; }
|
||||
.rb-compilation{ background: #3a2e1e; color: #fcd34d; }
|
||||
.rb-live { background: #3a1e1e; color: #fca5a5; }
|
||||
.hidden-badge { font-size: 9px; font-weight: 700; text-transform: uppercase; padding: 1px 5px; border-radius: 3px; background: #1a1a1a; color: #555; letter-spacing: 0.04em; }
|
||||
|
||||
/* Artist admin form */
|
||||
.artist-section { margin-top: 14px; }
|
||||
.artist-section-title { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
|
||||
.album-block { border: 1px solid var(--border); border-radius: 6px; margin-bottom: 8px; overflow: hidden; }
|
||||
.album-block-header { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: var(--bg-card); cursor: pointer; }
|
||||
.album-block-header img { width: 36px; height: 36px; border-radius: 3px; object-fit: cover; flex-shrink: 0; }
|
||||
.album-block-header .ab-name { flex: 1; font-size: 12px; font-weight: 500; }
|
||||
.album-block-header .ab-year { font-size: 10px; color: var(--text-muted); flex-shrink: 0; }
|
||||
.album-block-body { display: none; padding: 0; }
|
||||
.album-block-body.open { display: block; }
|
||||
.album-track-row { display: flex; align-items: center; gap: 8px; padding: 4px 10px; border-top: 1px solid var(--border); font-size: 11px; background: var(--bg-base); }
|
||||
.album-track-row.hidden-track { opacity: 0.45; }
|
||||
.album-track-row .atr-num { color: var(--text-muted); width: 22px; text-align: right; flex-shrink: 0; }
|
||||
.album-track-row .atr-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.album-track-row .atr-dur { color: var(--text-muted); font-size: 10px; flex-shrink: 0; }
|
||||
.appearance-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 12px; border-bottom: 1px solid var(--border); }
|
||||
.appearance-row:last-child { border-bottom: none; }
|
||||
.btn-hide { background: #1e293b; color: var(--text-muted); border: none; padding: 2px 7px; border-radius: 3px; cursor: pointer; font-size: 10px; font-family: inherit; }
|
||||
.btn-hide:hover { background: #334155; }
|
||||
.btn-show { background: #052e16; color: var(--success); border: none; padding: 2px 7px; border-radius: 3px; cursor: pointer; font-size: 10px; font-family: inherit; }
|
||||
.btn-show:hover { background: #065f46; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -740,7 +771,7 @@ async function loadLibAlbums() {
|
||||
let html = `<table><tr><th>Album</th><th>Artist</th><th style="width:50px">Year</th><th style="width:60px">Tracks</th><th style="width:50px">Edit</th></tr>`;
|
||||
for (const a of data.items) {
|
||||
html += `<tr>
|
||||
<td><span style="display:inline-flex;align-items:center;gap:5px"><img src="${API}/albums/${a.id}/cover" style="width:20px;height:20px;border-radius:2px;object-fit:cover;flex-shrink:0" onerror="this.style.display='none'"><span>${esc(a.name)}</span></span></td>
|
||||
<td><span style="display:inline-flex;align-items:center;gap:5px"><img src="${API}/albums/${a.id}/cover" style="width:20px;height:20px;border-radius:2px;object-fit:cover;flex-shrink:0" onerror="this.style.display='none'"><span>${esc(a.name)}</span></span> ${releaseBadge(a.release_type)} ${a.hidden?'<span class="hidden-badge">Hidden</span>':''}</td>
|
||||
<td>${esc(a.artist_name)}</td>
|
||||
<td>${a.year ?? ''}</td>
|
||||
<td style="color:var(--text-muted)">${a.track_count}</td>
|
||||
@@ -768,18 +799,30 @@ async function loadLibArtists() {
|
||||
el.innerHTML = '<div class="empty">No artists found</div>';
|
||||
} else {
|
||||
let html = `<table><tr>
|
||||
<th style="width:30px"></th><th style="width:50px">ID</th><th>Name</th>
|
||||
<th style="width:60px">Albums</th><th style="width:60px">Tracks</th>
|
||||
<th style="width:80px">Actions</th>
|
||||
<th style="width:30px"></th><th style="width:40px">ID</th><th>Name</th>
|
||||
<th style="width:46px" title="Albums">LP</th>
|
||||
<th style="width:42px" title="Singles">Sng</th>
|
||||
<th style="width:34px" title="EPs">EP</th>
|
||||
<th style="width:40px" title="Compilations">Cmp</th>
|
||||
<th style="width:36px" title="Live">Live</th>
|
||||
<th style="width:46px" title="Tracks">Trk</th>
|
||||
<th style="width:60px">Actions</th>
|
||||
</tr>`;
|
||||
for (const a of data.items) {
|
||||
html += `<tr>
|
||||
const dim = 'style="color:var(--text-muted);text-align:center"';
|
||||
html += `<tr ${a.hidden?'style="opacity:0.5"':''}>
|
||||
<td><input type="checkbox" class="cb" ${selectedArtists.has(a.id)?'checked':''} onchange="toggleSelectArtist(${a.id},this.checked)"></td>
|
||||
<td style="color:var(--text-muted)">${a.id}</td>
|
||||
<td class="editable" ondblclick="inlineEditArtist(this,${a.id})">${esc(a.name)}</td>
|
||||
<td style="color:var(--text-muted)">${a.album_count}</td>
|
||||
<td style="color:var(--text-muted)">${a.track_count}</td>
|
||||
<td class="actions"><button class="btn btn-edit" onclick="editArtist(${a.id},'${esc(a.name)}')">Rename</button></td>
|
||||
<td>${a.hidden?'<span class="hidden-badge" style="margin-right:4px">H</span>':''}${esc(a.name)}</td>
|
||||
<td ${dim}>${a.album_count||''}</td>
|
||||
<td ${dim}>${a.single_count||''}</td>
|
||||
<td ${dim}>${a.ep_count||''}</td>
|
||||
<td ${dim}>${a.compilation_count||''}</td>
|
||||
<td ${dim}>${a.live_count||''}</td>
|
||||
<td ${dim}>${a.track_count||''}</td>
|
||||
<td class="actions">
|
||||
<button class="btn btn-edit" onclick="openArtistForm(${a.id})">Edit</button>
|
||||
</td>
|
||||
</tr>`;
|
||||
}
|
||||
el.innerHTML = html + '</table>';
|
||||
@@ -844,10 +887,11 @@ async function editArtist(id, currentName) {
|
||||
}
|
||||
|
||||
// --- Track edit modal ---
|
||||
async function openTrackEdit(id) {
|
||||
async function openTrackEdit(id, returnCb) {
|
||||
const t = await api(`/tracks/${id}`);
|
||||
if (!t) return;
|
||||
|
||||
editReturnCallback = returnCb || null;
|
||||
editFeatured = [...(t.featured_artists || [])];
|
||||
|
||||
document.getElementById('modal').className = 'modal';
|
||||
@@ -899,7 +943,7 @@ async function openTrackEdit(id) {
|
||||
</div>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button class="btn btn-cancel" onclick="closeModal()">Cancel</button>
|
||||
<button class="btn btn-cancel" onclick="cancelTrackEdit()">Cancel</button>
|
||||
<button class="btn btn-primary" onclick="saveTrackEdit(${t.id})">Save</button>
|
||||
</div>
|
||||
`;
|
||||
@@ -908,6 +952,7 @@ async function openTrackEdit(id) {
|
||||
}
|
||||
|
||||
let teArtistTimer = null, teAlbumTimer = null;
|
||||
let editReturnCallback = null;
|
||||
|
||||
function onTeArtistSearch(q) {
|
||||
clearTimeout(teArtistTimer);
|
||||
@@ -973,12 +1018,21 @@ async function saveTrackEdit(id) {
|
||||
featured_artists: editFeatured,
|
||||
};
|
||||
await api(`/tracks/${id}`, { method: 'PUT', headers: {'Content-Type':'application/json'}, body: JSON.stringify(body) });
|
||||
closeModal();
|
||||
if (currentTab === 'tracks') loadLibTracks();
|
||||
const cb = editReturnCallback;
|
||||
editReturnCallback = null;
|
||||
if (cb) { cb(); } else { closeModal(); if (currentTab === 'tracks') loadLibTracks(); }
|
||||
}
|
||||
|
||||
function cancelTrackEdit() {
|
||||
const cb = editReturnCallback;
|
||||
editReturnCallback = null;
|
||||
if (cb) { cb(); } else { closeModal(); }
|
||||
}
|
||||
|
||||
// --- Album edit modal ---
|
||||
async function openAlbumEdit(id) {
|
||||
let albumEditReturnCallback = null;
|
||||
async function openAlbumEdit(id, returnCb) {
|
||||
albumEditReturnCallback = returnCb || null;
|
||||
const d = await api(`/albums/${id}/full`);
|
||||
if (!d) return;
|
||||
|
||||
@@ -1023,7 +1077,7 @@ async function openAlbumEdit(id) {
|
||||
</ul>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button class="btn btn-cancel" onclick="closeModal()">Cancel</button>
|
||||
<button class="btn btn-cancel" onclick="cancelAlbumEdit()">Cancel</button>
|
||||
<button class="btn btn-edit" onclick="saveAlbumReorder(${id})">Save Order</button>
|
||||
<button class="btn btn-primary" onclick="saveAlbumEdit(${id})">Save Album</button>
|
||||
</div>
|
||||
@@ -1073,6 +1127,12 @@ function selectAeArtist(id, name) {
|
||||
document.getElementById('ae-artist-dropdown').classList.remove('open');
|
||||
}
|
||||
|
||||
function cancelAlbumEdit() {
|
||||
const cb = albumEditReturnCallback;
|
||||
albumEditReturnCallback = null;
|
||||
if (cb) { cb(); } else { closeModal(); }
|
||||
}
|
||||
|
||||
async function saveAlbumEdit(id) {
|
||||
const artistId = parseInt(document.getElementById('ae-artist-id').value);
|
||||
if (!artistId) { alert('Please select an artist from the dropdown'); return; }
|
||||
@@ -1082,7 +1142,9 @@ async function saveAlbumEdit(id) {
|
||||
artist_id: artistId,
|
||||
};
|
||||
await api(`/albums/${id}/edit`, { method: 'PUT', headers: {'Content-Type':'application/json'}, body: JSON.stringify(body) });
|
||||
if (currentTab === 'albums') loadLibAlbums();
|
||||
const cb = albumEditReturnCallback;
|
||||
albumEditReturnCallback = null;
|
||||
if (cb) { cb(); } else { closeModal(); if (currentTab === 'albums') loadLibAlbums(); }
|
||||
}
|
||||
|
||||
async function saveAlbumReorder(id) {
|
||||
@@ -1094,8 +1156,11 @@ async function saveAlbumReorder(id) {
|
||||
}
|
||||
|
||||
async function openTrackEditFromAlbum(trackId, albumId) {
|
||||
closeModal();
|
||||
await openTrackEdit(trackId);
|
||||
const parentCb = albumEditReturnCallback;
|
||||
await openTrackEdit(trackId, () => openAlbumEdit(albumId, parentCb));
|
||||
}
|
||||
function openTrackEditForArtist(trackId, artistId) {
|
||||
openTrackEdit(trackId, () => openArtistForm(artistId));
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
@@ -1329,6 +1394,198 @@ async function retryMerge(id) {
|
||||
loadMerges();
|
||||
}
|
||||
|
||||
// --- Release badge helper ---
|
||||
function releaseBadge(t) {
|
||||
const labels = {album:'Album',single:'Single',ep:'EP',compilation:'Comp',live:'Live'};
|
||||
return `<span class="release-badge rb-${t||'album'}">${labels[t]||t||'Album'}</span>`;
|
||||
}
|
||||
|
||||
// --- Artist full admin form ---
|
||||
async function openArtistForm(id) {
|
||||
const d = await api(`/artists/${id}/full`);
|
||||
if (!d) return;
|
||||
const { artist, albums, appearances } = d;
|
||||
|
||||
// Separate albums by type
|
||||
const mainAlbums = albums.filter(a => a.release_type === 'album' || a.release_type === 'compilation' || a.release_type === 'live');
|
||||
const singles = albums.filter(a => a.release_type === 'single' || a.release_type === 'ep');
|
||||
|
||||
function renderAlbumBlock(alb) {
|
||||
const hiddenCls = alb.hidden ? ' style="opacity:0.55"' : '';
|
||||
const tracks = (alb.tracks || []).map(t => `
|
||||
<div class="album-track-row ${t.hidden?'hidden-track':''}" data-tid="${t.id}">
|
||||
<span class="atr-num">${t.track_number??''}</span>
|
||||
<span class="atr-title">${esc(t.title)}</span>
|
||||
<span class="atr-dur">${fmtDuration(t.duration_secs)}</span>
|
||||
<button class="btn btn-edit" style="font-size:10px;padding:2px 6px" onclick="openTrackEditForArtist(${t.id},${id})">Edit</button>
|
||||
<button data-hidden="${t.hidden}" onclick="toggleTrackHidden(${t.id},this)">${t.hidden?'Show':'Hide'}</button>
|
||||
</div>`).join('');
|
||||
|
||||
const releaseTypes = ['album','single','ep','compilation','live'];
|
||||
const typeOpts = releaseTypes.map(rt => `<option value="${rt}" ${alb.release_type===rt?'selected':''}>${rt.charAt(0).toUpperCase()+rt.slice(1)}</option>`).join('');
|
||||
|
||||
return `<div class="album-block" id="album-block-${alb.id}"${hiddenCls}>
|
||||
<div class="album-block-header" onclick="toggleAlbumBlock(${alb.id})">
|
||||
<img src="${API}/albums/${alb.id}/cover" onerror="this.style.display='none'">
|
||||
<span class="ab-name">${esc(alb.name)}</span>
|
||||
${alb.year ? `<span class="ab-year">${alb.year}</span>` : ''}
|
||||
${releaseBadge(alb.release_type)}
|
||||
${alb.hidden?'<span class="hidden-badge">Hidden</span>':''}
|
||||
<select onclick="event.stopPropagation()" onchange="changeReleaseType(${alb.id},this.value)" style="background:var(--bg-base);border:1px solid var(--border);border-radius:3px;color:var(--text);font-size:10px;padding:2px 4px;font-family:inherit">${typeOpts}</select>
|
||||
<button data-hidden="${alb.hidden}" onclick="event.stopPropagation();toggleAlbumHidden(${alb.id},this)">${alb.hidden?'Show':'Hide'}</button>
|
||||
</div>
|
||||
<div class="album-block-body" id="album-body-${alb.id}"></div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
const albumsHtml = mainAlbums.map(renderAlbumBlock).join('') || '<div style="color:var(--text-muted);font-size:12px;padding:4px 0">No albums</div>';
|
||||
const singlesHtml = singles.map(renderAlbumBlock).join('') || '<div style="color:var(--text-muted);font-size:12px;padding:4px 0">No singles/EPs</div>';
|
||||
|
||||
const appHtml = appearances.map(ap => `
|
||||
<div class="appearance-row">
|
||||
<span style="flex:1">${esc(ap.primary_artist_name)} — <strong>${esc(ap.track_title)}</strong>${ap.album_name?` <span style="color:var(--text-muted)">(${esc(ap.album_name)})</span>`:''}</span>
|
||||
<button class="btn btn-reject" style="font-size:10px;padding:2px 6px" onclick="removeAppearance(${id},${ap.track_id},this)">Remove</button>
|
||||
</div>`).join('') || '<div style="color:var(--text-muted);font-size:12px;padding:4px 0">No appearances</div>';
|
||||
|
||||
document.getElementById('modal').className = 'modal modal-wide';
|
||||
document.getElementById('modal').innerHTML = `
|
||||
<div style="display:flex;align-items:center;gap:10px;margin-bottom:12px">
|
||||
<h2 style="flex:1;margin:0">${esc(artist.name)}</h2>
|
||||
${artist.hidden?'<span class="hidden-badge" style="font-size:11px">Hidden</span>':''}
|
||||
<button data-hidden="${artist.hidden}" onclick="toggleArtistHidden(${id},this)">${artist.hidden?'Unhide Artist':'Hide Artist'}</button>
|
||||
<button class="btn btn-edit" onclick="promptRenameArtist(${id})">Rename</button>
|
||||
</div>
|
||||
|
||||
<div class="artist-section">
|
||||
<div class="artist-section-title">Albums & Compilations <span style="color:var(--text-dim);font-weight:400">(${mainAlbums.length})</span></div>
|
||||
${albumsHtml}
|
||||
</div>
|
||||
|
||||
<div class="artist-section">
|
||||
<div class="artist-section-title">Singles & EPs <span style="color:var(--text-dim);font-weight:400">(${singles.length})</span></div>
|
||||
${singlesHtml}
|
||||
</div>
|
||||
|
||||
<div class="artist-section">
|
||||
<div class="artist-section-title">Appearances (feat.) <span style="color:var(--text-dim);font-weight:400">(${appearances.length})</span></div>
|
||||
<div id="appearances-list">${appHtml}</div>
|
||||
<div style="margin-top:8px;display:flex;gap:6px;align-items:center">
|
||||
<div style="position:relative;flex:1">
|
||||
<input id="feat-track-search" placeholder="Search track to add appearance…" autocomplete="off"
|
||||
oninput="onFeatTrackSearch(${id},this.value)" style="width:100%;background:var(--bg-card);border:1px solid var(--border);border-radius:5px;padding:6px 9px;color:var(--text);font-family:inherit;font-size:12px">
|
||||
<div class="artist-dropdown" id="feat-track-dropdown"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button class="btn btn-cancel" onclick="closeModal()">Close</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Fill album body content and restore open state
|
||||
for (const alb of albums) {
|
||||
const body = document.getElementById(`album-body-${alb.id}`);
|
||||
if (!body) continue;
|
||||
const tracks = (alb.tracks || []).map(t => `
|
||||
<div class="album-track-row ${t.hidden?'hidden-track':''}" data-tid="${t.id}">
|
||||
<span class="atr-num">${t.track_number??''}</span>
|
||||
<span class="atr-title">${esc(t.title)}</span>
|
||||
<span class="atr-dur">${fmtDuration(t.duration_secs)}</span>
|
||||
<button class="btn btn-edit" style="font-size:10px;padding:2px 6px" onclick="openTrackEditForArtist(${t.id},${id})">Edit</button>
|
||||
<button data-hidden="${t.hidden}" onclick="toggleTrackHidden(${t.id},this)">${t.hidden?'Show':'Hide'}</button>
|
||||
</div>`).join('');
|
||||
body.innerHTML = tracks;
|
||||
if (openAlbumBlocks.has(alb.id)) body.classList.add('open');
|
||||
}
|
||||
|
||||
openModal();
|
||||
}
|
||||
|
||||
const openAlbumBlocks = new Set();
|
||||
|
||||
function toggleAlbumBlock(id) {
|
||||
const body = document.getElementById(`album-body-${id}`);
|
||||
if (!body) return;
|
||||
body.classList.toggle('open');
|
||||
if (body.classList.contains('open')) openAlbumBlocks.add(id);
|
||||
else openAlbumBlocks.delete(id);
|
||||
}
|
||||
|
||||
async function toggleTrackHidden(id, btn) {
|
||||
const hidden = btn.dataset.hidden !== 'true'; // toggle
|
||||
await api(`/tracks/${id}/hidden`, { method:'PUT', headers:{'Content-Type':'application/json'}, body: JSON.stringify({hidden}) });
|
||||
btn.dataset.hidden = String(hidden);
|
||||
btn.textContent = hidden ? 'Show' : 'Hide';
|
||||
const row = btn.closest('.album-track-row');
|
||||
if (row) row.classList.toggle('hidden-track', hidden);
|
||||
}
|
||||
|
||||
async function toggleAlbumHidden(id, btn) {
|
||||
const hidden = btn.dataset.hidden !== 'true'; // toggle
|
||||
await api(`/albums/${id}/hidden`, { method:'PUT', headers:{'Content-Type':'application/json'}, body: JSON.stringify({hidden}) });
|
||||
btn.dataset.hidden = String(hidden);
|
||||
btn.textContent = hidden ? 'Show' : 'Hide';
|
||||
const block = btn.closest('.album-block');
|
||||
if (block) block.style.opacity = hidden ? '0.55' : '';
|
||||
const header = block?.querySelector('.album-block-header');
|
||||
let badge = header?.querySelector('.hidden-badge');
|
||||
if (hidden && !badge) { badge = document.createElement('span'); badge.className='hidden-badge'; badge.textContent='Hidden'; header.insertBefore(badge, btn); }
|
||||
else if (!hidden && badge) badge.remove();
|
||||
}
|
||||
|
||||
async function toggleArtistHidden(id, btn) {
|
||||
const hidden = btn.dataset.hidden !== 'true'; // toggle
|
||||
await api(`/artists/${id}/hidden`, { method:'PUT', headers:{'Content-Type':'application/json'}, body: JSON.stringify({hidden}) });
|
||||
btn.dataset.hidden = String(hidden);
|
||||
btn.textContent = hidden ? 'Unhide Artist' : 'Hide Artist';
|
||||
}
|
||||
|
||||
async function changeReleaseType(id, type) {
|
||||
await api(`/albums/${id}/release_type`, { method:'PUT', headers:{'Content-Type':'application/json'}, body: JSON.stringify({release_type: type}) });
|
||||
}
|
||||
|
||||
async function promptRenameArtist(id) {
|
||||
const name = prompt('New artist name:');
|
||||
if (!name) return;
|
||||
await api(`/artists/${id}/rename`, { method:'PUT', headers:{'Content-Type':'application/json'}, body: JSON.stringify({name}) });
|
||||
// refresh
|
||||
closeModal();
|
||||
openArtistForm(id);
|
||||
}
|
||||
|
||||
let featTrackTimer = null;
|
||||
function onFeatTrackSearch(artistId, q) {
|
||||
clearTimeout(featTrackTimer);
|
||||
const dd = document.getElementById('feat-track-dropdown');
|
||||
if (q.length < 2) { dd.classList.remove('open'); return; }
|
||||
featTrackTimer = setTimeout(async () => {
|
||||
const results = await api(`/tracks/search?q=${encodeURIComponent(q)}`);
|
||||
if (!results || !results.length) { dd.classList.remove('open'); return; }
|
||||
dd.innerHTML = results.map(t =>
|
||||
`<div class="artist-option" onclick="addAppearance(${artistId},${t.id},'${esc(t.artist_name+' — '+t.title)}')">${esc(t.artist_name)} — ${esc(t.title)}</div>`
|
||||
).join('');
|
||||
dd.classList.add('open');
|
||||
}, 250);
|
||||
}
|
||||
|
||||
async function addAppearance(artistId, trackId, label) {
|
||||
await api(`/artists/${artistId}/appearances`, { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({track_id: trackId}) });
|
||||
document.getElementById('feat-track-search').value = '';
|
||||
document.getElementById('feat-track-dropdown').classList.remove('open');
|
||||
// Add row to appearances list
|
||||
const list = document.getElementById('appearances-list');
|
||||
const row = document.createElement('div');
|
||||
row.className = 'appearance-row';
|
||||
row.innerHTML = `<span style="flex:1">${esc(label)}</span><button class="btn btn-reject" style="font-size:10px;padding:2px 6px" onclick="removeAppearance(${artistId},${trackId},this)">Remove</button>`;
|
||||
list.appendChild(row);
|
||||
}
|
||||
|
||||
async function removeAppearance(artistId, trackId, btn) {
|
||||
await api(`/artists/${artistId}/appearances/${trackId}`, { method:'DELETE' });
|
||||
btn.closest('.appearance-row').remove();
|
||||
}
|
||||
|
||||
// --- Init ---
|
||||
loadStats();
|
||||
loadQueue();
|
||||
|
||||
@@ -143,6 +143,7 @@ pub async fn update_queue_item(
|
||||
track_number: body.norm_track_number,
|
||||
genre: body.norm_genre,
|
||||
featured_artists: body.featured_artists,
|
||||
release_type: None,
|
||||
confidence: Some(1.0), // manual edit = full confidence
|
||||
notes: Some("Manually edited".to_owned()),
|
||||
};
|
||||
@@ -574,6 +575,116 @@ pub async fn search_albums_for_artist(State(state): State<S>, Query(q): Query<Al
|
||||
}
|
||||
}
|
||||
|
||||
// --- Artist full admin form ---
|
||||
|
||||
pub async fn get_artist_full(State(state): State<S>, Path(id): Path<i64>) -> impl IntoResponse {
|
||||
let artist = match db::get_artist_by_id(&state.pool, id).await {
|
||||
Ok(Some(a)) => a,
|
||||
Ok(None) => return error_response(StatusCode::NOT_FOUND, "not found"),
|
||||
Err(e) => return error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
};
|
||||
let (albums, appearances) = tokio::join!(
|
||||
db::get_artist_albums(&state.pool, id),
|
||||
db::get_artist_appearances(&state.pool, id),
|
||||
);
|
||||
// For each album, load tracks
|
||||
let albums = match albums {
|
||||
Ok(a) => a,
|
||||
Err(e) => return error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
};
|
||||
let mut albums_with_tracks = Vec::new();
|
||||
for album in albums {
|
||||
let tracks = db::get_album_tracks_admin(&state.pool, album.id).await.unwrap_or_default();
|
||||
albums_with_tracks.push(serde_json::json!({
|
||||
"id": album.id, "name": album.name, "year": album.year,
|
||||
"release_type": album.release_type, "hidden": album.hidden,
|
||||
"track_count": album.track_count, "tracks": tracks,
|
||||
}));
|
||||
}
|
||||
(StatusCode::OK, Json(serde_json::json!({
|
||||
"artist": artist,
|
||||
"albums": albums_with_tracks,
|
||||
"appearances": appearances.unwrap_or_default(),
|
||||
}))).into_response()
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SetHiddenBody { pub hidden: bool }
|
||||
|
||||
pub async fn set_track_hidden(State(state): State<S>, Path(id): Path<i64>, Json(b): Json<SetHiddenBody>) -> impl IntoResponse {
|
||||
match db::set_track_hidden(&state.pool, id, b.hidden).await {
|
||||
Ok(()) => StatusCode::NO_CONTENT.into_response(),
|
||||
Err(e) => error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn set_album_hidden(State(state): State<S>, Path(id): Path<i64>, Json(b): Json<SetHiddenBody>) -> impl IntoResponse {
|
||||
match db::set_album_hidden(&state.pool, id, b.hidden).await {
|
||||
Ok(()) => StatusCode::NO_CONTENT.into_response(),
|
||||
Err(e) => error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn set_artist_hidden(State(state): State<S>, Path(id): Path<i64>, Json(b): Json<SetHiddenBody>) -> impl IntoResponse {
|
||||
match db::set_artist_hidden(&state.pool, id, b.hidden).await {
|
||||
Ok(()) => StatusCode::NO_CONTENT.into_response(),
|
||||
Err(e) => error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SetReleaseTypeBody { pub release_type: String }
|
||||
|
||||
pub async fn set_album_release_type(State(state): State<S>, Path(id): Path<i64>, Json(b): Json<SetReleaseTypeBody>) -> impl IntoResponse {
|
||||
let valid = ["album","single","ep","compilation","live"];
|
||||
if !valid.contains(&b.release_type.as_str()) {
|
||||
return error_response(StatusCode::BAD_REQUEST, "invalid release_type");
|
||||
}
|
||||
match db::set_album_release_type(&state.pool, id, &b.release_type).await {
|
||||
Ok(()) => StatusCode::NO_CONTENT.into_response(),
|
||||
Err(e) => error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct RenameArtistBody { pub name: String }
|
||||
|
||||
pub async fn rename_artist_api(State(state): State<S>, Path(id): Path<i64>, Json(b): Json<RenameArtistBody>) -> impl IntoResponse {
|
||||
match db::rename_artist_name(&state.pool, id, &b.name).await {
|
||||
Ok(()) => StatusCode::NO_CONTENT.into_response(),
|
||||
Err(e) => error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct AddAppearanceBody { pub track_id: i64 }
|
||||
|
||||
pub async fn add_appearance(State(state): State<S>, Path(artist_id): Path<i64>, Json(b): Json<AddAppearanceBody>) -> impl IntoResponse {
|
||||
match db::add_track_appearance(&state.pool, b.track_id, artist_id).await {
|
||||
Ok(()) => StatusCode::NO_CONTENT.into_response(),
|
||||
Err(e) => error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn remove_appearance(State(state): State<S>, Path((artist_id, track_id)): Path<(i64, i64)>) -> impl IntoResponse {
|
||||
match db::remove_track_appearance(&state.pool, track_id, artist_id).await {
|
||||
Ok(()) => StatusCode::NO_CONTENT.into_response(),
|
||||
Err(e) => error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SearchTracksQuery { #[serde(default)] pub q: String }
|
||||
|
||||
pub async fn search_tracks_feat(State(state): State<S>, Query(q): Query<SearchTracksQuery>) -> impl IntoResponse {
|
||||
match db::search_tracks_for_feat(&state.pool, &q.q).await {
|
||||
Ok(rows) => (StatusCode::OK, Json(serde_json::to_value(
|
||||
rows.iter().map(|(id, title, artist)| serde_json::json!({"id": id, "title": title, "artist_name": artist})).collect::<Vec<_>>()
|
||||
).unwrap())).into_response(),
|
||||
Err(e) => error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
fn error_response(status: StatusCode, message: &str) -> axum::response::Response {
|
||||
|
||||
@@ -2,7 +2,7 @@ pub mod api;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::{Router, routing::{get, post, put}};
|
||||
use axum::{Router, routing::{delete, get, post, put}};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::config::Args;
|
||||
@@ -32,12 +32,21 @@ pub fn build_router(state: Arc<AppState>) -> Router {
|
||||
.route("/artists", get(api::list_artists))
|
||||
.route("/artists/:id", put(api::update_artist))
|
||||
.route("/artists/:id/albums", get(api::list_albums))
|
||||
.route("/artists/:id/full", get(api::get_artist_full))
|
||||
.route("/artists/:id/hidden", put(api::set_artist_hidden))
|
||||
.route("/artists/:id/rename", put(api::rename_artist_api))
|
||||
.route("/artists/:id/appearances", post(api::add_appearance))
|
||||
.route("/artists/:id/appearances/:track_id", delete(api::remove_appearance))
|
||||
.route("/tracks/search", get(api::search_tracks_feat))
|
||||
.route("/tracks/:id", get(api::get_track).put(api::update_track))
|
||||
.route("/tracks/:id/hidden", put(api::set_track_hidden))
|
||||
.route("/albums/search", get(api::search_albums_for_artist))
|
||||
.route("/albums/:id/cover", get(api::album_cover))
|
||||
.route("/albums/:id/full", get(api::get_album_full))
|
||||
.route("/albums/:id/reorder", put(api::reorder_album_tracks))
|
||||
.route("/albums/:id/edit", put(api::update_album_full))
|
||||
.route("/albums/:id/hidden", put(api::set_album_hidden))
|
||||
.route("/albums/:id/release_type", put(api::set_album_release_type))
|
||||
.route("/albums/:id", put(api::update_album))
|
||||
.route("/merges", get(api::list_merges).post(api::create_merge))
|
||||
.route("/merges/:id", get(api::get_merge).put(api::update_merge))
|
||||
|
||||
Reference in New Issue
Block a user