d94cb2df4c
- Fix trailing whitespace in kex.rs and s3.rs - Add missing KexProposal import in kex_complete.rs - Auto-fix clippy warnings across all crates - All 153 tests pass
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
use axum::{
|
|
extract::Path,
|
|
http::StatusCode,
|
|
response::{IntoResponse, Json},
|
|
};
|
|
use serde_json::json;
|
|
use std::path::PathBuf;
|
|
|
|
use crate::download::storage;
|
|
|
|
pub async fn list_uploaded_files(Path(user_id): Path<String>) -> impl IntoResponse {
|
|
let file_list = storage::scan_uploaded_files(&user_id);
|
|
(StatusCode::OK, Json(file_list))
|
|
}
|
|
|
|
pub async fn get_file_info(Path((user_id, filename)): Path<(String, String)>) -> impl IntoResponse {
|
|
let base_path = format!("/Users/accusys/Downloads/{}", user_id);
|
|
let file_path = PathBuf::from(&base_path).join(&filename);
|
|
|
|
if !file_path.exists() {
|
|
return (
|
|
StatusCode::NOT_FOUND,
|
|
Json(json!({"error": "File not found"})),
|
|
)
|
|
.into_response();
|
|
}
|
|
|
|
let metadata = std::fs::metadata(&file_path).unwrap();
|
|
let file_size = metadata.len();
|
|
let file_hash = if file_size > 0 {
|
|
storage::compute_file_hash(&file_path).ok()
|
|
} else {
|
|
Some("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855".to_string())
|
|
};
|
|
|
|
(
|
|
StatusCode::OK,
|
|
Json(json!({
|
|
"filename": filename,
|
|
"file_size": file_size,
|
|
"file_hash": file_hash,
|
|
"file_path": file_path.to_string_lossy(),
|
|
"user_id": user_id
|
|
})),
|
|
)
|
|
.into_response()
|
|
}
|