diff --git a/data/users/warren.sqlite b/data/users/warren.sqlite index 85b386c..bcbf0c1 100644 Binary files a/data/users/warren.sqlite and b/data/users/warren.sqlite differ diff --git a/src/page.html b/src/page.html index 561d1d3..cbe0d33 100644 --- a/src/page.html +++ b/src/page.html @@ -717,11 +717,12 @@ function renderGrid(d,mode){ // DETAIL PANEL function showDetail(fuuid){ if(!fuuid)return; + var userId=localStorage.getItem("tree_user")||"demo"; document.getElementById("mb-overlay").style.display="block"; document.getElementById("mb-detail").style.display="block"; var b=document.getElementById("mb-detail-body"); b.innerHTML="
Loading...
"; - fetch("/api/v2/files/"+fuuid+"/info").then(function(r){return r.json()}).then(function(d){ + fetch("/api/v2/files/"+userId+"/"+fuuid+"/info").then(function(r){return r.json()}).then(function(d){ var node=_td&&_td.nodes?_td.nodes.find(function(n){return n.file_uuid==fuuid}):null; var label=node?dname(node):fuuid; var sz=node?fsize(node.file_size):"-"; diff --git a/src/scan.rs b/src/scan.rs index 48f18be..b270a7c 100644 --- a/src/scan.rs +++ b/src/scan.rs @@ -224,6 +224,18 @@ pub fn scan_directory(user_id: &str, dir: &str, batch_size: usize, options: Scan for node in file_nodes { insert_node(&conn, &node)?; + + if let Some(ref file_uuid) = node.file_uuid { + let path = node.aliases.get("path").cloned().unwrap_or_default(); + if !path.is_empty() { + conn.execute( + "INSERT OR IGNORE INTO file_locations (file_uuid, location, label, added_at) + VALUES (?1, ?2, 'origin', ?3)", + rusqlite::params![file_uuid, path, chrono::Utc::now().timestamp().to_string()], + )?; + } + } + inserted += 1; if inserted % batch_size == 0 { diff --git a/src/server.rs b/src/server.rs index 43f4f47..0ce9cc4 100644 --- a/src/server.rs +++ b/src/server.rs @@ -144,9 +144,9 @@ let state = AppState { patch(update_alias), ) .route("/api/v2/modes", get(get_modes)) - .route("/api/v2/files/:file_uuid/info", get(get_file_info)) - .route("/api/v2/files/:file_uuid/probe", get(get_file_probe)) - .route("/api/v2/files/:file_uuid/stream", get(stream_file)) + .route("/api/v2/files/:user_id/:file_uuid/info", get(get_file_info)) + .route("/api/v2/files/:user_id/:file_uuid/probe", get(get_file_probe)) + .route("/api/v2/files/:user_id/:file_uuid/stream", get(stream_file)) .route( "/api/v2/files/:file_uuid/locations", post(add_file_location), @@ -1076,9 +1076,11 @@ async fn unregister_file(Path(file_uuid): Path) -> impl IntoResponse { } } -async fn get_file_info(Path(file_uuid): Path) -> impl IntoResponse { +async fn get_file_info( + 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 conn = FileTree::open_user_db(&user_id)?; FileTree::get_file_info(&conn, &file_uuid) }) .await; @@ -1098,14 +1100,16 @@ async fn get_file_info(Path(file_uuid): Path) -> impl IntoResponse { } } -async fn stream_file(Path(file_uuid): Path) -> impl IntoResponse { +async fn stream_file( + Path((user_id, file_uuid)): Path<(String, String)>, +) -> impl IntoResponse { use axum::body::Body; use axum::http::header; use tokio_util::io::ReaderStream; let (path, mime) = match tokio::task::spawn_blocking(move || -> anyhow::Result<(String, String)> { - let conn = FileTree::open_user_db("demo")?; + let conn = FileTree::open_user_db(&user_id)?; let location: String = conn.query_row( "SELECT location FROM file_locations WHERE file_uuid = ?1 ORDER BY added_at LIMIT 1", [&file_uuid],