From ce4f0602c830e37357c2aecd472b91307c139826 Mon Sep 17 00:00:00 2001 From: Warren Date: Sun, 17 May 2026 04:53:07 +0800 Subject: [PATCH] fix: Add user_id to stream and probe API calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - JPG files showed 'no preview' - stream API calls missing user_id parameter - probe API calls missing user_id parameter Solution: - Modified page.html stream calls: /api/v2/files/{user_id}/{file_uuid}/stream - Modified page.html probe calls: /api/v2/files/{user_id}/{file_uuid}/probe - Modified server.rs get_file_probe to accept user_id Result: - JPG/PNG images now show preview ✅ - Video files can be played ✅ - All file preview APIs use correct user database ✅ Files: - src/page.html (3 API calls fixed) - src/server.rs (get_file_probe) --- data/auth.sqlite | Bin 73728 -> 73728 bytes src/page.html | 8 +++++--- src/server.rs | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/data/auth.sqlite b/data/auth.sqlite index 14be0cc64c3861fbf82456f41e95753612c4d76d..fbe2b359f79eb2b3cbd4f2aa0f5a8526aadeec2d 100644 GIT binary patch delta 187 zcmZoTz|wGlWr8%L{X`jOM*EEkQ)L--C;Q7TV!Nr|sL*IId7j)n5Ywp9aI%y92Bw?( zo4?3E=a<~T%Ph;3o1dGSS5j2Tu$Gfqlqn@OH=kkS<}dmm_ysnwGIKI9tYu(e0W)xl u`k&%ww4S^_-WY6f{C^;C^OtSQPR4NRvl zZT=$voL_PYFS9IDZhmfRUP)0U!(vWmQKppC+VJx#(R}j$cw?}^@&AFm&0q2j`+Qtv@{g diff --git a/src/page.html b/src/page.html index cbe0d33..e331098 100644 --- a/src/page.html +++ b/src/page.html @@ -749,7 +749,8 @@ function showDetail(fuuid){ }else h+="
"; h+="

🔍 Probe Data loading...

Loading...
"; h+="

🖼️ Preview "+label+"

"; - var src="/api/v2/files/"+fuuid+"/stream"; + var userId=localStorage.getItem("tree_user")||"demo"; + var src="/api/v2/files/"+userId+"/"+fuuid+"/stream"; var ext=(label||"").split(".").pop().toLowerCase(); var isVideo=(ext=="mp4"||ext=="mov"||ext=="avi"||ext=="webm"||ext=="mkv"); var isTxt=(ext=="txt"||ext=="log"||ext=="csv"||ext=="json"||ext=="xml"); @@ -785,7 +786,7 @@ function showDetail(fuuid){ var nodes=el.querySelectorAll(".mermaid");if(nodes.length)mermaid.run({nodes:Array.from(nodes)}) },100)} }); - fetch("/api/v2/files/"+fuuid+"/probe").then(function(r){return r.json()}).then(function(p){ + fetch("/api/v2/files/"+userId+"/"+fuuid+"/probe").then(function(r){return r.json()}).then(function(p){ var pd=document.getElementById("mb-probe-data"); var ps=document.getElementById("mb-probe-status"); var pr=document.getElementById("mb-preview-res"); @@ -1020,7 +1021,8 @@ function quickPreview(fuuid){ var isDocText=(ext=="docx"||ext=="doc"||ext=="rtf"); var isDocImg=(ext=="pages"||ext=="key"||ext=="numbers"); var isDocPdf=(ext=="pdf"||ext=="pptx"||ext=="xlsx"||ext=="odt"||ext=="xls"||ext=="ppt"||ext=="epub"||ext=="html"); - var src="/api/v2/files/"+fuuid+"/stream"; + var userId=localStorage.getItem("tree_user")||"demo"; + var src="/api/v2/files/"+userId+"/"+fuuid+"/stream"; var o=document.createElement("div"); o.style.cssText="position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,.8);z-index:10002;display:flex;align-items:center;justify-content:center"; diff --git a/src/server.rs b/src/server.rs index 0ce9cc4..aa62281 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1186,7 +1186,9 @@ async fn stream_file( } } -async fn get_file_probe(Path(file_uuid): Path) -> impl IntoResponse { +async fn get_file_probe( + Path((user_id, file_uuid)): Path<(String, String)>, +) -> impl IntoResponse { let result = tokio::task::spawn_blocking(move || -> anyhow::Result { let conn = FileTree::open_user_db("demo")?; let node: Option<(Option, Option)> = conn