[BE][Scans] Fixes #29: Don't throw error if a QR is not found

This commit is contained in:
Araozu 2023-11-30 14:25:45 -05:00
parent cead15a33d
commit 576ba579b7
2 changed files with 20 additions and 126 deletions

View File

@ -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<PathBuf>) -> Vec<ScanInfo> {
/// 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_<timestamp>.jpg`
///
///
/// The timestamp, DNI & cert id (if found) are sent to FE
///
///
/// - QR not found
///
/// The file in disk is renamed to `eeg_<timestamp>.jpg`, and this timestamp is sent to FE
///
///
/// The file in disk is renamed to `eeg_<timestamp>.jpg`, and this timestamp is sent to FE
///
/// - Error finding QR
///
///
/// An error is returned
///
///
/// ## File renaming
///
///
/// The processed files are renamed to `eeg_<timestamp>.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<ScanInfo>) -> 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();

File diff suppressed because one or more lines are too long