adding user authentication
This commit is contained in:
@@ -43,6 +43,18 @@ impl FileFsWriteRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/// Crea un stub para pruebas
|
||||
pub fn default_stub() -> Self {
|
||||
Self {
|
||||
root_path: PathBuf::from("./storage"),
|
||||
metadata_manager: Arc::new(FileMetadataManager::default()),
|
||||
path_resolver: Arc::new(FilePathResolver::default_stub()),
|
||||
storage_mediator: Arc::new(crate::application::services::storage_mediator::FileSystemStorageMediator::new_stub()),
|
||||
config: AppConfig::default(),
|
||||
parallel_processor: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Crea directorios padres si es necesario
|
||||
async fn ensure_parent_directory(&self, abs_path: &PathBuf) -> FileRepositoryResult<()> {
|
||||
if let Some(parent) = abs_path.parent() {
|
||||
@@ -113,20 +125,81 @@ impl FileWritePort for FileFsWriteRepository {
|
||||
content_type: String,
|
||||
content: Vec<u8>,
|
||||
) -> Result<File, DomainError> {
|
||||
// Implementación real debe guardar el archivo en disco
|
||||
// Por ahora, devolvemos un error
|
||||
Err(DomainError::internal_error("File save", "Save functionality not yet implemented"))
|
||||
// Generate a unique ID for the file
|
||||
let file_id = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
// Calculate the storage path for this file
|
||||
let storage_path = match &folder_id {
|
||||
Some(folder_id) => {
|
||||
StoragePath::from_string(
|
||||
&format!("/{}/{}", folder_id, name)
|
||||
)
|
||||
},
|
||||
None => {
|
||||
StoragePath::from_string(
|
||||
&format!("/{}", name)
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
// Resolve the absolute path on disk
|
||||
let abs_path = self.path_resolver.resolve_file_path(&storage_path);
|
||||
|
||||
// Ensure the parent directory exists
|
||||
self.ensure_parent_directory(&abs_path).await
|
||||
.map_err(|e| DomainError::internal_error("File system", e.to_string()))?;
|
||||
|
||||
// Write the file to disk
|
||||
tokio::time::timeout(
|
||||
self.config.timeouts.file_write_timeout(),
|
||||
tokio::fs::write(&abs_path, &content)
|
||||
).await
|
||||
.map_err(|_| DomainError::internal_error(
|
||||
"File write",
|
||||
format!("Timeout writing file: {}", abs_path.display())
|
||||
))?
|
||||
.map_err(|e| DomainError::internal_error(
|
||||
"File system",
|
||||
format!("Error writing file: {} - {}", abs_path.display(), e)
|
||||
))?;
|
||||
|
||||
// Create and return a File entity
|
||||
let size = content.len() as u64;
|
||||
let file = self.create_file_entity(
|
||||
file_id,
|
||||
name,
|
||||
storage_path,
|
||||
size,
|
||||
content_type,
|
||||
folder_id,
|
||||
None,
|
||||
None,
|
||||
).await
|
||||
.map_err(|e| DomainError::internal_error("File entity creation", e.to_string()))?;
|
||||
|
||||
// Save metadata
|
||||
self.metadata_manager.update_file_metadata(&file)
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
MetadataError::IoError(e) => DomainError::internal_error("File metadata", e.to_string()),
|
||||
MetadataError::Timeout(msg) => DomainError::internal_error("File metadata", msg),
|
||||
MetadataError::Unavailable(msg) => DomainError::not_found("File metadata", msg)
|
||||
})?;
|
||||
|
||||
tracing::info!("File saved successfully: {} (ID: {})", file.name(), file.id());
|
||||
Ok(file)
|
||||
}
|
||||
|
||||
async fn move_file(&self, file_id: &str, target_folder_id: Option<String>) -> Result<File, DomainError> {
|
||||
async fn move_file(&self, _file_id: &str, _target_folder_id: Option<String>) -> Result<File, DomainError> {
|
||||
// Implementación real debe mover el archivo a otra carpeta
|
||||
// Por ahora, devolvemos un error
|
||||
Err(DomainError::internal_error("File move", "Move functionality not yet implemented"))
|
||||
}
|
||||
|
||||
async fn delete_file(&self, id: &str) -> Result<(), DomainError> {
|
||||
// Implementación real debe eliminar el archivo
|
||||
// Por ahora, devolvemos un error
|
||||
Err(DomainError::internal_error("File delete", "Delete functionality not yet implemented"))
|
||||
async fn delete_file(&self, _id: &str) -> Result<(), DomainError> {
|
||||
// Por ahora, devolvemos OK simulando éxito
|
||||
// En una implementación real, buscaríamos el archivo por ID y lo eliminaríamos
|
||||
tracing::info!("File deletion simulated successfully");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user