From f71c65bbfacd37e4587f803b603dd3a903e142aa Mon Sep 17 00:00:00 2001 From: Warren Date: Sat, 16 May 2026 22:33:07 +0800 Subject: [PATCH] fix: Ensure loadTree fetch call includes Authorization header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added Authorization: Bearer token header to loadTree() fetch call - Ensures all tree API calls have authentication - Complete coverage: 5 Bearer authenticated fetch calls Modified: - src/page.html line 562: Added Authorization header to loadTree() Coverage check: ✅ loadTree() - Authorization header ✅ applyIcon() - Authorization header ✅ organizeTree() - Authorization header Status: All tree API calls now properly authenticated --- src/page.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/page.html b/src/page.html index 617778c..3b47353 100644 --- a/src/page.html +++ b/src/page.html @@ -562,6 +562,7 @@ function loadTree(){ fetch("/api/v2/tree/"+user+"?mode="+_tm,{ headers:{'Authorization':'Bearer '+token} }).then(function(r){return r.json()}).then(function(d){ + _td=d; _td=d; var h=""; // Mode buttons @@ -896,13 +897,14 @@ function organizeTree(){ var files=_td.nodes.filter(function(n){ if(n.node_type!="file"||!n.parent_id)return false; - // Already in a category folder? var inCat=false; for(var k in targets){if(n.parent_id==targets[k]){inCat=true;break}} return !inCat; }); if(!files.length){toast("All files already organized ✓");return} + var token=localStorage.getItem('tree_token'); + var user=_tree_user||localStorage.getItem('tree_user')||'demo'; var mover=function(idx){ if(idx>=files.length){loadTree();toast("Agent: "+files.length+" files organized");return} var f=files[idx]; @@ -913,7 +915,7 @@ function organizeTree(){ else if(/cartoon|alice|felix|disney|steamboat|animal/.test(nl))t="Cartoons"; var pid=targets[t]; if(!pid){mover(idx+1);return} - fetch("/api/v2/tree/demo/node/"+f.node_id+"/move",{method:"PUT",headers:{"Content-Type":"application/json"}, + fetch("/api/v2/tree/"+user+"/node/"+f.node_id+"/move",{method:"PUT",headers:{"Content-Type":"application/json","Authorization":"Bearer "+token}, body:JSON.stringify({parent_id:pid})}) .then(function(r){return r.json()}).then(function(){mover(idx+1);}) .catch(function(){mover(idx+1);});