Use Option<String> instead of String for get_token

This commit is contained in:
Mystikfluu 2023-04-01 17:05:06 +02:00
parent d28913b141
commit eaf04675e3

View File

@ -27,19 +27,21 @@ struct Saved {
_errorcode: u64
}
fn get_token() -> String {
fn get_token() -> Option<String> {
let mut token: String = String::new();
//check if file exists
if !std::path::Path::new(&(get_ipass_folder()+"token.ipasst")).exists() {
return "".to_string();
return None;
}
File::open(get_ipass_folder()+"token.ipasst").unwrap().read_to_string(&mut token).unwrap();
token
Some(token)
}
pub async fn isync_get() -> bool {
let token = get_token();
match token {
Some(token) => {
let client = reqwest::Client::builder().https_only(true).build().unwrap();
let req = client.get("https://ipass.ipost.rocks/saved").header("ipass-auth-token", token).build().unwrap();
let res = client.execute(req).await.unwrap();
@ -50,6 +52,11 @@ pub async fn isync_get() -> bool {
std::fs::remove_file(get_ipass_folder()+"temp.ipassx").unwrap();
return true;
}
},
None => {
return false;
}
}
false
}
@ -59,6 +66,8 @@ pub async fn isync_save() -> bool {
match possible_data {
Some(data) => {
let token = get_token();
match token {
Some(token) => {
let client = reqwest::Client::builder().https_only(true).build().unwrap();
let req = client.post("https://ipass.ipost.rocks/saved")
.header("ipass-auth-token", token)
@ -73,6 +82,11 @@ pub async fn isync_save() -> bool {
false
}
}
},
None => {
false
}
}
}
pub fn import_data<R: Read>(mut reader: brotli::Decompressor<R>) {