Updated error message of unwrapping the Arc in import.rs and export.rs, now collection the file in export.rs into Vec instead of String

This commit is contained in:
StNicolay 2023-05-08 19:12:50 +03:00
parent 05c7f721ec
commit 207832be43
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
2 changed files with 13 additions and 5 deletions

View File

@ -6,7 +6,7 @@ use crate::{
}; };
use futures::TryStreamExt; use futures::TryStreamExt;
use sea_orm::DatabaseConnection; use sea_orm::DatabaseConnection;
use serde_json::to_string_pretty; use serde_json::to_vec_pretty;
use std::sync::Arc; use std::sync::Arc;
use teloxide::{adaptors::Throttle, prelude::*, types::InputFile}; use teloxide::{adaptors::Throttle, prelude::*, types::InputFile};
use tokio::{sync::Mutex, task::spawn_blocking}; use tokio::{sync::Mutex, task::spawn_blocking};
@ -38,10 +38,14 @@ async fn get_master_pass(
drop(master_pass); drop(master_pass);
let mut accounts = match Arc::try_unwrap(accounts) { let mut accounts = match Arc::try_unwrap(accounts) {
Ok(account) => account.into_inner(), Ok(account) => account.into_inner(),
Err(_) => unreachable!(), Err(_) => {
return Err(crate::Error::msg(
"Couldn't get accounts from Arc in export.rs",
))
}
}; };
accounts.sort_unstable_by(|this, other| this.name.cmp(&other.name)); accounts.sort_unstable_by(|this, other| this.name.cmp(&other.name));
let json = to_string_pretty(&User { accounts })?; let json = to_vec_pretty(&User { accounts })?;
let file = InputFile::memory(json).file_name("accounts.json"); let file = InputFile::memory(json).file_name("accounts.json");
bot.send_document(msg.chat.id, file) bot.send_document(msg.chat.id, file)
.reply_markup(deletion_markup()) .reply_markup(deletion_markup())

View File

@ -49,7 +49,11 @@ async fn get_master_pass(
drop(master_pass); drop(master_pass);
let failed = match Arc::try_unwrap(failed) { let failed = match Arc::try_unwrap(failed) {
Ok(accounts) => accounts.into_inner(), Ok(accounts) => accounts.into_inner(),
Err(_) => unreachable!(), Err(_) => {
return Err(crate::Error::msg(
"Couldn't get accounts from Arc in import.rs",
))
}
}; };
let message = if failed.is_empty() { let message = if failed.is_empty() {
"Success".to_owned() "Success".to_owned()
@ -84,7 +88,7 @@ async fn get_document(
} }
}; };
match document.file_name { match document.file_name {
Some(ref name) if name.trim().ends_with(".json") => (), Some(ref name) if name.trim_end().ends_with(".json") => (),
_ => { _ => {
bot.send_message(msg.chat.id, "Invalid file name") bot.send_message(msg.chat.id, "Invalid file name")
.reply_markup(deletion_markup()) .reply_markup(deletion_markup())