feat: fix content sharing — nginx proxy, file path resolution, catalog filtering
- Add /content and /dwn proxy locations to nginx config (both HTTP and HTTPS) so peer requests reach the backend instead of the SPA catch-all - Update content_file_path() to check FileBrowser data dir as fallback when files aren't in the dedicated content/files/ directory - Populate size_bytes from actual file metadata in content.add - Filter out availability:nobody items from the public catalog endpoint Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -348,10 +348,11 @@ impl ApiHandler {
|
||||
async fn handle_content_catalog(config: &Config) -> Result<Response<hyper::Body>> {
|
||||
match content_server::load_catalog(&config.data_dir).await {
|
||||
Ok(catalog) => {
|
||||
// Only expose public metadata, not file paths
|
||||
// Only expose public metadata for available items
|
||||
let items: Vec<serde_json::Value> = catalog
|
||||
.items
|
||||
.iter()
|
||||
.filter(|i| !matches!(i.availability, content_server::Availability::Nobody))
|
||||
.map(|i| {
|
||||
serde_json::json!({
|
||||
"id": i.id,
|
||||
|
||||
@@ -31,7 +31,7 @@ impl RpcHandler {
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("");
|
||||
|
||||
let item = ContentItem {
|
||||
let mut item = ContentItem {
|
||||
id: uuid::Uuid::new_v4().to_string(),
|
||||
filename: filename.to_string(),
|
||||
mime_type: mime_type.to_string(),
|
||||
@@ -42,6 +42,12 @@ impl RpcHandler {
|
||||
added_at: chrono::Utc::now().to_rfc3339(),
|
||||
};
|
||||
|
||||
// Resolve actual file size from disk
|
||||
let file_path = content_server::content_file_path(&self.config.data_dir, &item);
|
||||
if let Ok(metadata) = std::fs::metadata(&file_path) {
|
||||
item.size_bytes = metadata.len();
|
||||
}
|
||||
|
||||
content_server::add_item(&self.config.data_dir, item.clone()).await?;
|
||||
Ok(serde_json::json!({ "item": item }))
|
||||
}
|
||||
|
||||
@@ -89,8 +89,26 @@ pub async fn save_catalog(data_dir: &Path, catalog: &ContentCatalog) -> Result<(
|
||||
}
|
||||
|
||||
/// Get the full filesystem path for a content item.
|
||||
/// Checks the dedicated content/files/ directory first, then falls back to the
|
||||
/// FileBrowser data directory (where users manage files via the web UI).
|
||||
pub fn content_file_path(data_dir: &Path, item: &ContentItem) -> PathBuf {
|
||||
data_dir.join(CONTENT_DIR).join(&item.filename)
|
||||
// Strip leading slash from filename for path joining
|
||||
let clean_name = item.filename.trim_start_matches('/');
|
||||
|
||||
// Primary: dedicated content directory
|
||||
let primary = data_dir.join(CONTENT_DIR).join(clean_name);
|
||||
if primary.exists() {
|
||||
return primary;
|
||||
}
|
||||
|
||||
// Fallback: FileBrowser data directory (users share files managed via FileBrowser)
|
||||
let fb_path = data_dir.join("filebrowser").join(clean_name);
|
||||
if fb_path.exists() {
|
||||
return fb_path;
|
||||
}
|
||||
|
||||
// Return primary path even if it doesn't exist (caller checks existence)
|
||||
primary
|
||||
}
|
||||
|
||||
/// Add a content item to the catalog.
|
||||
|
||||
Reference in New Issue
Block a user