[BE][Scans] Fixes #29: Don't throw error if a QR is not found
This commit is contained in:
parent
cead15a33d
commit
576ba579b7
@ -13,7 +13,7 @@ use std::{
|
|||||||
const SCAN_PATH: &str = "/srv/srv/shares/eegsac/ESCANEOS/";
|
const SCAN_PATH: &str = "/srv/srv/shares/eegsac/ESCANEOS/";
|
||||||
|
|
||||||
/// Represents the result of parsing a QR code, and look for an eegsac URL.
|
/// 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
|
/// When the frontend requests the list of files available for conversion, this
|
||||||
/// is sent. It contains essentially a unix timestamp
|
/// is sent. It contains essentially a unix timestamp
|
||||||
#[derive(Serialize, Deserialize)]
|
#[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.
|
/// Actually detects the QR data from a file.
|
||||||
/// Reads the file, looks for a QR & return info about this process
|
/// Reads the file, looks for a QR & return info about this process
|
||||||
///
|
///
|
||||||
/// Here 3 things may happen:
|
/// Here 3 things may happen:
|
||||||
///
|
///
|
||||||
/// - QR found
|
/// - QR found
|
||||||
///
|
///
|
||||||
/// The URL is parsed to get the person DNI & certificate id.
|
/// The URL is parsed to get the person DNI & certificate id.
|
||||||
///
|
///
|
||||||
/// The file in disk is renamed to `eeg_<timestamp>.jpg`
|
/// The file in disk is renamed to `eeg_<timestamp>.jpg`
|
||||||
///
|
///
|
||||||
/// The timestamp, DNI & cert id (if found) are sent to FE
|
/// The timestamp, DNI & cert id (if found) are sent to FE
|
||||||
///
|
///
|
||||||
/// - QR not found
|
/// - 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
|
/// - Error finding QR
|
||||||
///
|
///
|
||||||
/// An error is returned
|
/// An error is returned
|
||||||
///
|
///
|
||||||
/// ## File renaming
|
/// ## File renaming
|
||||||
///
|
///
|
||||||
/// The processed files are renamed to `eeg_<timestamp>.jpg` and sent to the FE.
|
/// 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
|
/// 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.
|
/// 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
|
/// 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.
|
/// the same time, only the last one will have the valid timestamps.
|
||||||
fn get_image_info(path: PathBuf) -> ScanInfo {
|
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
|
// if the image is not thresholded, it may fail more often
|
||||||
let results = bardecoder::default_decoder().decode(&thresholded_image);
|
let results = bardecoder::default_decoder().decode(&thresholded_image);
|
||||||
|
|
||||||
|
|
||||||
// If no QR is detected, only rename
|
// If no QR is detected, only rename
|
||||||
if results.is_empty() {
|
if results.is_empty() {
|
||||||
log::info!("QR not found");
|
log::info!("QR not found");
|
||||||
@ -212,7 +211,8 @@ fn get_image_info(path: PathBuf) -> ScanInfo {
|
|||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
log::error!("Error decoding qr: {:?}", 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.
|
/// Converts a list of files into PDFs.
|
||||||
///
|
///
|
||||||
/// Uses the timestamps inside `data` to read the correct JPG files and convert them.
|
/// 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> {
|
async fn convert_scans_from_data(data: &Vec<ScanInfo>) -> Result<(), String> {
|
||||||
// Get a tuple with all the DNIs & iids.
|
// 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("0.05")
|
||||||
.arg("-quality")
|
.arg("-quality")
|
||||||
.arg("75%")
|
.arg("75%")
|
||||||
// .arg("-rotate")
|
.arg("-rotate")
|
||||||
// .arg("270")
|
.arg("270")
|
||||||
.arg(image_path)
|
.arg(image_path)
|
||||||
.arg(output_path)
|
.arg(output_path)
|
||||||
.spawn();
|
.spawn();
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user