fix: Add user_id to stream and probe API calls

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)
This commit is contained in:
Warren
2026-05-17 04:53:07 +08:00
parent 89aa4989da
commit ce4f0602c8
3 changed files with 8 additions and 4 deletions

Binary file not shown.

View File

@@ -749,7 +749,8 @@ function showDetail(fuuid){
}else h+="<div style=color:#64748b>—</div>";
h+="<h3>🔍 Probe Data <span id=mb-probe-status style=font-size:11px;color:#64748b>loading...</span></h3><div id=mb-probe-data style=color:#64748b>Loading...</div>";
h+="<h3>🖼️ Preview <span style=font-size:12px;color:#94a3b8>"+label+"</span> <span id=mb-preview-res style=font-size:12px;color:#64748b></span></h3><div style=margin-top:8px;position:relative;display:flex;align-items:center;gap:8px>";
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";

View File

@@ -1186,7 +1186,9 @@ async fn stream_file(
}
}
async fn get_file_probe(Path(file_uuid): Path<String>) -> 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<serde_json::Value> {
let conn = FileTree::open_user_db("demo")?;
let node: Option<(Option<String>, Option<String>)> = conn