From 576ba579b7e6211d394da921be5c6aa2af768189 Mon Sep 17 00:00:00 2001 From: Araozu Date: Thu, 30 Nov 2023 14:25:45 -0500 Subject: [PATCH] [BE][Scans] Fixes #29: Don't throw error if a QR is not found --- backend/src/controller/scans/mod.rs | 41 +++++----- frontend/src/utils/carnetGenerator.ts | 105 -------------------------- 2 files changed, 20 insertions(+), 126 deletions(-) delete mode 100644 frontend/src/utils/carnetGenerator.ts diff --git a/backend/src/controller/scans/mod.rs b/backend/src/controller/scans/mod.rs index f840225..20c5bfb 100644 --- a/backend/src/controller/scans/mod.rs +++ b/backend/src/controller/scans/mod.rs @@ -13,7 +13,7 @@ use std::{ const SCAN_PATH: &str = "/srv/srv/shares/eegsac/ESCANEOS/"; /// Represents the result of parsing a QR code, and look for an eegsac URL. -/// +/// /// When the frontend requests the list of files available for conversion, this /// is sent. It contains essentially a unix timestamp #[derive(Serialize, Deserialize)] @@ -125,32 +125,32 @@ fn get_details_from_paths(paths: Vec) -> Vec { /// Actually detects the QR data from a file. /// Reads the file, looks for a QR & return info about this process -/// +/// /// Here 3 things may happen: -/// +/// /// - QR found -/// +/// /// The URL is parsed to get the person DNI & certificate id. -/// +/// /// The file in disk is renamed to `eeg_.jpg` -/// +/// /// The timestamp, DNI & cert id (if found) are sent to FE -/// +/// /// - QR not found -/// -/// The file in disk is renamed to `eeg_.jpg`, and this timestamp is sent to FE -/// +/// +/// The file in disk is renamed to `eeg_.jpg`, and this timestamp is sent to FE +/// /// - Error finding QR -/// +/// /// An error is returned -/// +/// /// ## File renaming -/// +/// /// The processed files are renamed to `eeg_.jpg` and sent to the FE. -/// +/// /// Later on, the FE will send back this information, and another function in this /// file will use the timestamps to read the JPGs, and do the conversion to PDF. -/// +/// /// This is done so that there's no race conditions. If 2 persons call this function at /// the same time, only the last one will have the valid timestamps. fn get_image_info(path: PathBuf) -> ScanInfo { @@ -189,7 +189,6 @@ fn get_image_info(path: PathBuf) -> ScanInfo { // if the image is not thresholded, it may fail more often let results = bardecoder::default_decoder().decode(&thresholded_image); - // If no QR is detected, only rename if results.is_empty() { log::info!("QR not found"); @@ -212,7 +211,8 @@ fn get_image_info(path: PathBuf) -> ScanInfo { Ok(url) => url, Err(reason) => { log::error!("Error decoding qr: {:?}", reason); - return ScanInfo::Error("Error recuperando QR.".into()); + // Here there was a problem aligning the QR. Assume no QR + return ScanInfo::Empty(current_ms.to_string()); } }; @@ -274,9 +274,8 @@ fn get_image_info(path: PathBuf) -> ScanInfo { } } - /// Converts a list of files into PDFs. -/// +/// /// Uses the timestamps inside `data` to read the correct JPG files and convert them. async fn convert_scans_from_data(data: &Vec) -> Result<(), String> { // Get a tuple with all the DNIs & iids. @@ -415,8 +414,8 @@ fn convert_to_pdf(image_path: &PathBuf, output_path: &PathBuf) -> Result<(), Str .arg("0.05") .arg("-quality") .arg("75%") - // .arg("-rotate") - // .arg("270") + .arg("-rotate") + .arg("270") .arg(image_path) .arg(output_path) .spawn(); diff --git a/frontend/src/utils/carnetGenerator.ts b/frontend/src/utils/carnetGenerator.ts deleted file mode 100644 index bbd71f4..0000000 --- a/frontend/src/utils/carnetGenerator.ts +++ /dev/null @@ -1,105 +0,0 @@ -export function genCarnet(d: { - fullname: string, - dni: string, - code: string, - expiryMonth: string, - expiryYear: string, - qrBase64: string, -}) { - const { fullname, dni, code, expiryMonth, expiryYear, qrBase64 } = d; - - return ` - - - - - ${fullname.toUpperCase()} - - - DNI: ${dni} - - - ${code}-${expiryYear}-EEG - - - ${code}-${expiryYear}-EEG - - - ${expiryMonth.toUpperCase()} ${parseInt(expiryYear, 10) + 1} - - - `; -}