fix: resolve all clippy warnings and enforce cargo fmt
- display_helpers: convert module doc-comments to regular comments, merge identical text/markdown + text/ branches - search_service: replace needless range loops with slice-based pagination - folder_repository, folder_db_repository: collapse nested if statements - favorites_pg_repository: remove unnecessary borrow on generic arg - file_blob_read_repository: collapse 6 nested if-let blocks - file_blob_write_repository: collapse nested if for dedup ref decrement - chunked_upload_service: use div_ceil(), collapse 2 nested if blocks - folder_handler: collapse nested if-let for owner check - webdav_handler: replace 7x io::Error::new(ErrorKind::Other, ..) with io::Error::other(..) - cargo fmt applied to all files Passes: cargo clippy --all-targets --all-features -- -D warnings
This commit is contained in:
@@ -476,13 +476,8 @@ impl FileHandler {
|
||||
Ok((_file, content)) => match content {
|
||||
OptimizedFileContent::Bytes {
|
||||
data, mime_type, ..
|
||||
} => Self::build_cached_response(
|
||||
data,
|
||||
&mime_type,
|
||||
&disposition,
|
||||
&etag,
|
||||
)
|
||||
.into_response(),
|
||||
} => Self::build_cached_response(data, &mime_type, &disposition, &etag)
|
||||
.into_response(),
|
||||
OptimizedFileContent::Mmap(mmap_data) => Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header(header::CONTENT_TYPE, &file_dto.mime_type)
|
||||
@@ -566,10 +561,8 @@ impl FileHandler {
|
||||
|
||||
tracing::info!("Found {} files", files.len());
|
||||
let mut resp = (StatusCode::OK, Json(files)).into_response();
|
||||
resp.headers_mut().insert(
|
||||
header::ETAG,
|
||||
header::HeaderValue::from_str(&etag).unwrap(),
|
||||
);
|
||||
resp.headers_mut()
|
||||
.insert(header::ETAG, header::HeaderValue::from_str(&etag).unwrap());
|
||||
resp
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -601,7 +594,11 @@ impl FileHandler {
|
||||
};
|
||||
|
||||
// Generate thumbnails for supported images in background
|
||||
if state.core.thumbnail_service.is_supported_image(&file.mime_type) {
|
||||
if state
|
||||
.core
|
||||
.thumbnail_service
|
||||
.is_supported_image(&file.mime_type)
|
||||
{
|
||||
let file_id = file.id.clone();
|
||||
let file_path_rel = file.path.clone();
|
||||
let thumbnail_service = state.core.thumbnail_service.clone();
|
||||
|
||||
@@ -89,17 +89,16 @@ impl FolderHandler {
|
||||
match service.get_folder(&id).await {
|
||||
Ok(folder) => {
|
||||
// Access check: folder must belong to the requesting user
|
||||
if let Some(ref owner) = folder.owner_id {
|
||||
if owner != &auth_user.id {
|
||||
tracing::warn!(
|
||||
"get_folder: user '{}' attempted to access folder '{}' owned by '{}'",
|
||||
auth_user.id,
|
||||
id,
|
||||
owner
|
||||
);
|
||||
return (StatusCode::NOT_FOUND, "Folder not found".to_string())
|
||||
.into_response();
|
||||
}
|
||||
if let Some(ref owner) = folder.owner_id
|
||||
&& owner != &auth_user.id
|
||||
{
|
||||
tracing::warn!(
|
||||
"get_folder: user '{}' attempted to access folder '{}' owned by '{}'",
|
||||
auth_user.id,
|
||||
id,
|
||||
owner
|
||||
);
|
||||
return (StatusCode::NOT_FOUND, "Folder not found".to_string()).into_response();
|
||||
}
|
||||
(StatusCode::OK, Json(folder)).into_response()
|
||||
}
|
||||
@@ -198,8 +197,13 @@ impl FolderHandler {
|
||||
|
||||
/// Compute a lightweight ETag from the maximum `modified_at` timestamp
|
||||
/// and item count. No body buffering required.
|
||||
fn compute_listing_etag(folders: &[crate::application::dtos::folder_dto::FolderDto], files: &[crate::application::dtos::file_dto::FileDto]) -> String {
|
||||
let max_mod = folders.iter().map(|f| f.modified_at)
|
||||
fn compute_listing_etag(
|
||||
folders: &[crate::application::dtos::folder_dto::FolderDto],
|
||||
files: &[crate::application::dtos::file_dto::FileDto],
|
||||
) -> String {
|
||||
let max_mod = folders
|
||||
.iter()
|
||||
.map(|f| f.modified_at)
|
||||
.chain(files.iter().map(|f| f.modified_at))
|
||||
.max()
|
||||
.unwrap_or(0);
|
||||
@@ -249,10 +253,8 @@ impl FolderHandler {
|
||||
|
||||
let listing = FolderListingDto { folders, files };
|
||||
let mut resp = (StatusCode::OK, Json(listing)).into_response();
|
||||
resp.headers_mut().insert(
|
||||
header::ETAG,
|
||||
header::HeaderValue::from_str(&etag).unwrap(),
|
||||
);
|
||||
resp.headers_mut()
|
||||
.insert(header::ETAG, header::HeaderValue::from_str(&etag).unwrap());
|
||||
resp
|
||||
}
|
||||
(Err(err), _) | (_, Err(err)) => {
|
||||
@@ -441,10 +443,7 @@ impl FolderHandler {
|
||||
}
|
||||
};
|
||||
|
||||
tracing::info!(
|
||||
"ZIP file created successfully, size: {} bytes",
|
||||
file_size
|
||||
);
|
||||
tracing::info!("ZIP file created successfully, size: {} bytes", file_size);
|
||||
|
||||
// Split the NamedTempFile into the already-open std File
|
||||
// and the TempPath (auto-deletes on drop). This reuses
|
||||
|
||||
@@ -284,13 +284,8 @@ async fn handle_propfind(
|
||||
let mut xml_writer = Writer::new(&mut buf);
|
||||
WebDavAdapter::write_multistatus_start(&mut xml_writer)
|
||||
.map_err(|e| AppError::internal_error(format!("XML write error: {}", e)))?;
|
||||
WebDavAdapter::write_file_entry(
|
||||
&mut xml_writer,
|
||||
&file,
|
||||
&propfind_request,
|
||||
&base_href,
|
||||
)
|
||||
.map_err(|e| AppError::internal_error(format!("XML write error: {}", e)))?;
|
||||
WebDavAdapter::write_file_entry(&mut xml_writer, &file, &propfind_request, &base_href)
|
||||
.map_err(|e| AppError::internal_error(format!("XML write error: {}", e)))?;
|
||||
WebDavAdapter::write_multistatus_end(&mut xml_writer)
|
||||
.map_err(|e| AppError::internal_error(format!("XML write error: {}", e)))?;
|
||||
}
|
||||
@@ -329,9 +324,9 @@ async fn build_streaming_propfind_response(
|
||||
{
|
||||
let mut w = Writer::new(&mut buf);
|
||||
WebDavAdapter::write_multistatus_start(&mut w)
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
.map_err(|e| std::io::Error::other(e.to_string()))?;
|
||||
WebDavAdapter::write_folder_entry(&mut w, &folder, &propfind_request, &base_href)
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
.map_err(|e| std::io::Error::other(e.to_string()))?;
|
||||
}
|
||||
yield Bytes::from(buf);
|
||||
|
||||
@@ -353,7 +348,7 @@ async fn build_streaming_propfind_response(
|
||||
let result = folder_service
|
||||
.list_folders_paginated(fid_ref, &pag)
|
||||
.await
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
.map_err(|e| std::io::Error::other(e.to_string()))?;
|
||||
|
||||
if result.items.is_empty() {
|
||||
break;
|
||||
@@ -365,7 +360,7 @@ async fn build_streaming_propfind_response(
|
||||
for subfolder in &result.items {
|
||||
let href = format!("{}{}/", base_href, subfolder.name);
|
||||
WebDavAdapter::write_folder_entry(&mut w, subfolder, &propfind_request, &href)
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
.map_err(|e| std::io::Error::other(e.to_string()))?;
|
||||
}
|
||||
}
|
||||
let has_more = result.pagination.has_next;
|
||||
@@ -383,7 +378,7 @@ async fn build_streaming_propfind_response(
|
||||
let batch: Vec<FileDto> = file_retrieval_service
|
||||
.list_files_batch(fid_ref, offset, PROPFIND_BATCH_SIZE)
|
||||
.await
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
.map_err(|e| std::io::Error::other(e.to_string()))?;
|
||||
|
||||
if batch.is_empty() {
|
||||
break;
|
||||
@@ -396,7 +391,7 @@ async fn build_streaming_propfind_response(
|
||||
for file in &batch {
|
||||
let href = format!("{}{}", base_href, file.name);
|
||||
WebDavAdapter::write_file_entry(&mut w, file, &propfind_request, &href)
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
.map_err(|e| std::io::Error::other(e.to_string()))?;
|
||||
}
|
||||
}
|
||||
yield Bytes::from(chunk);
|
||||
@@ -413,13 +408,14 @@ async fn build_streaming_propfind_response(
|
||||
{
|
||||
let mut w = Writer::new(&mut buf);
|
||||
WebDavAdapter::write_multistatus_end(&mut w)
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
.map_err(|e| std::io::Error::other(e.to_string()))?;
|
||||
}
|
||||
yield Bytes::from(buf);
|
||||
};
|
||||
|
||||
use futures::TryStreamExt;
|
||||
let stream = stream.map_err(|e: std::io::Error| -> Box<dyn std::error::Error + Send + Sync> { Box::new(e) });
|
||||
let stream = stream
|
||||
.map_err(|e: std::io::Error| -> Box<dyn std::error::Error + Send + Sync> { Box::new(e) });
|
||||
|
||||
Ok(Response::builder()
|
||||
.status(StatusCode::MULTI_STATUS)
|
||||
@@ -453,7 +449,9 @@ async fn handle_proppatch(
|
||||
// Read request body (XML — bounded to 1 MB)
|
||||
let body_bytes = body::to_bytes(req.into_body(), MAX_XML_BODY)
|
||||
.await
|
||||
.map_err(|e| AppError::payload_too_large(format!("PROPPATCH body too large or unreadable: {}", e)))?;
|
||||
.map_err(|e| {
|
||||
AppError::payload_too_large(format!("PROPPATCH body too large or unreadable: {}", e))
|
||||
})?;
|
||||
let (props_to_set, props_to_remove) = WebDavAdapter::parse_proppatch(body_bytes.reader())
|
||||
.map_err(|e| AppError::bad_request(format!("Failed to parse PROPPATCH request: {}", e)))?;
|
||||
|
||||
@@ -661,12 +659,13 @@ async fn handle_put(
|
||||
)));
|
||||
}
|
||||
hasher.update(chunk);
|
||||
file.write_all(chunk)
|
||||
.await
|
||||
.map_err(|e| AppError::internal_error(format!("Failed to write to temp file: {}", e)))?;
|
||||
file.write_all(chunk).await.map_err(|e| {
|
||||
AppError::internal_error(format!("Failed to write to temp file: {}", e))
|
||||
})?;
|
||||
}
|
||||
}
|
||||
file.flush().await
|
||||
file.flush()
|
||||
.await
|
||||
.map_err(|e| AppError::internal_error(format!("Failed to flush temp file: {}", e)))?;
|
||||
drop(file);
|
||||
|
||||
@@ -1109,10 +1108,7 @@ async fn handle_copy(
|
||||
.create_folder(create_dto)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
AppError::internal_error(format!(
|
||||
"Failed to create destination folder: {}",
|
||||
e
|
||||
))
|
||||
AppError::internal_error(format!("Failed to create destination folder: {}", e))
|
||||
})?;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -13,7 +13,7 @@ use axum::{
|
||||
Router,
|
||||
body::Body,
|
||||
extract::{Path, Query, State},
|
||||
http::{HeaderMap, StatusCode, Request},
|
||||
http::{HeaderMap, Request, StatusCode},
|
||||
response::{Html, IntoResponse, Response},
|
||||
routing::{get, post},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user