Skip to content

Commit

Permalink
Cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yveszoundi committed Jul 9, 2022
1 parent d182669 commit e97c131
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
3 changes: 1 addition & 2 deletions entrusted_client/src/main_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2437,8 +2437,7 @@ pub fn list_apps_for_pdfs() -> HashMap<String, String> {
app_name.push_str(&active_key_value);
}
} else {
let app_url_pathbuf = PathBuf::from(&app_url);
if let Some(basename_ostr) = &app_url_pathbuf.file_stem() {
if let Some(basename_ostr) = std::path::Path::new(&app_url).file_stem() {
if let Some(basename) = &basename_ostr.to_str() {
if let Ok(r_app_name_decoded)= percent_decode(basename.as_bytes()).decode_utf8() {
app_name.push_str(&r_app_name_decoded);
Expand Down
68 changes: 33 additions & 35 deletions entrusted_webclient/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async fn main() {
}
}

async fn handle_args() -> Result<(), Box<dyn Error + Send + Sync>> {
async fn handle_args() -> Result<(), Box<dyn Error + Send + Sync>> {
let locale = match env::var(l10n::ENV_VAR_ENTRUSTED_LANGID) {
Ok(selected_locale) => selected_locale,
Err(_) => l10n::sys_locale()
Expand All @@ -143,22 +143,22 @@ async fn handle_args() -> Result<(), Box<dyn Error + Send + Sync>> {
let appconfig_ret = load_config();
let appconfig = appconfig_ret.unwrap_or(AppConfig::default());
let port_number_text = format!("{}", appconfig.port);

let help_host = trans.gettext("Server host or IP address");
let help_port = trans.gettext("Server port number");
let help_output_filename = trans.gettext("Output filename");
let help_input_filename = trans.gettext("Input filename");
let help_ocr_lang = trans.gettext("Optional language for OCR (i.e. 'eng' for English)");
let help_file_suffix = trans.gettext("Default file suffix (entrusted)");
let help_password_prompt = trans.gettext("Prompt for document password");

let app = App::new(option_env!("CARGO_PKG_NAME").unwrap_or("Unknown"))
.version(option_env!("CARGO_PKG_VERSION").unwrap_or("Unknown"))
.author(option_env!("CARGO_PKG_AUTHORS").unwrap_or("Unknown"))
.about(option_env!("CARGO_PKG_DESCRIPTION").unwrap_or("Unknown"))
.arg(
Arg::with_name("host")
.long("host")
.long("host")
.help(&help_host)
.required(true)
.default_value(&appconfig.host)
Expand All @@ -174,7 +174,7 @@ async fn handle_args() -> Result<(), Box<dyn Error + Send + Sync>> {
)
.arg(
Arg::with_name("ocr-lang")
.long("ocr-lang")
.long("ocr-lang")
.help(&help_ocr_lang)
.required(false)
.takes_value(true)
Expand Down Expand Up @@ -218,12 +218,12 @@ async fn handle_args() -> Result<(), Box<dyn Error + Send + Sync>> {
if let Some(proposed_ocr_lang) = &opt_ocr_lang {
let supported_ocr_languages = l10n::ocr_lang_key_by_name(trans.clone_box());
let proposed_ocr_lang_str = proposed_ocr_lang.as_str();

if !supported_ocr_languages.contains_key(&proposed_ocr_lang_str) {
let mut ocr_lang_err = String::new();
ocr_lang_err.push_str(&trans.gettext_fmt("Unknown language code for the ocr-lang parameter: {0}. Hint: Try 'eng' for English.", vec![proposed_ocr_lang]));

ocr_lang_err.push_str(" => ");
ocr_lang_err.push_str(" => ");
let mut prev = false;

for (lang_code, language) in supported_ocr_languages {
Expand Down Expand Up @@ -272,14 +272,14 @@ async fn handle_args() -> Result<(), Box<dyn Error + Send + Sync>> {
Some(password)
} else {
return Err(trans.gettext("Failed to read password!").into());
}
}
} else {
None
};

if let Some(output_dir) = p.parent() {
let filename = p.file_name().unwrap().to_str().unwrap();

let conversion_options = ConversionOptions {
host:host.to_string(), port:port.to_string(), opt_ocr_lang, opt_passwd, file_suffix,
};
Expand Down Expand Up @@ -322,7 +322,7 @@ async fn convert_file (
}

let client = Client::new();

let resp = client
.post(format!("http://{}/upload", addr.clone()))
.header("Accept-Language", l10n.langid())
Expand Down Expand Up @@ -353,7 +353,7 @@ async fn convert_file (
return Err(l10n.gettext("Could not determine input file base name!").into());
}
};

let mut output_file = File::create(output_path).await?;
output_file.write_all(&download_data).await?;

Expand All @@ -364,7 +364,7 @@ async fn process_notifications(tracking_url: String,
l10n: &Box<dyn l10n::Translations>) -> Result<String, Box<dyn Error + Send + Sync>> {
let mut es = EventSource::get(format!("{}", tracking_url));
let pb = ProgressBar::new(100);

let processing_status: Result<String, Box<dyn Error>> = {
let mut download_uri = String::new();

Expand All @@ -379,30 +379,28 @@ async fn process_notifications(tracking_url: String,
pb.set_position(log_msg.percent_complete as u64);
pb.println(&log_msg.data);
}
} else {
if msg.event == "processing_success" {
let log_msg_ret: serde_json::Result<LogMessage> = serde_json::from_str(&msg.data);

if let Ok(log_msg) = log_msg_ret {
download_uri = log_msg.data.clone();
pb.set_position(log_msg.percent_complete as u64);
println!("{}", l10n.gettext("Conversion completed successfully!"));
}

es.close();

return Ok(download_uri);
} else if msg.event == "processing_failure" {
let log_msg_ret: serde_json::Result<LogMessage> = serde_json::from_str(&msg.data);

if let Ok(log_msg) = log_msg_ret {
pb.set_position(log_msg.percent_complete as u64);
}

es.close();

return Err(l10n.gettext("Conversion failed!").into());
} else if msg.event == "processing_success" {
let log_msg_ret: serde_json::Result<LogMessage> = serde_json::from_str(&msg.data);

if let Ok(log_msg) = log_msg_ret {
download_uri = log_msg.data.clone();
pb.set_position(log_msg.percent_complete as u64);
println!("{}", l10n.gettext("Conversion completed successfully!"));
}

es.close();

return Ok(download_uri);
} else if msg.event == "processing_failure" {
let log_msg_ret: serde_json::Result<LogMessage> = serde_json::from_str(&msg.data);

if let Ok(log_msg) = log_msg_ret {
pb.set_position(log_msg.percent_complete as u64);
}

es.close();

return Err(l10n.gettext("Conversion failed!").into());
}
},
Err(err) => {
Expand Down

0 comments on commit e97c131

Please sign in to comment.