fix: resolve clippy warnings (unused mut, from_str, result_large_err)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,10 +6,11 @@
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use crate::application::ports::storage_ports::FileReadPort;
|
use crate::application::ports::storage_ports::{FileReadPort, FileWritePort};
|
||||||
use crate::common::errors::DomainError;
|
use crate::common::errors::DomainError;
|
||||||
use crate::domain::entities::file::File;
|
use crate::domain::entities::file::File;
|
||||||
use crate::domain::services::path_service::StoragePath;
|
use crate::domain::services::path_service::StoragePath;
|
||||||
@@ -117,6 +118,10 @@ impl FileReadPort for MockFileReadPort {
|
|||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_folder_id_by_path(&self, _folder_path: &str) -> Result<String, DomainError> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
async fn stream_files_in_subtree(
|
async fn stream_files_in_subtree(
|
||||||
&self,
|
&self,
|
||||||
_folder_id: &str,
|
_folder_id: &str,
|
||||||
@@ -125,6 +130,115 @@ impl FileReadPort for MockFileReadPort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Minimal mock write port — only `move_file` and `rename_file` need real logic.
|
||||||
|
struct MockFileWritePort {
|
||||||
|
files: Mutex<HashMap<String, File>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MockFileWritePort {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
files: Mutex::new(HashMap::new()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert(&self, id: &str, name: &str) {
|
||||||
|
let file = File::new(
|
||||||
|
id.to_string(),
|
||||||
|
name.to_string(),
|
||||||
|
StoragePath::from_string(&format!("/{}", name)),
|
||||||
|
42,
|
||||||
|
"text/plain".to_string(),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
self.files.lock().unwrap().insert(id.to_string(), file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FileWritePort for MockFileWritePort {
|
||||||
|
async fn save_file_from_temp(
|
||||||
|
&self,
|
||||||
|
_name: String,
|
||||||
|
_folder_id: Option<String>,
|
||||||
|
_content_type: String,
|
||||||
|
_temp_path: &Path,
|
||||||
|
_size: u64,
|
||||||
|
_pre_computed_hash: Option<String>,
|
||||||
|
) -> Result<File, DomainError> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn move_file(
|
||||||
|
&self,
|
||||||
|
file_id: &str,
|
||||||
|
_target_folder_id: Option<String>,
|
||||||
|
) -> Result<File, DomainError> {
|
||||||
|
let files = self.files.lock().unwrap();
|
||||||
|
files
|
||||||
|
.get(file_id)
|
||||||
|
.cloned()
|
||||||
|
.ok_or_else(|| DomainError::not_found("File", file_id.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn rename_file(&self, file_id: &str, _new_name: &str) -> Result<File, DomainError> {
|
||||||
|
let files = self.files.lock().unwrap();
|
||||||
|
files
|
||||||
|
.get(file_id)
|
||||||
|
.cloned()
|
||||||
|
.ok_or_else(|| DomainError::not_found("File", file_id.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete_file(&self, _id: &str) -> Result<(), DomainError> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn update_file_content_from_temp(
|
||||||
|
&self,
|
||||||
|
_file_id: &str,
|
||||||
|
_temp_path: &Path,
|
||||||
|
_size: u64,
|
||||||
|
_content_type: Option<String>,
|
||||||
|
_pre_computed_hash: Option<String>,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn register_file_deferred(
|
||||||
|
&self,
|
||||||
|
_name: String,
|
||||||
|
_folder_id: Option<String>,
|
||||||
|
_content_type: String,
|
||||||
|
_size: u64,
|
||||||
|
) -> Result<(File, PathBuf), DomainError> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn copy_file(
|
||||||
|
&self,
|
||||||
|
_file_id: &str,
|
||||||
|
_target_folder_id: Option<String>,
|
||||||
|
) -> Result<File, DomainError> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn move_to_trash(&self, _file_id: &str) -> Result<(), DomainError> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn restore_from_trash(
|
||||||
|
&self,
|
||||||
|
_file_id: &str,
|
||||||
|
_original_path: &str,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete_file_permanently(&self, _file_id: &str) -> Result<(), DomainError> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
// Tests — FileReadPort::get_file_for_owner (Repository layer, Solution C)
|
// Tests — FileReadPort::get_file_for_owner (Repository layer, Solution C)
|
||||||
// ═══════════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub mod wopi_token_service;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod idor_protection_test;
|
mod idor_protection_test;
|
||||||
#[cfg(all(test, integration_tests))]
|
#[cfg(test)]
|
||||||
mod trash_service_test;
|
mod trash_service_test;
|
||||||
|
|
||||||
// Re-exportar para facilitar acceso
|
// Re-exportar para facilitar acceso
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ pub fn nextcloud_routes_with_state(state: Arc<AppState>) -> Router<Arc<AppState>
|
|||||||
// ──────────────── Handler glue ────────────────
|
// ──────────────── Handler glue ────────────────
|
||||||
|
|
||||||
/// Reject requests where the URL `{user}` doesn't match the authenticated user.
|
/// Reject requests where the URL `{user}` doesn't match the authenticated user.
|
||||||
|
#[allow(clippy::result_large_err)]
|
||||||
fn verify_url_user(url_user: &str, auth_user: &CurrentUser) -> Result<(), Response> {
|
fn verify_url_user(url_user: &str, auth_user: &CurrentUser) -> Result<(), Response> {
|
||||||
if url_user != auth_user.username {
|
if url_user != auth_user.username {
|
||||||
Err(StatusCode::FORBIDDEN.into_response())
|
Err(StatusCode::FORBIDDEN.into_response())
|
||||||
|
|||||||
@@ -480,7 +480,7 @@ async fn handle_put(
|
|||||||
.unwrap_or("application/octet-stream")
|
.unwrap_or("application/octet-stream")
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let oc_mtime = req
|
let _oc_mtime = req
|
||||||
.headers()
|
.headers()
|
||||||
.get("x-oc-mtime")
|
.get("x-oc-mtime")
|
||||||
.and_then(|v| v.to_str().ok())
|
.and_then(|v| v.to_str().ok())
|
||||||
@@ -507,7 +507,7 @@ async fn handle_put(
|
|||||||
|
|
||||||
// Re-fetch for etag.
|
// Re-fetch for etag.
|
||||||
if let Ok(updated) = file_service.get_file_by_path(&internal_path).await {
|
if let Ok(updated) = file_service.get_file_by_path(&internal_path).await {
|
||||||
let mut builder = Response::builder()
|
let builder = Response::builder()
|
||||||
.status(StatusCode::NO_CONTENT)
|
.status(StatusCode::NO_CONTENT)
|
||||||
.header(header::ETAG, format!("\"{}\"", updated.id))
|
.header(header::ETAG, format!("\"{}\"", updated.id))
|
||||||
.header("oc-etag", format!("\"{}\"", updated.id));
|
.header("oc-etag", format!("\"{}\"", updated.id));
|
||||||
@@ -534,7 +534,7 @@ async fn handle_put(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| AppError::internal_error(format!("Failed to create file: {}", e)))?;
|
.map_err(|e| AppError::internal_error(format!("Failed to create file: {}", e)))?;
|
||||||
|
|
||||||
let mut builder = Response::builder()
|
let builder = Response::builder()
|
||||||
.status(StatusCode::CREATED)
|
.status(StatusCode::CREATED)
|
||||||
.header(header::ETAG, format!("\"{}\"", file_dto.id))
|
.header(header::ETAG, format!("\"{}\"", file_dto.id))
|
||||||
.header("oc-etag", format!("\"{}\"", file_dto.id));
|
.header("oc-etag", format!("\"{}\"", file_dto.id));
|
||||||
|
|||||||
Reference in New Issue
Block a user