From cb337fd4637b6e3db5e6a6c34fb0ba52a1ae3b49 Mon Sep 17 00:00:00 2001 From: Honey Date: Sun, 26 Apr 2026 01:42:59 +0200 Subject: [PATCH] fix: playlist cover upload via PUT /api/playlist/{id} with base64 imageData Navidrome (react-admin) expects image as base64 data URL in JSON body, not as a raw binary POST to /image endpoint. Bump SW to ns-v35. Co-Authored-By: Claude Sonnet 4.6 --- app.js | 10 ++++++---- sw.js | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index 59a13f9..436f397 100644 --- a/app.js +++ b/app.js @@ -505,11 +505,13 @@ async function editPlCoverSelected(input){ const preview=URL.createObjectURL(file); document.getElementById('edit-pl-cover').innerHTML=``; try{ + const imageData=await new Promise((res,rej)=>{const r=new FileReader();r.onload=()=>res(r.result);r.onerror=rej;r.readAsDataURL(file);}); const token=await ndAuth(); - const res=await fetch(`${cfg.url}/api/playlist/${_currentPlaylist.id}/image`,{ - method:'POST', - headers:{'X-Nd-Authorization':'Bearer '+token,'Content-Type':file.type||'image/jpeg'}, - body:file + const pl=_currentPlaylist; + const res=await fetch(`${cfg.url}/api/playlist/${pl.id}`,{ + method:'PUT', + headers:{'X-Nd-Authorization':'Bearer '+token,'Content-Type':'application/json'}, + body:JSON.stringify({name:pl.name,comment:pl.comment||'',public:!!pl.public,imageData}) }); if(!res.ok)throw new Error(res.status); toast('Cover aktualisiert'); diff --git a/sw.js b/sw.js index 10022b7..c5ff3b0 100644 --- a/sw.js +++ b/sw.js @@ -1,4 +1,4 @@ -const CACHE = 'ns-v34'; +const CACHE = 'ns-v35'; const PRECACHE = ['/', 'index.html', 'styles.css', 'app.js', 'manifest.json', 'icon.svg']; const SKIP_PATHS = ['/rest/stream', '/rest/download', '/config.js'];