chore: translate all Spanish comments and log messages to English

This commit is contained in:
Dionisio
2026-02-12 09:41:25 +01:00
parent bc169de8f6
commit d31a413e57
89 changed files with 2480 additions and 2482 deletions
+47 -47
View File
@@ -13,47 +13,47 @@ use crate::{
};
use std::sync::Arc;
/// Error relacionado con la creación de archivos ZIP
/// Error related to ZIP file creation
#[derive(Debug, Error)]
pub enum ZipError {
#[error("Error de IO: {0}")]
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Error de ZIP: {0}")]
#[error("ZIP error: {0}")]
ZipError(#[from] zip::result::ZipError),
#[error("Error al leer el archivo: {0}")]
#[error("Error reading file: {0}")]
FileReadError(String),
#[error("Error al obtener contenido de carpeta: {0}")]
#[error("Error getting folder contents: {0}")]
FolderContentsError(String),
#[error("Carpeta no encontrada: {0}")]
#[error("Folder not found: {0}")]
FolderNotFound(String),
}
// Implementar From<ZipError> para DomainError para permitir el uso de ?
// Implement From<ZipError> for DomainError to allow the use of ?
impl From<ZipError> for DomainError {
fn from(err: ZipError) -> Self {
DomainError::new(ErrorKind::InternalError, "zip_service", err.to_string())
}
}
// Implementar From<zip::result::ZipError> para DomainError directamente
// Implement From<zip::result::ZipError> for DomainError directly
impl From<zip::result::ZipError> for DomainError {
fn from(err: zip::result::ZipError) -> Self {
DomainError::new(ErrorKind::InternalError, "zip_service", err.to_string())
}
}
/// Servicio para crear archivos ZIP
/// Service for creating ZIP files
pub struct ZipService {
file_service: Arc<dyn FileRetrievalUseCase>,
folder_service: Arc<dyn FolderUseCase>,
}
impl ZipService {
/// Crea una nueva instancia del servicio ZIP con una referencia al servicio de archivos
/// Creates a new instance of the ZIP service with a reference to the file service
pub fn new(file_service: Arc<dyn FileRetrievalUseCase>, folder_service: Arc<dyn FolderUseCase>) -> Self {
Self {
file_service,
@@ -61,33 +61,33 @@ impl ZipService {
}
}
/// Crea un archivo ZIP con el contenido de una carpeta y todas sus subcarpetas
/// Retorna los bytes del ZIP
/// Creates a ZIP file with the contents of a folder and all its subfolders
/// Returns the ZIP bytes
pub async fn create_folder_zip(&self, folder_id: &str, folder_name: &str) -> Result<Vec<u8>> {
info!("Creando ZIP para carpeta: {} (ID: {})", folder_name, folder_id);
info!("Creating ZIP for folder: {} (ID: {})", folder_name, folder_id);
// Verificar si la carpeta existe
// Verify if the folder exists
let folder = match self.folder_service.get_folder(folder_id).await {
Ok(folder) => folder,
Err(e) => {
error!("Error al obtener carpeta {}: {}", folder_id, e);
error!("Error getting folder {}: {}", folder_id, e);
return Err(ZipError::FolderNotFound(folder_id.to_string()).into());
}
};
// Crear un buffer en memoria para el ZIP
// Create an in-memory buffer for the ZIP
let buf = Cursor::new(Vec::new());
let mut zip = ZipWriter::new(buf);
// Establecer opciones de compresión
// Set compression options
let options = SimpleFileOptions::default()
.compression_method(zip::CompressionMethod::Deflated)
.unix_permissions(0o755);
// Objeto para seguir las carpetas procesadas y evitar ciclos
// Object to track processed folders and avoid cycles
let mut processed_folders = std::collections::HashSet::new();
// Procesamos la carpeta raíz y construimos el ZIP
// Process the root folder and build the ZIP
self.process_folder_recursively(
&mut zip,
&folder,
@@ -96,20 +96,20 @@ impl ZipService {
&mut processed_folders
).await?;
// Finalizar el ZIP y obtener los bytes
// Finalize the ZIP and get the bytes
let mut zip_buf = zip.finish()?;
let mut bytes = Vec::new();
match zip_buf.read_to_end(&mut bytes) {
Ok(_) => Ok(bytes),
Err(e) => {
error!("Error al leer ZIP finalizado: {}", e);
error!("Error reading finalized ZIP: {}", e);
Err(ZipError::IoError(e).into())
}
}
}
// Implementación alternativa para evitar recursión en async
// Alternative implementation to avoid recursion in async
async fn process_folder_recursively(
&self,
zip: &mut ZipWriter<Cursor<Vec<u8>>>,
@@ -118,63 +118,63 @@ impl ZipService {
options: &SimpleFileOptions,
processed_folders: &mut std::collections::HashSet<String>
) -> Result<()> {
// Estructura para representar el trabajo pendiente
// Structure to represent pending work
struct PendingFolder {
folder: FolderDto,
path: String,
}
// Cola de trabajo para procesamiento iterativo
// Work queue for iterative processing
let mut work_queue = vec![PendingFolder {
folder: folder.clone(),
path: path.to_string(),
}];
// Procesar la cola mientras haya elementos
// Process the queue while there are elements
while let Some(current) = work_queue.pop() {
let folder_id = current.folder.id.to_string();
// Evitar ciclos
// Avoid cycles
if processed_folders.contains(&folder_id) {
continue;
}
processed_folders.insert(folder_id.clone());
// Crear la entrada de directorio en el ZIP
// Create the directory entry in the ZIP
let folder_path = format!("{}/", current.path);
match zip.add_directory(&folder_path, *options) {
Ok(_) => debug!("Carpeta agregada al ZIP: {}", folder_path),
Ok(_) => debug!("Folder added to ZIP: {}", folder_path),
Err(e) => {
warn!("No se pudo agregar carpeta al ZIP (puede que ya exista): {}", e);
// Continuamos aunque falle crear el directorio (podría estar duplicado)
warn!("Could not add folder to ZIP (it may already exist): {}", e);
// Continue even if creating the directory fails (it could be a duplicate)
}
}
// Agregar archivos de la carpeta al ZIP
// Add files from the folder to the ZIP
let files = match self.file_service.list_files(Some(&folder_id)).await {
Ok(files) => files,
Err(e) => {
error!("Error al listar archivos en carpeta {}: {}", folder_id, e);
return Err(ZipError::FolderContentsError(format!("Error al listar archivos: {}", e)).into());
error!("Error listing files in folder {}: {}", folder_id, e);
return Err(ZipError::FolderContentsError(format!("Error listing files: {}", e)).into());
}
};
// Agregar cada archivo al ZIP
// Add each file to the ZIP
for file in files {
self.add_file_to_zip(zip, &file, &folder_path, options).await?;
}
// Procesar subcarpetas
// Process subfolders
let subfolders = match self.folder_service.list_folders(Some(&folder_id)).await {
Ok(folders) => folders,
Err(e) => {
error!("Error al listar subcarpetas en {}: {}", folder_id, e);
return Err(ZipError::FolderContentsError(format!("Error al listar subcarpetas: {}", e)).into());
error!("Error listing subfolders in {}: {}", folder_id, e);
return Err(ZipError::FolderContentsError(format!("Error listing subfolders: {}", e)).into());
}
};
// Agregar subcarpetas a la cola
// Add subfolders to the queue
for subfolder in subfolders {
let subfolder_path = format!("{}/{}", current.path, subfolder.name);
work_queue.push(PendingFolder {
@@ -187,7 +187,7 @@ impl ZipService {
Ok(())
}
// Agrega un archivo al ZIP
// Adds a file to the ZIP
async fn add_file_to_zip(
&self,
zip: &mut ZipWriter<Cursor<Vec<u8>>>,
@@ -196,34 +196,34 @@ impl ZipService {
options: &SimpleFileOptions,
) -> Result<()> {
let file_path = format!("{}{}", folder_path, file.name);
info!("Agregando archivo al ZIP: {}", file_path);
info!("Adding file to ZIP: {}", file_path);
// Obtener el contenido del archivo
// Get the file content
let file_id = file.id.to_string();
let content = match self.file_service.get_file_content(&file_id).await {
Ok(content) => content,
Err(e) => {
error!("Error al leer contenido del archivo {}: {}", file_id, e);
return Err(ZipError::FileReadError(format!("Error al leer archivo {}: {}", file_id, e)).into());
error!("Error reading file content {}: {}", file_id, e);
return Err(ZipError::FileReadError(format!("Error reading file {}: {}", file_id, e)).into());
}
};
// Escribir archivo al ZIP
// Write file to the ZIP
match zip.start_file_from_path(std::path::Path::new(&file_path), *options) {
Ok(_) => {
match zip.write_all(&content) {
Ok(_) => {
debug!("Archivo agregado al ZIP: {}", file_path);
debug!("File added to ZIP: {}", file_path);
Ok(())
},
Err(e) => {
error!("Error al escribir contenido del archivo {}: {}", file_path, e);
error!("Error writing file content {}: {}", file_path, e);
Err(ZipError::IoError(e).into())
}
}
},
Err(e) => {
error!("Error al iniciar archivo en ZIP {}: {}", file_path, e);
error!("Error starting file in ZIP {}: {}", file_path, e);
Err(ZipError::ZipError(e).into())
}
}