Compare commits

...
2 Commits
Author SHA1 Message Date
Aleksandr Bogomiakov 2b7117a4f6 Fixed metadata AI assistant
Build and Publish / Build and Publish Docker Image (push) Successful in 4m28s
2026-11-16 01:10:59 +00:00
Aleksandr Bogomiakov 3d886d1acd Improved metadata AI Assistant.
Build and Publish / Build and Publish Docker Image (push) Successful in 5m54s
2026-11-16 00:32:33 +00:00
8 changed files with 1277 additions and 252 deletions

No files matched your search

Generated
+1 -1
View File
@@ -1988,7 +1988,7 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
[[package]] [[package]]
name = "furumusic" name = "furumusic"
version = "0.12.2" version = "0.12.3"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-stream", "async-stream",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "furumusic" name = "furumusic"
version = "0.12.2" version = "0.12.3"
edition = "2024" edition = "2024"
description = "Reusable web-app boilerplate: auth, OIDC/SSO, admin panel, user management, i18n, PostgreSQL" description = "Reusable web-app boilerplate: auth, OIDC/SSO, admin panel, user management, i18n, PostgreSQL"
+36
View File
@@ -132,6 +132,42 @@ container `furumi-statistics-test-pg`. It requires Playwright (or
`PLAYWRIGHT_MODULE`) and Chrome (or `CHROME_PATH`). Never point this test at a `PLAYWRIGHT_MODULE`) and Chrome (or `CHROME_PATH`). Never point this test at a
live service. live service.
## Metadata Repair
Admin → Library Tools provides a chat for editing the selected library resources.
Use **Show related**, then **Deselect all** to choose only the resources needed
for the task. Selecting a release includes its tracks; individual tracks can
then be unchecked to exclude them. Unselected artists remain read-only context
and their IDs can still be used in credits. Releases show their years; tracks
show their source release.
The assistant sees the complete selected scope and replaces the proposed plan
after every clarification. Expand **Proposed changes** in the chat to review or
edit it before applying. Plans support moving tracks, creating releases, merging
releases, and deleting artists, releases, or tracks. Release deletion requires
explicit moves or deletion of all its tracks. Artist deletion detaches credits
and requires all credited releases and tracks to be included.
Applied plans are transactional and can be undone from History. Metadata Repair
retains audio and artwork files for Undo. Undo refuses to overwrite subsequent
metadata, playback, or federation changes.
```bash
node --test tests/admin_metadata_repair.test.cjs
cargo test admin::metadata_fix::tests
```
`tests/browser-metadata-repair.cjs` checks the chat and plan updates, a four-release
merge, deletion and restoration of tracks and artist credits, playlists, playback
queues, and undo conflicts. Run it only against a disposable instance and a
PostgreSQL container named `furumi-repair-test-pg`, with database
`furumi_repair_test`. Set `FURU_TEST_URL`, `FURU_REPAIR_TEST_PG`, `CHROME_PATH`, and
`PLAYWRIGHT_MODULE` as needed. It seeds `tests/metadata_repair_fixture.sql` after
creating the test administrator. Set `FURU_REPAIR_SKIP_SEED=1` for a seeded database.
With `FURU_REPAIR_TEST_MODEL=1`, it additionally checks the reported release-only
selection and full ordered tracklist against the configured model, applies and
undoes that plan, and verifies individual track exclusions.
## Importing into playlists ## Importing into playlists
The player's download manager offers **Add downloads to a playlist** for file The player's download manager offers **Add downloads to a playlist** for file
+713 -182
View File
File diff suppressed because it is too large. Load diff
+170 -68
View File
@@ -184,28 +184,58 @@ button {
} }
.repair-shell { display:grid;grid-template-columns:290px minmax(0,1fr);gap:14px;height:calc(100dvh - 116px);min-height:520px; } .repair-shell { display:grid;grid-template-columns:290px minmax(0,1fr);gap:14px;height:calc(100dvh - 116px);min-height:520px; }
.repair-side,.repair-work { min-height:0;display:flex;flex-direction:column;gap:12px; } .repair-side,.repair-work { min-width:0;min-height:0;display:flex;flex-direction:column;gap:12px; }
.repair-side .panel,.repair-plan,.repair-chat { min-height:0;display:flex;flex-direction:column; } .repair-side .panel,.repair-plan,.repair-chat { min-height:0;display:flex;flex-direction:column; }
.repair-side .panel { flex:1; } .repair-side .panel { flex:1; }
.repair-scroll { overflow:auto;min-height:0;padding:12px; } .repair-scroll { overflow:auto;min-height:0;padding:12px; }
.repair-work .repair-plan { flex:1; } .repair-work .repair-chat { flex:1; }
.repair-work .repair-chat { height:220px;flex:none; } .repair-chat > .repair-scroll { flex:1;display:flex;flex-direction:column;gap:12px; }
.repair-plan { border:1px solid var(--border-color);border-radius:8px;background:var(--bg-primary);flex:none; }
.repair-plan summary { cursor:pointer;padding:14px;display:flex;align-items:center;gap:10px;flex-wrap:wrap; }
.repair-plan summary::before { content:'▸'; }
.repair-plan[open] summary::before { content:'▾'; }
.repair-plan-body { padding:0 12px 14px;overflow:auto; }
.repair-preview { display:grid;gap:8px;margin:10px 0; }
.repair-preview-row { padding:10px 12px;border:1px solid var(--border-color);border-radius:6px; }
.repair-preview-row strong { display:block;font-size:13px;margin:4px 0;overflow-wrap:anywhere; }
.repair-preview-row p { margin:0;font-size:12px;line-height:1.5;color:var(--text-secondary);white-space:pre-line;overflow-wrap:anywhere; }
.repair-manual > summary { font-size:12px;color:var(--text-secondary); }
.repair-plan-actions { display:flex;align-items:center;justify-content:space-between;gap:10px;padding:12px;border-top:1px solid var(--border-color); }
.repair-delete { color:var(--red); }
.repair-context { display:block;color:var(--text-subdued);font-size:11px;margin-top:3px; }
@media (max-width:800px) {
html:has(.repair-view),body:has(.repair-view) { min-width:0; }
.repair-view { grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr); }
.repair-view .sidebar { border-right:0;border-bottom:1px solid var(--border-color); }
.repair-view .sidebar .brand,.repair-view .sidebar .nav-label,.repair-view .sidebar .nav-group:last-child { display:none; }
.repair-view .sidebar .nav-group { display:flex;overflow-x:auto;gap:4px;padding:8px; }
.repair-view .sidebar .nav-btn { width:auto;flex:none;white-space:nowrap;padding:10px; }
.repair-view .sidebar .nav-count { display:none; }
.repair-view .topbar { height:auto;padding:12px;flex-wrap:wrap; }
.repair-view .content { padding:12px; }
.repair-view .panel-head { flex-wrap:wrap;gap:12px; }
.repair-plan-actions { align-items:stretch;flex-direction:column; }
.repair-shell { grid-template-columns:1fr;height:auto;min-height:0; }
.repair-side .panel:first-child .repair-scroll { max-height:280px; }
.repair-work .repair-chat { min-height:65dvh;max-height:90dvh; }
}
.repair-group { margin:12px 0 5px;color:var(--text-secondary);font-size:11px;font-weight:800;text-transform:uppercase; } .repair-group { margin:12px 0 5px;color:var(--text-secondary);font-size:11px;font-weight:800;text-transform:uppercase; }
.repair-entity { display:flex;align-items:flex-start;gap:8px;padding:6px 0;font-size:12px; } .repair-entity { display:flex;align-items:flex-start;gap:8px;padding:6px 0;font-size:12px; }
.repair-entity span { overflow-wrap:anywhere; } .repair-entity span { overflow-wrap:anywhere; }
.repair-search-results { max-height:160px;overflow:auto;border:1px solid var(--border-color);border-radius:6px;margin-top:6px; } .repair-search-results { max-height:160px;overflow:auto;border:1px solid var(--border-color);border-radius:6px;margin-top:6px; }
.repair-search-results button { display:block;width:100%;padding:8px;background:transparent;color:var(--text-primary);text-align:left;cursor:pointer; } .repair-search-results button { display:block;width:100%;padding:8px;background:transparent;color:var(--text-primary);text-align:left;cursor:pointer; }
.repair-search-results button:hover { background:var(--bg-hover); } .repair-search-results button:hover { background:var(--bg-hover); }
.repair-diff { width:100%;border-collapse:collapse;font-size:12px; } .repair-diff { min-width:850px;width:100%;border-collapse:collapse;font-size:12px; }
.repair-diff th,.repair-diff td { text-align:left;border-bottom:1px solid var(--border-color);padding:7px;vertical-align:top; } .repair-diff th,.repair-diff td { text-align:left;border-bottom:1px solid var(--border-color);padding:7px;vertical-align:top; }
.repair-diff th { color:var(--text-subdued);font-size:10px;text-transform:uppercase; } .repair-diff th { color:var(--text-subdued);font-size:10px;text-transform:uppercase; }
.repair-diff input,.repair-diff select { width:100%;min-width:90px;background:var(--bg-primary);color:var(--text-primary);border:1px solid var(--border-color);border-radius:5px;padding:6px; } .repair-diff input,.repair-diff select { width:100%;min-width:90px;background:var(--bg-primary);color:var(--text-primary);border:1px solid var(--border-color);border-radius:5px;padding:6px; }
.repair-diff .compact { min-width:65px;max-width:90px; } .repair-diff .compact { min-width:65px;max-width:90px; }
.repair-message { padding:7px 9px;border-radius:7px;max-width:86%;font-size:12px;white-space:pre-wrap;overflow-wrap:anywhere; } .repair-message { padding:12px 14px;border-radius:9px;max-width:90%;font-size:14px;line-height:1.6;white-space:pre-wrap;overflow-wrap:anywhere; }
.repair-message.user { background:#16452a;align-self:flex-end; } .repair-message.user { background:#16452a;align-self:flex-end; }
.repair-message.assistant { background:var(--bg-elevated);align-self:flex-start; } .repair-message.assistant { background:var(--bg-elevated);align-self:flex-start; }
.repair-composer { border-top:1px solid var(--border-color);padding:9px;display:flex;gap:8px;align-items:end; } .repair-composer { border-top:1px solid var(--border-color);padding:9px;display:flex;gap:8px;align-items:end; }
.repair-composer textarea { flex:1;min-width:0;resize:vertical;max-height:100px;background:var(--bg-primary);color:var(--text-primary);border:1px solid var(--border-color);border-radius:6px;padding:8px; } .repair-composer textarea { flex:1;min-width:0;resize:vertical;max-height:180px;background:var(--bg-primary);color:var(--text-primary);border:1px solid var(--border-color);border-radius:6px;padding:8px; }
.repair-thinking { display:flex;align-items:center;gap:8px;color:var(--amber);font-size:12px;padding:10px; } .repair-thinking { display:flex;align-items:center;gap:8px;color:var(--amber);font-size:12px;padding:10px; }
.repair-thinking::before { content:"";width:10px;height:10px;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;animation:repair-spin .8s linear infinite; } .repair-thinking::before { content:"";width:10px;height:10px;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;animation:repair-spin .8s linear infinite; }
@keyframes repair-spin { to { transform:rotate(360deg); } } @keyframes repair-spin { to { transform:rotate(360deg); } }
@@ -2060,7 +2090,7 @@ tbody tr:hover {
{% endblock head_extra %} {% endblock head_extra %}
{% block content %} {% block content %}
<div class="admin-shell" :class="{'statistics-view': activeView === 'statistics'}" x-data="adminV2()" x-cloak> <div class="admin-shell" :class="{'statistics-view': activeView === 'statistics', 'repair-view': activeView === 'tools'}" x-data="adminV2()" x-cloak>
<aside class="sidebar"> <aside class="sidebar">
<div class="brand"> <div class="brand">
<div class="brand-title"> <div class="brand-title">
@@ -2674,42 +2704,56 @@ tbody tr:hover {
<template x-for="item in repairSearchResults" :key="item.kind + ':' + item.id"><button type="button" @click="addRepairEntity(item)" x-text="item.title + (item.subtitle ? ' · ' + item.subtitle : '')"></button></template> <template x-for="item in repairSearchResults" :key="item.kind + ':' + item.id"><button type="button" @click="addRepairEntity(item)" x-text="item.title + (item.subtitle ? ' · ' + item.subtitle : '')"></button></template>
</div> </div>
<div class="repair-group">Selected and related · <span x-text="repairIncludedCount()"></span></div> <div class="repair-group">Selected and related · <span x-text="repairIncludedCount()"></span></div>
<div class="toolbar"><button class="btn" @click="setAllRepairIncluded(true)" :disabled="repairBusy || !repairRowsCount()">Select all</button><button class="btn" @click="setAllRepairIncluded(false)" :disabled="repairBusy || !repairIncludedCount()">Deselect all</button></div>
<div class="muted" x-show="!repairExpanded && repairSelected.length === 0">Search and select an artist, release, or track.</div> <div class="muted" x-show="!repairExpanded && repairSelected.length === 0">Search and select an artist, release, or track.</div>
<template x-for="kind in ['artists','releases','tracks']" :key="kind"> <template x-for="kind in ['artists','releases','tracks']" :key="kind">
<div x-show="repairRows(kind).length"> <div x-show="repairRows(kind).length">
<div class="repair-group" x-text="kind"></div> <div class="repair-group" x-text="kind"></div>
<template x-for="item in repairRows(kind)" :key="kind + item.id"> <template x-for="item in repairRows(kind)" :key="kind + item.id">
<label class="repair-entity"><input type="checkbox" :checked="repairIncluded[kind + ':' + item.id] !== false" @change="setRepairIncluded(kind,item.id,$event.target.checked)" :disabled="repairBusy" /><span x-text="(item.name || item.title) + ' #' + item.id"></span></label> <label class="repair-entity"><input type="checkbox" :checked="repairIsIncluded(kind,item.id)" @change="setRepairIncluded(kind,item.id,$event.target.checked)" :disabled="repairBusy" /><span><span x-text="(item.name || item.title) + ' #' + item.id"></span><small class="repair-context" x-text="repairEntityContext(kind,item)"></small></span></label>
</template> </template>
</div> </div>
</template> </template>
<div class="toolbar" style="margin-top:12px"><button class="btn" @click="expandRepair()" :disabled="repairSelected.length === 0 || repairBusy">Show related</button><button class="btn" @click="clearRepair()" :disabled="repairBusy">Clear</button></div> <div class="toolbar" style="margin-top:12px"><button class="btn" @click="expandRepair()" :disabled="repairSelected.length === 0 || repairBusy">Show related</button><button class="btn" @click="clearRepair()" :disabled="repairBusy">Clear</button></div>
<div class="muted" style="margin-top:8px">Uncheck any related item to exclude it from the plan. Audio files stay in their current folders.</div> <div class="muted" style="margin-top:8px">Selecting a release includes its tracks. Uncheck individual tracks to exclude them. Artist names are read-only unless the artist is checked. Audio files stay in their current folders.</div>
</div> </div>
</section> </section>
<section class="panel" style="max-height:160px"><div class="panel-head"><div class="panel-title"><strong>History</strong><span>Recent applied plans</span></div></div><div class="repair-scroll repair-history"><template x-for="entry in repairHistory" :key="entry.id"><div class="repair-entity"><span style="flex:1" x-text="'#' + entry.id + ' · ' + entry.instruction.slice(0,55) + (entry.undone_at ? ' · undone' : '')"></span><button class="btn" x-show="!entry.undone_at" @click="undoRepair(entry.id)" :disabled="repairBusy">Undo</button></div></template><div class="muted" x-show="repairHistory.length === 0">No applied plans yet.</div></div></section> <section class="panel" style="max-height:160px"><div class="panel-head"><div class="panel-title"><strong>History</strong><span>Recent applied plans</span></div></div><div class="repair-scroll repair-history"><template x-for="entry in repairHistory" :key="entry.id"><div class="repair-entity"><span style="flex:1" x-text="'#' + entry.id + ' · ' + entry.instruction.slice(0,55) + (entry.undone_at ? ' · undone' : '')"></span><button class="btn" x-show="!entry.undone_at" @click="undoRepair(entry.id)" :disabled="repairBusy">Undo</button></div></template><div class="muted" x-show="repairHistory.length === 0">No applied plans yet.</div></div></section>
</aside> </aside>
<div class="repair-work"> <div class="repair-work">
<section class="panel repair-plan"> <section class="panel repair-chat">
<div class="panel-head"><div class="panel-title"><strong>Proposed changes</strong><span x-text="repairIncomplete ? (repairBusy ? 'Processing tracks: ' : 'Paused at track: ') + repairTrackOffset + ' / ' + repairTrackTotal : (repairPlan ? 'Review and edit before applying' : 'The agent’s plan will appear here')"></span></div><div class="toolbar"><span class="selection-summary" x-show="repairPlan" x-text="repairChangeCount() + ' changes'"></span><button class="btn primary" x-show="repairPlan" @click="applyRepair()" :disabled="repairBusy || repairIncomplete || !repairChangeCount()">Apply plan</button></div></div> <div class="panel-head"><div class="panel-title"><strong>Metadata assistant</strong><span>Discuss the task. The proposed plan updates with each reply.</span></div></div>
<div class="repair-scroll" :style="repairBusy ? 'pointer-events:none' : ''"> <div class="repair-scroll" x-ref="repairChat">
<div class="repair-thinking" x-show="repairBusy && repairStage === 'thinking'">Agent is reviewing the selected metadata…</div> <div class="muted" x-show="repairChat.length === 0">Select resources and describe what should change. You can ask to combine releases, move tracks, edit metadata, or delete resources.</div>
<div class="empty" x-show="!repairPlan && !(repairBusy && repairStage === 'thinking')">Select entities and describe the correction in the chat below.</div> <template x-for="(turn,index) in repairChat" :key="index"><div class="repair-message" :class="turn.role" x-text="turn.content"></div></template>
<div class="repair-thinking" x-show="repairBusy" x-text="repairStage === 'applying' ? 'Applying changes…' : 'Agent is reviewing the selected metadata and updating the plan…'" role="status"></div>
<details class="repair-plan" x-show="repairPlan" :open="repairPlanOpen" @toggle="repairPlanOpen = $el.open">
<summary><strong>Proposed changes</strong><span class="selection-summary" x-text="repairChangeCount() + ' changes' + (repairDeleteCount() ? ' · ' + repairDeleteCount() + ' deletions' : '')"></span><span class="muted" x-text="repairIncomplete ? 'Update incomplete · retry your message' : 'Expand to review the current plan'"></span></summary>
<div class="repair-plan-body"><fieldset :disabled="repairBusy || repairIncomplete" style="border:0;padding:0;margin:0;min-width:0">
<template x-if="repairPlan"><div> <template x-if="repairPlan"><div>
<div class="repair-section-title" x-show="repairPlan.questions.length">Questions to review</div> <div class="repair-section-title" x-show="repairPlan.questions.length">Questions to review</div>
<template x-for="question in repairPlan.questions" :key="question"><div class="repair-entity" style="color:var(--amber)" x-text="question"></div></template> <template x-for="question in repairPlan.questions" :key="question"><div class="repair-entity" style="color:var(--amber)" x-text="question"></div></template>
<div class="repair-preview"><template x-for="row in repairPreview()" :key="row.key"><div class="repair-preview-row"><small class="muted" x-text="row.action"></small><strong x-text="row.title"></strong><p x-text="row.detail"></p></div></template></div>
<details class="repair-manual"><summary>Edit fields manually</summary>
<div class="repair-section-title" x-show="repairPlan.artists.length">Artists</div> <div class="repair-section-title" x-show="repairPlan.artists.length">Artists</div>
<table class="repair-diff" x-show="repairPlan.artists.length"><thead><tr><th>Before</th><th>After</th><th></th></tr></thead><tbody><template x-for="(edit,index) in repairPlan.artists" :key="edit.id"><tr><td x-text="repairBefore('artists',edit.id)?.name || ''"></td><td><input x-model="edit.name" /></td><td><button class="btn" @click="repairPlan.artists.splice(index,1)">Remove</button></td></tr></template></tbody></table> <table class="repair-diff" x-show="repairPlan.artists.length"><thead><tr><th>Before</th><th>After</th><th></th></tr></thead><tbody><template x-for="(edit,index) in repairPlan.artists" :key="edit.id"><tr><td x-text="repairEntityLabel('artists',edit.id)"></td><td><input x-model="edit.name" /></td><td><button class="btn" @click="repairPlan.artists.splice(index,1)">Remove edit</button></td></tr></template></tbody></table>
<div class="repair-section-title" x-show="repairPlan.releases.length">Releases</div> <div class="repair-section-title" x-show="repairPlan.releases.length">Releases</div>
<table class="repair-diff" x-show="repairPlan.releases.length"><thead><tr><th>Before</th><th>After</th><th>Type</th><th>Year</th><th>Artist IDs</th><th></th></tr></thead><tbody><template x-for="(edit,index) in repairPlan.releases" :key="edit.id || edit.key"><tr><td><div x-text="edit.id ? (repairBefore('releases',edit.id)?.title || '') : 'New release'"></div><small class="muted" x-show="edit.id" x-text="edit.id ? [repairBefore('releases',edit.id)?.release_type,repairBefore('releases',edit.id)?.year].filter(x => x != null).join(' · ') : ''"></small></td><td><input x-model="edit.title" /></td><td><select x-model="edit.release_type"><template x-for="type in ['album','single','ep','compilation','mixtape','live','soundtrack','remix','demo']" :key="type"><option :value="type" x-text="type"></option></template></select></td><td><input class="compact" type="number" x-model.number="edit.year" /></td><td><input :value="edit.artist_ids.join(', ')" @change="edit.artist_ids = parseRepairIds($event.target.value)" /></td><td><button class="btn" @click="repairPlan.releases.splice(index,1)">Remove</button></td></tr></template></tbody></table> <table class="repair-diff" x-show="repairPlan.releases.length"><thead><tr><th>Before</th><th>After</th><th>Type</th><th>Year</th><th>Artist IDs</th><th></th></tr></thead><tbody><template x-for="(edit,index) in repairPlan.releases" :key="edit.id || edit.key"><tr><td><div x-text="edit.id ? repairEntityLabel('releases',edit.id) : 'New release'"></div><small class="muted" x-show="edit.id" x-text="edit.id ? [repairBefore('releases',edit.id)?.release_type,repairBefore('releases',edit.id)?.year].filter(x => x != null).join(' · ') : ''"></small></td><td><input x-model="edit.title" /></td><td><select x-model="edit.release_type"><template x-for="type in ['album','single','ep','compilation','mixtape','live','soundtrack','remix','demo']" :key="type"><option :value="type" x-text="type"></option></template></select></td><td><input class="compact" type="number" x-model.number="edit.year" /></td><td><input :value="edit.artist_ids.join(', ')" @change="edit.artist_ids = parseRepairIds($event.target.value)" /><small class="repair-context" x-text="repairArtistNames(edit.artist_ids)"></small></td><td><button class="btn" @click="repairPlan.releases.splice(index,1)">Remove edit</button></td></tr></template></tbody></table>
<div class="toolbar" x-show="repairPlan"><button class="btn" @click="addRepairRelease()">+ New release</button></div> <div class="toolbar" x-show="repairPlan"><button class="btn" @click="addRepairRelease()">+ New release</button></div>
<div class="repair-section-title" x-show="repairPlan.tracks.length">Tracks</div> <div class="repair-section-title" x-show="repairPlan.tracks.length">Tracks</div>
<table class="repair-diff" x-show="repairPlan.tracks.length"><thead><tr><th>Before</th><th>After</th><th>Release</th><th>#</th><th>Disc</th><th>Year</th><th>Artist IDs</th><th></th></tr></thead><tbody><template x-for="(edit,index) in repairPlan.tracks" :key="edit.id"><tr><td><div x-text="repairBefore('tracks',edit.id)?.title || ''"></div><small class="muted" x-text="'#' + (repairBefore('tracks',edit.id)?.track_number ?? '—') + ' · release #' + (repairBefore('tracks',edit.id)?.release_id || '')"></small></td><td><input x-model="edit.title" /></td><td><select x-model="edit.target_release"><template x-for="release in repairTargetReleases()" :key="release.value"><option :value="release.value" x-text="release.label"></option></template></select></td><td><input class="compact" type="number" x-model.number="edit.track_number" /></td><td><input class="compact" type="number" x-model.number="edit.disc_number" /></td><td><input class="compact" type="number" x-model.number="edit.year" /></td><td><input :value="edit.artist_ids.join(', ')" @change="edit.artist_ids = parseRepairIds($event.target.value)" /></td><td><button class="btn" @click="repairPlan.tracks.splice(index,1)">Remove</button></td></tr></template></tbody></table> <table class="repair-diff" x-show="repairPlan.tracks.length"><thead><tr><th>Before</th><th>After</th><th>Release</th><th>#</th><th>Disc</th><th>Year</th><th>Artist IDs</th><th></th></tr></thead><tbody><template x-for="(edit,index) in repairPlan.tracks" :key="edit.id"><tr><td><div x-text="repairEntityLabel('tracks',edit.id)"></div><small class="muted" x-text="repairEntityContext('tracks',repairBefore('tracks',edit.id))"></small></td><td><input x-model="edit.title" /></td><td><select x-model="edit.target_release"><template x-for="release in repairTargetReleases()" :key="release.value"><option :value="release.value" x-text="release.label"></option></template></select></td><td><input class="compact" type="number" x-model.number="edit.track_number" /></td><td><input class="compact" type="number" x-model.number="edit.disc_number" /></td><td><input class="compact" type="number" x-model.number="edit.year" /></td><td><input :value="edit.artist_ids.join(', ')" @change="edit.artist_ids = parseRepairIds($event.target.value)" /><small class="repair-context" x-text="repairArtistNames(edit.artist_ids)"></small></td><td><button class="btn" @click="repairPlan.tracks.splice(index,1)">Remove edit</button></td></tr></template></tbody></table>
<div class="toolbar"><button class="btn" @click="addRepairTrack()">+ Track edit</button></div> <div class="toolbar"><button class="btn" @click="addRepairTrack()">+ Track edit</button></div>
</details>
<div class="repair-section-title repair-delete" x-show="repairDeleteCount()">Delete resources · <span x-text="repairDeleteCount()"></span></div>
<p class="muted" x-show="repairDeleteCount()">These resources will be removed from the library. Audio files are retained for Undo. Release tracks must be moved or explicitly deleted; artist credits are detached.</p>
<template x-for="kind in ['artists','releases','tracks']" :key="kind"><div><template x-for="id in (repairPlan.delete?.[kind] || [])" :key="id"><div class="repair-entity repair-delete"><span style="flex:1" x-text="kind + ' · ' + repairEntityLabel(kind,id) + (kind === 'releases' ? ' · ' + repairEntityContext(kind,repairBefore(kind,id)) : '')"></span><button class="btn" @click="repairPlan.delete[kind] = repairPlan.delete[kind].filter(value => value !== id)">Keep resource</button></div></template></div></template>
</div></template> </div></template>
</fieldset></div>
<div class="repair-plan-actions"><span class="muted">Review the plan before applying.</span><button class="btn primary" @click="applyRepair()" :disabled="repairBusy || repairIncomplete || !repairChangeCount()">Apply plan</button></div>
</details>
</div> </div>
<form class="repair-composer" @submit.prevent="sendRepair()"><textarea rows="3" placeholder="Describe the task or clarify the current plan…" aria-label="Message to metadata assistant" x-model="repairDraft" :disabled="repairBusy" @keydown.ctrl.enter.prevent="sendRepair()"></textarea><button class="btn primary" type="submit" :disabled="repairBusy || !repairDraft.trim() || !repairIncludedCount()" x-text="repairIncomplete && repairDraft.trim() === repairPendingInstruction ? 'Retry' : 'Send'"></button></form>
</section> </section>
<section class="panel repair-chat"><div class="repair-scroll" style="display:flex;flex-direction:column;gap:7px" x-ref="repairChat"><template x-for="(turn,index) in repairChat" :key="index"><div class="repair-message" :class="turn.role" x-text="turn.content"></div></template><div class="muted" x-show="repairChat.length === 0">Describe what should change. The agent will respond in your language.</div></div><form class="repair-composer" @submit.prevent="sendRepair()"><textarea rows="2" placeholder="Describe the metadata problem…" x-model="repairDraft" @keydown.ctrl.enter.prevent="sendRepair()"></textarea><button class="btn primary" type="submit" :disabled="repairBusy || !repairDraft.trim() || !repairIncludedCount()" x-text="repairIncomplete && repairDraft.trim() === repairPendingInstruction ? 'Retry' : 'Send'"></button></form></section>
</div> </div>
</div> </div>
</div> </div>
@@ -4211,19 +4255,18 @@ function adminV2() {
repairSelected: [], repairSelected: [],
repairExpanded: null, repairExpanded: null,
repairIncluded: {}, repairIncluded: {},
repairExcludedTracks: [],
repairDraft: '', repairDraft: '',
repairChat: [], repairChat: [],
repairPlan: null, repairPlan: null,
repairPlanOpen: false,
repairSnapshot: null, repairSnapshot: null,
repairInstruction: '', repairInstruction: '',
repairBusy: false, repairBusy: false,
repairStage: '', repairStage: '',
repairIncomplete: false, repairIncomplete: false,
repairTrackOffset: 0,
repairTrackTotal: 0,
repairPendingInstruction: '', repairPendingInstruction: '',
repairReference: '', repairReference: '',
repairExpandedReference: '',
repairHistory: [], repairHistory: [],
settings: { values: {}, sources: {}, youtube_cookie_files: [], lastfm_api_key_configured: false, lastfm_shared_secret_configured: false, lastfm_scrobbling_configured: false }, settings: { values: {}, sources: {}, youtube_cookie_files: [], lastfm_api_key_configured: false, lastfm_shared_secret_configured: false, lastfm_scrobbling_configured: false },
settingsDraft: { settingsDraft: {
@@ -4479,11 +4522,10 @@ function adminV2() {
this.repairSelected.push({kind:item.kind,id:Number(item.id),title:item.title}); this.repairSelected.push({kind:item.kind,id:Number(item.id),title:item.title});
this.repairExpanded = null; this.repairExpanded = null;
this.repairPlan = null; this.repairPlan = null;
this.repairSnapshot = null;
this.repairIncomplete = false; this.repairIncomplete = false;
this.repairTrackOffset = 0;
this.repairPendingInstruction = ''; this.repairPendingInstruction = '';
this.repairReference = ''; this.repairReference = '';
this.repairExpandedReference = '';
this.repairSearch = ''; this.repairSearch = '';
this.repairSearchResults = []; this.repairSearchResults = [];
}, },
@@ -4491,16 +4533,14 @@ function adminV2() {
this.repairSelected = []; this.repairSelected = [];
this.repairExpanded = null; this.repairExpanded = null;
this.repairIncluded = {}; this.repairIncluded = {};
this.repairExcludedTracks = [];
this.repairPlan = null; this.repairPlan = null;
this.repairSnapshot = null; this.repairSnapshot = null;
this.repairChat = []; this.repairChat = [];
this.repairDraft = ''; this.repairDraft = '';
this.repairIncomplete = false; this.repairIncomplete = false;
this.repairTrackOffset = 0;
this.repairTrackTotal = 0;
this.repairPendingInstruction = ''; this.repairPendingInstruction = '';
this.repairReference = ''; this.repairReference = '';
this.repairExpandedReference = '';
}, },
repairSelection(expanded = false) { repairSelection(expanded = false) {
const selection = {artists:[],releases:[],tracks:[]}; const selection = {artists:[],releases:[],tracks:[]};
@@ -4513,8 +4553,15 @@ function adminV2() {
} else { } else {
for (const item of this.repairSelected) if (this.repairIncluded[item.kind + ':' + item.id] !== false) selection[item.kind].push(item.id); for (const item of this.repairSelected) if (this.repairIncluded[item.kind + ':' + item.id] !== false) selection[item.kind].push(item.id);
} }
if (expanded && this.repairExpanded) {
for (const track of this.repairExpanded.snapshot.tracks || []) {
if (selection.releases.includes(track.release_id) && !this.repairExcludedTracks.includes(track.id) && !selection.tracks.includes(track.id)) selection.tracks.push(track.id);
}
selection.tracks = selection.tracks.filter(id => !this.repairExcludedTracks.includes(id)).sort((a,b) => a-b);
}
return selection; return selection;
}, },
repairIsIncluded(kind,id) { return this.repairSelection(true)[kind].includes(Number(id)); },
repairRows(kind) { repairRows(kind) {
if (this.repairExpanded) return this.repairExpanded.snapshot[kind] || []; if (this.repairExpanded) return this.repairExpanded.snapshot[kind] || [];
return this.repairSelected.filter(item => item.kind === kind); return this.repairSelected.filter(item => item.kind === kind);
@@ -4522,16 +4569,50 @@ function adminV2() {
repairIncludedCount() { repairIncludedCount() {
return Object.values(this.repairSelection(true)).reduce((total, ids) => total + ids.length, 0); return Object.values(this.repairSelection(true)).reduce((total, ids) => total + ids.length, 0);
}, },
setRepairIncluded(kind,id,checked) { repairRowsCount() { return ['artists','releases','tracks'].reduce((count,kind) => count + this.repairRows(kind).length,0); },
if (this.repairBusy) return; invalidateRepairPlan() {
this.repairIncluded[kind + ':' + id] = checked;
this.repairPlan = null; this.repairPlan = null;
this.repairSnapshot = null; this.repairSnapshot = null;
this.repairIncomplete = false; this.repairIncomplete = false;
this.repairTrackOffset = 0;
this.repairPendingInstruction = ''; this.repairPendingInstruction = '';
this.repairReference = ''; },
this.repairExpandedReference = ''; setAllRepairIncluded(checked) {
if (this.repairBusy) return;
this.repairExcludedTracks = [];
for (const kind of ['artists','releases','tracks']) {
for (const item of this.repairRows(kind)) this.repairIncluded[kind + ':' + item.id] = checked;
}
this.invalidateRepairPlan();
},
setRepairIncluded(kind,id,checked) {
if (this.repairBusy) return;
this.repairIncluded[kind + ':' + id] = checked;
if (kind === 'tracks') {
this.repairExcludedTracks = this.repairExcludedTracks.filter(value => value !== id);
if (!checked) this.repairExcludedTracks.push(id);
}
if (kind === 'releases' && checked) {
const tracks = this.repairRows('tracks').filter(track => track.release_id === id).map(track => track.id);
this.repairExcludedTracks = this.repairExcludedTracks.filter(id => !tracks.includes(id));
}
this.invalidateRepairPlan();
},
repairEntityLabel(kind,id) {
const row = this.repairBefore(kind,id) || this.repairRows(kind).find(row => Number(row.id) === Number(id));
return (row?.name || row?.title || kind) + ' #' + id;
},
repairArtistNames(ids) {
return ids.map(id => this.repairEntityLabel('artists',id)).join(', ');
},
repairEntityContext(kind,item) {
if (!item) return '';
const scope = this.repairSnapshot || this.repairExpanded?.snapshot;
if (kind === 'releases') return [item.year, item.release_type, (scope?.release_artists || []).filter(link => link.owner_id === item.id).map(link => this.repairEntityLabel('artists',link.artist_id)).join(', ')].filter(Boolean).join(' · ');
if (kind === 'tracks') {
const release = (scope?.releases || []).find(row => row.id === item.release_id);
return [release ? release.title + ' #' + release.id : 'Release #' + item.release_id, release?.year, item.track_number ? 'Track ' + item.track_number : ''].filter(Boolean).join(' · ');
}
return '';
}, },
async expandRepair() { async expandRepair() {
if (this.repairSelected.length === 0) return; if (this.repairSelected.length === 0) return;
@@ -4541,12 +4622,11 @@ function adminV2() {
this.repairExpanded = await this.request(`${this.apiBase}/metadata-fix/expand`, { this.repairExpanded = await this.request(`${this.apiBase}/metadata-fix/expand`, {
method:'POST',body:JSON.stringify({selection:this.repairSelection(false),reference:this.repairReference || null}) method:'POST',body:JSON.stringify({selection:this.repairSelection(false),reference:this.repairReference || null})
}); });
this.repairExpandedReference = this.repairReference;
this.repairPlan = null; this.repairPlan = null;
this.repairSnapshot = null; this.repairSnapshot = null;
this.repairIncluded = {}; this.repairIncluded = {};
this.repairExcludedTracks = [];
this.repairIncomplete = false; this.repairIncomplete = false;
this.repairTrackOffset = 0;
this.repairPendingInstruction = ''; this.repairPendingInstruction = '';
} catch (error) { this.showToast(error.message); } } catch (error) { this.showToast(error.message); }
finally { this.repairBusy = false; this.repairStage = ''; } finally { this.repairBusy = false; this.repairStage = ''; }
@@ -4557,9 +4637,9 @@ function adminV2() {
return relations.filter(row => Number(row.owner_id) === Number(id)).map(row => Number(row.artist_id)); return relations.filter(row => Number(row.owner_id) === Number(id)).map(row => Number(row.artist_id));
}, },
repairTargetReleases() { repairTargetReleases() {
const existing = (this.repairSnapshot?.releases || []).map(row => ({value:'existing:' + row.id,label:row.title + ' #' + row.id})); const existing = (this.repairSnapshot?.releases || []).filter(row => !this.repairPlan?.delete?.releases?.includes(row.id)).map(row => ({value:'existing:' + row.id,label:row.title + (row.year ? ' (' + row.year + ')' : '') + ' #' + row.id}));
for (const track of this.repairSnapshot?.tracks || []) { for (const track of this.repairSnapshot?.tracks || []) {
if (!existing.some(row => row.value === 'existing:' + track.release_id)) existing.push({value:'existing:' + track.release_id,label:'Current release #' + track.release_id}); if (!this.repairPlan?.delete?.releases?.includes(track.release_id) && !existing.some(row => row.value === 'existing:' + track.release_id)) existing.push({value:'existing:' + track.release_id,label:'Current release #' + track.release_id});
} }
const created = (this.repairPlan?.releases || []).filter(row => row.key && !row.id).map(row => ({value:'new:' + row.key,label:(row.title || 'New release') + ' · new'})); const created = (this.repairPlan?.releases || []).filter(row => row.key && !row.id).map(row => ({value:'new:' + row.key,label:(row.title || 'New release') + ' · new'}));
return existing.concat(created); return existing.concat(created);
@@ -4573,11 +4653,32 @@ function adminV2() {
}, },
addRepairTrack() { addRepairTrack() {
if (!this.repairPlan || !this.repairSnapshot) return; if (!this.repairPlan || !this.repairSnapshot) return;
const row = this.repairSnapshot.tracks.find(x => !this.repairPlan.tracks.some(edit => edit.id === x.id)); const row = this.repairSnapshot.tracks.find(x => !this.repairPlan.tracks.some(edit => edit.id === x.id) && !this.repairPlan.delete?.tracks?.includes(x.id));
if (!row) { this.showToast('All selected tracks are already in the plan'); return; } if (!row) { this.showToast('All selected tracks are already in the plan'); return; }
this.repairPlan.tracks.push({id:row.id,title:row.title,target_release:'existing:' + row.release_id,track_number:row.track_number,disc_number:row.disc_number,year:row.year,artist_ids:this.repairArtistIds('tracks',row.id)}); this.repairPlan.tracks.push({id:row.id,title:row.title,target_release:'existing:' + row.release_id,track_number:row.track_number,disc_number:row.disc_number,year:row.year,artist_ids:this.repairArtistIds('tracks',row.id)});
}, },
repairChangeCount() { return this.repairPlan ? this.repairPlan.artists.length + this.repairPlan.releases.length + this.repairPlan.tracks.length : 0; }, repairPreview() {
if (!this.repairPlan) return [];
const rows = [];
for (const edit of this.repairPlan.artists) rows.push({key:'artist:' + edit.id,action:'Rename artist',title:this.repairEntityLabel('artists',edit.id),detail:'→ ' + edit.name});
for (const edit of this.repairPlan.releases) {
const old = edit.id ? this.repairBefore('releases',edit.id) : null;
rows.push({key:'release:' + (edit.id || edit.key),action:old ? 'Edit release' : 'Create release',title:edit.title + (edit.year != null ? ' (' + edit.year + ')' : ''),detail:[old ? 'Before: ' + this.repairEntityLabel('releases',edit.id) + (old.year != null ? ' (' + old.year + ')' : '') : '',edit.release_type,this.repairArtistNames(edit.artist_ids)].filter(Boolean).join(' · ')});
}
for (const edit of this.repairPlan.tracks) {
const old = this.repairBefore('tracks',edit.id);
const moved = old && edit.target_release !== 'existing:' + old.release_id;
const details = [];
if (moved) details.push(this.repairEntityLabel('releases',old.release_id) + ' → ' + (this.repairTargetReleases().find(row => row.value === edit.target_release)?.label || edit.target_release));
if (old && old.title !== edit.title) details.push('Title: ' + old.title + ' → ' + edit.title);
for (const [field,label] of [['track_number','Track number'],['disc_number','Disc'],['year','Year']]) if (old && old[field] !== edit[field]) details.push(label + ': ' + (old[field] ?? '—') + ' → ' + (edit[field] ?? '—'));
if (JSON.stringify(this.repairArtistIds('tracks',edit.id)) !== JSON.stringify(edit.artist_ids)) details.push('Artists: ' + this.repairArtistNames(edit.artist_ids));
rows.push({key:'track:' + edit.id,action:moved ? 'Move track' : 'Edit track',title:edit.title + ' #' + edit.id,detail:details.join('\n')});
}
return rows;
},
repairDeleteCount() { return Object.values(this.repairPlan?.delete || {}).reduce((count,ids) => count + ids.length,0); },
repairChangeCount() { return this.repairPlan ? this.repairPlan.artists.length + this.repairPlan.releases.length + this.repairPlan.tracks.length + this.repairDeleteCount() : 0; },
repairPlanPayload() { repairPlanPayload() {
const plan = JSON.parse(JSON.stringify(this.repairPlan)); const plan = JSON.parse(JSON.stringify(this.repairPlan));
for (const edit of [...plan.releases, ...plan.tracks]) { for (const edit of [...plan.releases, ...plan.tracks]) {
@@ -4590,52 +4691,43 @@ function adminV2() {
async sendRepair() { async sendRepair() {
const instruction = this.repairDraft.trim(); const instruction = this.repairDraft.trim();
if (!instruction || this.repairBusy || !this.repairIncludedCount()) return; if (!instruction || this.repairBusy || !this.repairIncludedCount()) return;
if (!this.repairReference) {
const source = this.repairChat.find(turn => turn.role === 'user' && turn.content.includes('### ') && /^\s*\d+\.\s+\S/m.test(turn.content));
if (source) this.repairReference = source.content;
}
const resuming = this.repairIncomplete && this.repairPendingInstruction === instruction;
if (instruction.includes('### ') && /^\s*\d+\.\s+\S/m.test(instruction)) this.repairReference = instruction; if (instruction.includes('### ') && /^\s*\d+\.\s+\S/m.test(instruction)) this.repairReference = instruction;
if (!resuming) { const resuming = this.repairIncomplete && this.repairPendingInstruction === instruction;
this.repairTrackOffset = 0;
this.repairTrackTotal = 0;
}
this.repairBusy = true; this.repairBusy = true;
this.repairStage = 'thinking'; this.repairStage = 'thinking';
this.repairIncomplete = true; this.repairIncomplete = true;
this.repairPendingInstruction = instruction; this.repairPendingInstruction = instruction;
this.repairTrackTotal = this.repairSelection(true).tracks.length;
this.repairDraft = ''; this.repairDraft = '';
const previous = this.repairChat.slice(-6); const previous = this.repairChat.slice(-20);
if (resuming && previous.at(-1)?.role === 'user' && previous.at(-1).content === instruction) previous.pop();
if (!resuming) this.repairChat.push({role:'user',content:instruction}); if (!resuming) this.repairChat.push({role:'user',content:instruction});
this.scrollRepairChat();
try { try {
if (!this.repairExpanded || this.repairExpandedReference !== this.repairReference) { if (!this.repairExpanded) {
this.repairExpanded = await this.request(`${this.apiBase}/metadata-fix/expand`, {method:'POST',body:JSON.stringify({selection:this.repairSelection(false),reference:this.repairReference || null})}); await this.expandRepairForChat();
this.repairExpandedReference = this.repairReference;
} }
while (true) { const result = await this.request(`${this.apiBase}/metadata-fix/plan`, {method:'POST',body:JSON.stringify({selection:this.repairSelection(true),excluded_track_ids:this.repairExcludedTracks,instruction,reference:this.repairReference || null,primary_artist_ids:this.repairSelected.filter(item => item.kind === 'artists').map(item => item.id),conversation:previous,current_plan:this.repairPlan ? this.repairPlanPayload() : null})});
const result = await this.request(`${this.apiBase}/metadata-fix/plan`, {method:'POST',body:JSON.stringify({selection:this.repairSelection(true),instruction,reference:this.repairReference || null,primary_artist_ids:this.repairSelected.filter(item => item.kind === 'artists').map(item => item.id),conversation:previous,current_plan:this.repairPlan ? this.repairPlanPayload() : null,track_offset:this.repairTrackOffset})}); this.repairPlan = result.plan;
this.repairPlan = result.plan; this.repairSnapshot = result.snapshot;
this.repairSnapshot = result.snapshot; this.repairChat.push({role:'assistant',content:result.message});
this.repairTrackTotal = result.total_tracks; this.repairIncomplete = false;
this.repairTrackOffset = result.next_track_offset ?? result.total_tracks; this.repairPendingInstruction = '';
if (result.next_track_offset == null) { this.repairInstruction = this.repairChat.filter(turn => turn.role === 'user').map(turn => turn.content).join('\n\n').slice(-8000);
this.repairChat.push({role:'assistant',content:result.message});
this.repairIncomplete = false;
this.repairPendingInstruction = '';
break;
}
}
this.repairInstruction = instruction;
} catch (error) { } catch (error) {
this.repairDraft = instruction; this.repairDraft = instruction;
this.showToast(error.message); this.showToast(error.message);
} finally { } finally {
this.repairBusy = false; this.repairBusy = false;
this.repairStage = ''; this.repairStage = '';
this.$nextTick(() => { if (this.$refs.repairChat) this.$refs.repairChat.scrollTop = this.$refs.repairChat.scrollHeight; }); this.scrollRepairChat();
} }
}, },
async expandRepairForChat() {
this.repairExpanded = await this.request(`${this.apiBase}/metadata-fix/expand`, {method:'POST',body:JSON.stringify({selection:this.repairSelection(false),reference:this.repairReference || null})});
},
scrollRepairChat() {
this.$nextTick(() => { if (this.$refs.repairChat) this.$refs.repairChat.scrollTop = this.$refs.repairChat.scrollHeight; });
},
async applyRepair() { async applyRepair() {
if (!this.repairPlan || !this.repairSnapshot || this.repairBusy || this.repairIncomplete || !this.repairChangeCount()) return; if (!this.repairPlan || !this.repairSnapshot || this.repairBusy || this.repairIncomplete || !this.repairChangeCount()) return;
this.repairBusy = true; this.repairBusy = true;
@@ -4643,6 +4735,11 @@ function adminV2() {
try { try {
const result = await this.request(`${this.apiBase}/metadata-fix/apply`, {method:'POST',body:JSON.stringify({snapshot:this.repairSnapshot,plan:this.repairPlanPayload(),instruction:this.repairInstruction})}); const result = await this.request(`${this.apiBase}/metadata-fix/apply`, {method:'POST',body:JSON.stringify({snapshot:this.repairSnapshot,plan:this.repairPlanPayload(),instruction:this.repairInstruction})});
this.showToast('Applied · history #' + result.history_id); this.showToast('Applied · history #' + result.history_id);
this.repairChat.push({role:'assistant',content:'Plan applied · history #' + result.history_id + '. You can undo it from History.'});
this.repairSelected = [];
this.repairIncluded = {};
this.repairExcludedTracks = [];
this.repairIncomplete = false;
this.repairPlan = null; this.repairPlan = null;
this.repairSnapshot = null; this.repairSnapshot = null;
this.repairExpanded = null; this.repairExpanded = null;
@@ -4662,8 +4759,13 @@ function adminV2() {
await this.request(`${this.apiBase}/metadata-fix/undo`, {method:'POST',body:JSON.stringify({history_id:historyId})}); await this.request(`${this.apiBase}/metadata-fix/undo`, {method:'POST',body:JSON.stringify({history_id:historyId})});
await this.loadRepairHistory(); await this.loadRepairHistory();
this.repairExpanded = null; this.repairExpanded = null;
this.repairPlan = null; this.invalidateRepairPlan();
this.repairSelected = [];
this.repairIncluded = {};
this.repairExcludedTracks = [];
this.repairChat.push({role:'assistant',content:'Metadata repair #' + historyId + ' undone.'});
this.showToast('Metadata repair undone'); this.showToast('Metadata repair undone');
await this.loadLibrary(false);
} catch (error) { this.showToast(error.message); } } catch (error) { this.showToast(error.message); }
finally { this.repairBusy = false; } finally { this.repairBusy = false; }
}, },
+130
View File
@@ -0,0 +1,130 @@
const assert = require('node:assert/strict');
const { readFileSync } = require('node:fs');
const { test } = require('node:test');
const vm = require('node:vm');
const template = readFileSync(`${__dirname}/../templates/admin/v2.html`, 'utf8');
const script = template.match(/<script>\s*(function adminV2\(\)[\s\S]*?)<\/script>/)[1];
function createApp() {
const context = vm.createContext({URLSearchParams});
vm.runInContext(script, context);
const app = context.adminV2();
app.showToast = message => { app.toastMessage = message; };
app.$nextTick = fn => fn();
app.$refs = {};
app.repairSelected = [{kind:'artists',id:1,title:'Artist'}];
app.repairExpanded = {snapshot:{artists:[{id:1,name:'Artist'}],releases:[{id:2,title:'#ИЗИРОК',year:2018}],tracks:[{id:3,title:'Actual song',release_id:2}]}};
return app;
}
const emptyPlan = () => ({artists:[],releases:[],tracks:[],questions:[],delete:{artists:[],releases:[],tracks:[]}});
test('deselect all retains related rows and allows selecting only the needed resources', async () => {
const app = createApp();
app.setAllRepairIncluded(false);
assert.equal(app.repairIncludedCount(),0);
assert.equal(app.repairRowsCount(),3);
app.setRepairIncluded('releases',2,true);
app.setRepairIncluded('tracks',3,true);
assert.equal(app.repairIncludedCount(),2);
app.repairDraft = 'Only these';
app.request = async (url,options) => {
assert.ok(url.endsWith('/plan'), 'must not re-expand exclusions');
const body = JSON.parse(options.body);
assert.deepEqual(body.selection,{artists:[],releases:[2],tracks:[3]});
return {plan:emptyPlan(),snapshot:app.repairExpanded.snapshot,message:'Done'};
};
await app.sendRepair();
assert.equal(app.repairChat.length,2);
app.setAllRepairIncluded(true);
assert.equal(app.repairIncludedCount(),3);
});
test('checking only releases includes their contents without selecting the artist', () => {
const app = createApp();
app.setAllRepairIncluded(false);
app.setRepairIncluded('releases',2,true);
assert.deepEqual(JSON.parse(JSON.stringify(app.repairSelection(true))),{artists:[],releases:[2],tracks:[3]});
assert.equal(app.repairIsIncluded('tracks',3),true);
assert.equal(app.repairIsIncluded('artists',1),false);
app.setRepairIncluded('tracks',3,false);
assert.equal(app.repairIsIncluded('tracks',3),false);
assert.deepEqual(JSON.parse(JSON.stringify(app.repairSelection(true))).tracks,[]);
assert.deepEqual(JSON.parse(JSON.stringify(app.repairExcludedTracks)),[3]);
app.setAllRepairIncluded(false);
app.setRepairIncluded('releases',2,true);
assert.equal(app.repairIsIncluded('tracks',3),true);
});
test('explicit track exclusions are sent to planning without re-expanding them', async () => {
const app=createApp();
app.setAllRepairIncluded(false);
app.setRepairIncluded('releases',2,true);
app.setRepairIncluded('tracks',3,false);
app.repairDraft='Edit release only';
app.request=async(url,options)=>{
assert.ok(url.endsWith('/plan'));
const body=JSON.parse(options.body);
assert.deepEqual(body.selection,{artists:[],releases:[2],tracks:[]});
assert.deepEqual(body.excluded_track_ids,[3]);
return {plan:emptyPlan(),snapshot:app.repairExpanded.snapshot,message:'Done'};
};
await app.sendRepair();
});
test('clarification replaces the single plan including removed changes and questions', async () => {
const app = createApp();
app.repairPlan = {...emptyPlan(),delete:{artists:[],releases:[],tracks:[3]},questions:['Which release?']};
app.repairChat = [{role:'user',content:'Delete song'},{role:'assistant',content:'Please review'}];
app.repairPlanOpen = true;
app.repairDraft = 'Keep song, cancel everything';
app.request = async (_url,options) => {
const body=JSON.parse(options.body);
assert.deepEqual(body.current_plan.delete.tracks,[3]);
assert.equal(body.conversation.length,2);
return {plan:emptyPlan(),snapshot:app.repairExpanded.snapshot,message:'Cancelled'};
};
await app.sendRepair();
assert.equal(app.repairChangeCount(),0);
assert.equal(app.repairPlan.questions.length,0);
assert.equal(app.repairPlanOpen,true);
assert.equal(app.repairChat.length,4);
});
test('failed revision preserves prior plan and retry avoids duplicate user messages', async () => {
const app = createApp();
const prior = {...emptyPlan(),delete:{artists:[],releases:[],tracks:[3]}};
app.repairPlan = prior;
app.repairDraft = 'Keep song';
app.request = async () => {throw Error('Offline');};
await app.sendRepair();
assert.equal(app.repairPlan,prior);
assert.equal(app.repairIncomplete,true);
assert.equal(app.repairChat.length,1);
app.request = async (_url,options) => {
assert.equal(JSON.parse(options.body).conversation.length,0);
return {plan:emptyPlan(),snapshot:app.repairExpanded.snapshot,message:'Kept'};
};
await app.sendRepair();
assert.equal(app.repairChat.length,2);
assert.equal(app.repairIncomplete,false);
});
test('incomplete plan cannot apply, deletion-only plan can apply and clears stale selection', async () => {
const app = createApp();
app.repairPlan = {...emptyPlan(),delete:{artists:[],releases:[],tracks:[3]}};
app.repairSnapshot = app.repairExpanded.snapshot;
app.repairIncomplete = true;
app.request = async () => assert.fail('must not apply incomplete plan');
await app.applyRepair();
app.repairIncomplete = false;
app.request = async (url,options) => {
assert.ok(url.endsWith('/apply'));
assert.deepEqual(JSON.parse(options.body).plan.delete.tracks,[3]);
return {history_id:7};
};
app.loadRepairHistory = async () => {};
app.loadLibrary = async () => {};
await app.applyRepair();
assert.equal(app.repairIncludedCount(),0);
assert.equal(app.repairPlan,null);
assert.equal(app.repairChat.at(-1).content.includes('#7'),true);
});
+181
View File
@@ -0,0 +1,181 @@
// Run against a fresh disposable instance with tests/metadata_repair_fixture.sql.
// FURU_REPAIR_TEST_PG must name its disposable PostgreSQL container.
const {chromium}=require(process.env.PLAYWRIGHT_MODULE || 'playwright');
const assert=require('node:assert/strict');
const {readFileSync}=require('node:fs');
const {spawnSync}=require('node:child_process');
const base=process.env.FURU_TEST_URL || 'http://127.0.0.1:3029';
const container=process.env.FURU_REPAIR_TEST_PG || 'furumi-repair-test-pg';
function sql(statement) {
const result=spawnSync('docker',['exec','-i',container,'psql','-U','postgres','-d','furumi_repair_test','-At','-v','ON_ERROR_STOP=1'],{input:statement,encoding:'utf8'});
assert.equal(result.status,0,result.stderr);
return result.stdout.trim();
}
const emptyPlan=()=>({artists:[],releases:[],tracks:[],questions:[],delete:{artists:[],releases:[],tracks:[]}});
(async()=>{
const browser=await chromium.launch({headless:true,executablePath:process.env.CHROME_PATH || '/run/current-system/sw/bin/chromium',args:['--no-sandbox']});
try {
const context=await browser.newContext({viewport:{width:1440,height:1000}});
if (process.env.FURU_TEST_ASSETS) {
for (const [url,file] of [['alpinejs@3/dist/cdn.min.js','alpine.js'],['lucide@latest/dist/umd/lucide.min.js','lucide.js']]) {
await context.route('https://cdn.jsdelivr.net/npm/'+url,route=>route.fulfill({path:process.env.FURU_TEST_ASSETS+'/'+file}));
}
}
const api=context.request;
assert.equal((await api.post(base+'/admin/v2/api/metadata-fix/apply',{data:{snapshot:{},plan:{},instruction:'test'}})).status()>=400,true);
const page=await context.newPage(); const errors=[]; page.on('pageerror',error=>errors.push(error.message));
await page.goto(base+'/admin/setup');
if (page.url().includes('/admin/setup')) {
await page.locator('[name=username]').fill('repair_admin');
await page.locator('[name=password]').fill('repair-test-password');
await page.locator('[name=confirm_password]').fill('repair-test-password');
await page.locator('button[type=submit]').click();
await page.waitForURL('**/admin/v2');
} else {
await page.goto(base+'/login');
await page.locator('[name=username]').fill('repair_admin');
await page.locator('[name=password]').fill('repair-test-password');
await page.locator('button[type=submit]').click();
await page.waitForURL(base+'/');
await page.goto(base+'/admin/v2');
}
if (!process.env.FURU_REPAIR_SKIP_SEED) sql(readFileSync(__dirname+'/metadata_repair_fixture.sql','utf8'));
const post=async(path,data,status=200)=>{
const response=await api.post(base+'/admin/v2/api/metadata-fix/'+path,{data,timeout:240000});
assert.equal(response.status(),status,await response.text());
return response.json();
};
const expanded=await post('expand',{selection:{artists:[2719],releases:[],tracks:[]}});
const before=expanded.snapshot;
assert.equal(before.releases.length,4); assert.equal(before.tracks.length,10);
// Reproduce the reported request using ONLY the four release checkboxes.
if (process.env.FURU_REPAIR_TEST_MODEL) {
const selection={artists:[],releases:before.releases.map(r=>r.id),tracks:[]};
const instruction=`релизы #ИЗИРОК на самом деле один релиз типа компиляция 2021 года. тебе нужно сделать план по объединению в один релиз. вот полный треклист по порядку 01. Старик и братья
02. Потрошитель
03. Последняя песня
04. Песня для твоей подруги
05. Просто я сегодня... (feat. Перегаз)
06. Отзвуки тьмы
07. Битва за Москву
08. Настроение лето
09. Пробил час
10. Цусима`;
const proposed=await post('plan',{selection,instruction});
assert.equal(proposed.snapshot.artists.length,0);
assert.equal(proposed.snapshot.tracks.length,10);
assert.deepEqual(proposed.plan.artists,[]);
assert.deepEqual(proposed.plan.delete.artists,[]);
assert.deepEqual(proposed.plan.delete.tracks,[]);
const destination=proposed.plan.releases.find(r=>r.release_type==='compilation' && r.year===2021);
assert.ok(destination,JSON.stringify(proposed.plan));
const target=destination.id ? 'existing:'+destination.id : 'new:'+destination.key;
for (const [index,track] of before.tracks.entries()) {
const edit=proposed.plan.tracks.find(t=>t.id===track.id);
assert.equal(edit?.target_release || 'existing:'+track.release_id,target);
assert.equal(edit?.track_number ?? track.track_number,index+1);
assert.deepEqual(edit?.artist_ids || [2719],[2719]);
}
const result=await post('apply',{snapshot:proposed.snapshot,plan:proposed.plan,instruction});
assert.equal(sql('SELECT count(*) FROM furumusic__track'),'10');
assert.equal(sql('SELECT count(*) FROM furumusic__release'),'1');
assert.equal(sql('SELECT name FROM furumusic__artist'),'Radio Tapok');
await post('undo',{history_id:result.history_id});
assert.deepEqual((await post('expand',{selection:expanded.selection})).snapshot,before);
const excluded=await post('plan',{selection,excluded_track_ids:[33683],instruction:'Ничего не меняй. Верни пустой план.'});
assert.equal(excluded.snapshot.tracks.length,9);
assert.equal(excluded.snapshot.tracks.some(t=>t.id===33683),false);
assert.deepEqual(excluded.plan.tracks,[]);
const recovered=await post('plan',{selection,instruction:'__TEST_INVALID_ARTIST__ Объедини четыре релиза в компиляцию 2021 года.'});
assert.deepEqual(recovered.plan.artists,[]);
assert.equal(recovered.plan.releases[0].year,2021);
console.log('Release-only scope, exact ordered tracklist, model correction and exclusions passed.');
}
const artistIds=track=>before.track_artists.filter(link=>link.owner_id===track.id).map(link=>link.artist_id);
const merge={...emptyPlan(),releases:[{id:null,key:'collection',title:'#ИЗИРОК Сборник',release_type:'compilation',year:2021,artist_ids:[2719]}],tracks:before.tracks.map(track=>({id:track.id,title:track.title,target_release:'new:collection',track_number:track.track_number,disc_number:track.disc_number,year:track.year,artist_ids:artistIds(track)})),delete:{artists:[],releases:before.releases.map(release=>release.id),tracks:[]}};
await page.getByRole('button',{name:'Library Tools',exact:true}).click();
const tools=page.locator('.content').filter({has:page.getByText('Metadata assistant',{exact:true})});
await tools.locator('select').first().selectOption('artists');
await tools.getByPlaceholder('Search library…').fill('Radio Tapok');
await tools.locator('.repair-search-results button').first().click();
await tools.getByRole('button',{name:'Show related',exact:true}).click();
await page.waitForFunction(()=>Alpine.$data(document.querySelector('.admin-shell')).repairRowsCount()===15);
await tools.getByRole('button',{name:'Deselect all',exact:true}).click();
assert.equal(await tools.locator('.repair-entity input:checked').count(),0);
assert.equal(await tools.locator('.repair-entity input[type=checkbox]').count(),15);
for (const release of before.releases) {
await tools.getByRole('checkbox',{name:new RegExp('^#ИЗИРОК #' + release.id + ' ')}).check();
}
assert.equal(await tools.locator('.repair-entity input:checked').count(),14);
assert.equal(await tools.getByRole('checkbox',{name:'Radio Tapok #2719',exact:true}).isChecked(),false);
let calls=0;
await page.route('**/metadata-fix/plan',async route=>{
const body=route.request().postDataJSON(); calls++;
assert.deepEqual(body.selection,{...expanded.selection,artists:[]});
if (calls===1) await route.fulfill({json:{snapshot:before,plan:merge,message:'Объединю все 10 треков в сборник 2021 года.'}});
else {
assert.equal(body.current_plan.releases[0].year,2021);
assert.equal(body.conversation.length,2);
await route.fulfill({json:{snapshot:before,plan:{...merge,releases:[{...merge.releases[0],year:2022}]},message:'Год сборника изменён на 2022.'}});
}
});
const composer=tools.getByRole('textbox',{name:'Message to metadata assistant'});
await composer.fill('Объедини #ИЗИРОК в #ИЗИРОК Сборник, год 2021');
await tools.getByRole('button',{name:'Send',exact:true}).click();
await tools.getByText('Объединю все 10 треков в сборник 2021 года.',{exact:true}).waitFor();
const plan=tools.locator('details.repair-plan');
assert.equal(await plan.getAttribute('open'),null);
await plan.locator(':scope > summary').click();
await plan.getByText('Edit fields manually',{exact:true}).click();
assert.equal(await plan.locator('.repair-diff').nth(1).locator('input[type=number]').inputValue(),'2021');
await composer.fill('Сделай год 2022');
await tools.getByRole('button',{name:'Send',exact:true}).click();
await tools.getByText('Год сборника изменён на 2022.',{exact:true}).waitFor();
assert.equal(await tools.locator('details.repair-plan').count(),1);
assert.equal(await plan.locator('.repair-diff').nth(1).locator('input[type=number]').inputValue(),'2022');
await plan.getByText('Edit fields manually',{exact:true}).click();
await plan.locator(':scope > summary').scrollIntoViewIfNeeded();
await page.screenshot({path:'/tmp/furumi-repair-desktop.png'});
await page.setViewportSize({width:390,height:844});
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true);
await page.screenshot({path:'/tmp/furumi-repair-mobile.png'});
await page.setViewportSize({width:1440,height:1000});
// Apply the 2021 plan against the original snapshot, then undo it.
const applied=await post('apply',{snapshot:before,plan:merge,instruction:'Merge #ИЗИРОК'});
assert.equal(sql("SELECT title || '|' || year || '|' || total_tracks FROM furumusic__release"),'#ИЗИРОК Сборник|2021|10');
assert.equal(sql('SELECT count(*) FROM furumusic__track'),'10');
assert.equal(sql('SELECT count(*) FROM furumusic__media_file'),'10');
assert.equal(sql('SELECT count(*) FROM furumusic__playlist_track'),'2');
await post('undo',{history_id:applied.history_id});
assert.deepEqual((await post('expand',{selection:expanded.selection})).snapshot,before);
const deletion={...emptyPlan(),delete:{artists:[],releases:[],tracks:[33683,33684]}};
const removed=await post('apply',{snapshot:before,plan:deletion,instruction:'Delete two tracks'});
assert.equal(sql('SELECT count(*) FROM furumusic__track'),'8');
assert.equal(sql('SELECT count(*) FROM furumusic__playlist_track'),'0');
assert.equal(sql('SELECT count(*) FROM furumusic__track_ref WHERE local_track_id IS NULL'),'2');
assert.equal(sql('SELECT queue_json FROM furumusic__playback_state'),'[33685]');
await post('undo',{history_id:removed.history_id});
assert.equal(sql('SELECT count(*) FROM furumusic__playlist_track'),'2');
assert.equal(sql('SELECT local_track_id FROM furumusic__track_ref ORDER BY content_id'),'33683\n33684');
assert.equal(sql('SELECT current_track_id || \'|\' || position_ms || \'|\' || queue_json FROM furumusic__playback_state'),'33683|1234|[33683,33684,33685]');
assert.deepEqual((await post('expand',{selection:expanded.selection})).snapshot,before);
const artistRemoval=await post('apply',{snapshot:before,plan:{...emptyPlan(),delete:{artists:[2719],releases:[],tracks:[]}},instruction:'Delete artist'});
assert.equal(sql('SELECT count(*) FROM furumusic__artist'),'0');
assert.equal(sql('SELECT count(*) FROM furumusic__track'),'10');
assert.equal(sql('SELECT count(*) FROM furumusic__track_artist'),'0');
await post('undo',{history_id:artistRemoval.history_id});
assert.deepEqual((await post('expand',{selection:expanded.selection})).snapshot,before);
const invalid={...emptyPlan(),delete:{artists:[],releases:[4256],tracks:[]}};
await post('apply',{snapshot:before,plan:invalid,instruction:'Invalid deletion'},400);
// A changed detached reference must block undo atomically.
const conflict=await post('apply',{snapshot:before,plan:deletion,instruction:'Delete before playback changes'});
sql("UPDATE furumusic__playback_state SET position_ms=9876");
await post('undo',{history_id:conflict.history_id},409);
assert.equal(sql('SELECT count(*) FROM furumusic__track'),'8');
sql('UPDATE furumusic__playback_state SET position_ms=0');
await post('undo',{history_id:conflict.history_id});
assert.equal(sql('SELECT count(*) FROM furumusic__track'),'10');
assert.deepEqual(errors,[]);
console.log('Metadata Repair browser, merge, deletion, undo and conflict checks passed.');
} finally { await browser.close(); }
})().catch(error=>{console.error(error);process.exit(1);});
+45
View File
@@ -0,0 +1,45 @@
INSERT INTO furumusic__artist (id,name,is_hidden,name_sort,model_name,updated_at,created_at) VALUES (2719,'Radio Tapok',false,'radio tapok','unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K','2026-11-15T23:13:56Z','2026-01-01T00:00:00Z');
INSERT INTO furumusic__release (id,year,title,is_hidden,model_name,title_sort,updated_at,total_discs,release_type,total_tracks,cover_file_id,created_at) VALUES (4256,2018,'#ИЗИРОК',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K','#изирок','2026-11-15T23:25:33Z',NULL,'album',NULL,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__release (id,year,title,is_hidden,model_name,title_sort,updated_at,total_discs,release_type,total_tracks,cover_file_id,created_at) VALUES (4257,2019,'#ИЗИРОК',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K','#изирок','2026-11-15T23:25:34Z',NULL,'album',NULL,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__release (id,year,title,is_hidden,model_name,title_sort,updated_at,total_discs,release_type,total_tracks,cover_file_id,created_at) VALUES (4258,2020,'#ИЗИРОК',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K','#изирок','2026-11-15T23:25:46Z',NULL,'ep',NULL,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__release (id,year,title,is_hidden,model_name,title_sort,updated_at,total_discs,release_type,total_tracks,cover_file_id,created_at) VALUES (4259,2021,'#ИЗИРОК',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K','#изирок','2026-11-15T23:25:47Z',NULL,'ep',NULL,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__media_file (id,file_type,file_path,original_filename,mime_type,file_size_bytes,sha256_hash,created_at) VALUES (33683,'audio','/tmp/test-33683.mp3','test.mp3','audio/mpeg',1,'0000000000000000000000000000000000000000000000000000000000033683','2026-01-01T00:00:00Z');
INSERT INTO furumusic__track (id,year,title,is_hidden,model_name,release_id,title_sort,updated_at,disc_number,track_number,lastfm_rating,lastfm_listeners,lastfm_playcount,lastfm_checked_at,lastfm_updated_at,lastfm_lookup_title,lastfm_lookup_artist,duration_seconds,audio_file_id,cover_file_id,created_at) VALUES (33683,2018,'Старик и братья',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K',4256,'старик и братья','2026-11-15T23:25:32Z',NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,180,33683,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__media_file (id,file_type,file_path,original_filename,mime_type,file_size_bytes,sha256_hash,created_at) VALUES (33684,'audio','/tmp/test-33684.mp3','test.mp3','audio/mpeg',1,'0000000000000000000000000000000000000000000000000000000000033684','2026-01-01T00:00:00Z');
INSERT INTO furumusic__track (id,year,title,is_hidden,model_name,release_id,title_sort,updated_at,disc_number,track_number,lastfm_rating,lastfm_listeners,lastfm_playcount,lastfm_checked_at,lastfm_updated_at,lastfm_lookup_title,lastfm_lookup_artist,duration_seconds,audio_file_id,cover_file_id,created_at) VALUES (33684,2018,'Потрошитель',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K',4256,'потрошитель','2026-11-15T23:25:33Z',NULL,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,180,33684,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__media_file (id,file_type,file_path,original_filename,mime_type,file_size_bytes,sha256_hash,created_at) VALUES (33685,'audio','/tmp/test-33685.mp3','test.mp3','audio/mpeg',1,'0000000000000000000000000000000000000000000000000000000000033685','2026-01-01T00:00:00Z');
INSERT INTO furumusic__track (id,year,title,is_hidden,model_name,release_id,title_sort,updated_at,disc_number,track_number,lastfm_rating,lastfm_listeners,lastfm_playcount,lastfm_checked_at,lastfm_updated_at,lastfm_lookup_title,lastfm_lookup_artist,duration_seconds,audio_file_id,cover_file_id,created_at) VALUES (33685,2018,'Последняя песня',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K',4256,'последняя песня','2026-11-15T23:25:33Z',NULL,3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,180,33685,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__media_file (id,file_type,file_path,original_filename,mime_type,file_size_bytes,sha256_hash,created_at) VALUES (33686,'audio','/tmp/test-33686.mp3','test.mp3','audio/mpeg',1,'0000000000000000000000000000000000000000000000000000000000033686','2026-01-01T00:00:00Z');
INSERT INTO furumusic__track (id,year,title,is_hidden,model_name,release_id,title_sort,updated_at,disc_number,track_number,lastfm_rating,lastfm_listeners,lastfm_playcount,lastfm_checked_at,lastfm_updated_at,lastfm_lookup_title,lastfm_lookup_artist,duration_seconds,audio_file_id,cover_file_id,created_at) VALUES (33686,2018,'Песня для твоей подруги',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K',4256,'песня для твоей подруги','2026-11-15T23:25:33Z',NULL,4,NULL,NULL,NULL,NULL,NULL,NULL,NULL,180,33686,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__media_file (id,file_type,file_path,original_filename,mime_type,file_size_bytes,sha256_hash,created_at) VALUES (33687,'audio','/tmp/test-33687.mp3','test.mp3','audio/mpeg',1,'0000000000000000000000000000000000000000000000000000000000033687','2026-01-01T00:00:00Z');
INSERT INTO furumusic__track (id,year,title,is_hidden,model_name,release_id,title_sort,updated_at,disc_number,track_number,lastfm_rating,lastfm_listeners,lastfm_playcount,lastfm_checked_at,lastfm_updated_at,lastfm_lookup_title,lastfm_lookup_artist,duration_seconds,audio_file_id,cover_file_id,created_at) VALUES (33687,2018,'Просто я сегодня...',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K',4256,'просто я сегодня...','2026-11-15T23:25:33Z',NULL,5,NULL,NULL,NULL,NULL,NULL,NULL,NULL,180,33687,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__media_file (id,file_type,file_path,original_filename,mime_type,file_size_bytes,sha256_hash,created_at) VALUES (33688,'audio','/tmp/test-33688.mp3','test.mp3','audio/mpeg',1,'0000000000000000000000000000000000000000000000000000000000033688','2026-01-01T00:00:00Z');
INSERT INTO furumusic__track (id,year,title,is_hidden,model_name,release_id,title_sort,updated_at,disc_number,track_number,lastfm_rating,lastfm_listeners,lastfm_playcount,lastfm_checked_at,lastfm_updated_at,lastfm_lookup_title,lastfm_lookup_artist,duration_seconds,audio_file_id,cover_file_id,created_at) VALUES (33688,2019,'Отзвуки тьмы',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K',4257,'отзвуки тьмы','2026-11-15T23:25:34Z',NULL,6,NULL,NULL,NULL,NULL,NULL,NULL,NULL,180,33688,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__media_file (id,file_type,file_path,original_filename,mime_type,file_size_bytes,sha256_hash,created_at) VALUES (33689,'audio','/tmp/test-33689.mp3','test.mp3','audio/mpeg',1,'0000000000000000000000000000000000000000000000000000000000033689','2026-01-01T00:00:00Z');
INSERT INTO furumusic__track (id,year,title,is_hidden,model_name,release_id,title_sort,updated_at,disc_number,track_number,lastfm_rating,lastfm_listeners,lastfm_playcount,lastfm_checked_at,lastfm_updated_at,lastfm_lookup_title,lastfm_lookup_artist,duration_seconds,audio_file_id,cover_file_id,created_at) VALUES (33689,2019,'Битва за Москву',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K',4257,'битва за москву','2026-11-15T23:25:34Z',NULL,7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,180,33689,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__media_file (id,file_type,file_path,original_filename,mime_type,file_size_bytes,sha256_hash,created_at) VALUES (33690,'audio','/tmp/test-33690.mp3','test.mp3','audio/mpeg',1,'0000000000000000000000000000000000000000000000000000000000033690','2026-01-01T00:00:00Z');
INSERT INTO furumusic__track (id,year,title,is_hidden,model_name,release_id,title_sort,updated_at,disc_number,track_number,lastfm_rating,lastfm_listeners,lastfm_playcount,lastfm_checked_at,lastfm_updated_at,lastfm_lookup_title,lastfm_lookup_artist,duration_seconds,audio_file_id,cover_file_id,created_at) VALUES (33690,2020,'Настроение лето',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K',4258,'настроение лето','2026-11-15T23:25:46Z',NULL,8,NULL,NULL,NULL,NULL,NULL,NULL,NULL,180,33690,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__media_file (id,file_type,file_path,original_filename,mime_type,file_size_bytes,sha256_hash,created_at) VALUES (33691,'audio','/tmp/test-33691.mp3','test.mp3','audio/mpeg',1,'0000000000000000000000000000000000000000000000000000000000033691','2026-01-01T00:00:00Z');
INSERT INTO furumusic__track (id,year,title,is_hidden,model_name,release_id,title_sort,updated_at,disc_number,track_number,lastfm_rating,lastfm_listeners,lastfm_playcount,lastfm_checked_at,lastfm_updated_at,lastfm_lookup_title,lastfm_lookup_artist,duration_seconds,audio_file_id,cover_file_id,created_at) VALUES (33691,2020,'Пробил час',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K',4258,'пробил час','2026-11-15T23:25:47Z',NULL,9,NULL,NULL,NULL,NULL,NULL,NULL,NULL,180,33691,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__media_file (id,file_type,file_path,original_filename,mime_type,file_size_bytes,sha256_hash,created_at) VALUES (33692,'audio','/tmp/test-33692.mp3','test.mp3','audio/mpeg',1,'0000000000000000000000000000000000000000000000000000000000033692','2026-01-01T00:00:00Z');
INSERT INTO furumusic__track (id,year,title,is_hidden,model_name,release_id,title_sort,updated_at,disc_number,track_number,lastfm_rating,lastfm_listeners,lastfm_playcount,lastfm_checked_at,lastfm_updated_at,lastfm_lookup_title,lastfm_lookup_artist,duration_seconds,audio_file_id,cover_file_id,created_at) VALUES (33692,2021,'Цусима',false,'unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q6_K',4259,'цусима','2026-11-15T23:25:47Z',NULL,10,NULL,NULL,NULL,NULL,NULL,NULL,NULL,180,33692,NULL,'2026-01-01T00:00:00Z');
INSERT INTO furumusic__release_artist (release_id,artist_id,position) VALUES (4256,2719,0);
INSERT INTO furumusic__release_artist (release_id,artist_id,position) VALUES (4257,2719,0);
INSERT INTO furumusic__release_artist (release_id,artist_id,position) VALUES (4258,2719,0);
INSERT INTO furumusic__release_artist (release_id,artist_id,position) VALUES (4259,2719,0);
INSERT INTO furumusic__track_artist (track_id,artist_id,role,position) VALUES (33683,2719,'main',0);
INSERT INTO furumusic__track_artist (track_id,artist_id,role,position) VALUES (33684,2719,'main',0);
INSERT INTO furumusic__track_artist (track_id,artist_id,role,position) VALUES (33685,2719,'main',0);
INSERT INTO furumusic__track_artist (track_id,artist_id,role,position) VALUES (33686,2719,'main',0);
INSERT INTO furumusic__track_artist (track_id,artist_id,role,position) VALUES (33687,2719,'main',0);
INSERT INTO furumusic__track_artist (track_id,artist_id,role,position) VALUES (33688,2719,'main',0);
INSERT INTO furumusic__track_artist (track_id,artist_id,role,position) VALUES (33689,2719,'main',0);
INSERT INTO furumusic__track_artist (track_id,artist_id,role,position) VALUES (33690,2719,'main',0);
INSERT INTO furumusic__track_artist (track_id,artist_id,role,position) VALUES (33691,2719,'main',0);
INSERT INTO furumusic__track_artist (track_id,artist_id,role,position) VALUES (33692,2719,'main',0);
INSERT INTO furumusic__playlist (id,owner_id,title,is_public,created_at,updated_at) VALUES (1,1,'Repair test',false,'2026-01-01T00:00:00Z','2026-01-01T00:00:00Z');
INSERT INTO furumusic__playlist_track (playlist_id,track_id,position,added_at,added_by_user_id) VALUES (1,33683,0,'2026-01-01T00:00:00Z',1);
INSERT INTO furumusic__track_ref (content_id,local_track_id,title,created_at,updated_at) VALUES ('content-33683',33683,'Старик и братья','2026-01-01T00:00:00Z','2026-01-01T00:00:00Z');
INSERT INTO furumusic__playlist_track (playlist_id,track_id,position,added_at,added_by_user_id) VALUES (1,33684,1,'2026-01-01T00:00:00Z',1);
INSERT INTO furumusic__track_ref (content_id,local_track_id,title,created_at,updated_at) VALUES ('content-33684',33684,'Потрошитель','2026-01-01T00:00:00Z','2026-01-01T00:00:00Z');
INSERT INTO furumusic__playback_state (user_id,current_track_id,position_ms,queue_json,queue_position,shuffle,repeat_mode,volume,updated_at) VALUES (1,33683,1234,'[33683,33684,33685]',0,false,'off',1.0,'2026-01-01T00:00:00Z');