Use Option<String> instead of String for get_token
This commit is contained in:
parent
d28913b141
commit
eaf04675e3
20
src/lib.rs
20
src/lib.rs
@ -27,19 +27,21 @@ struct Saved {
|
|||||||
_errorcode: u64
|
_errorcode: u64
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_token() -> String {
|
fn get_token() -> Option<String> {
|
||||||
let mut token: String = String::new();
|
let mut token: String = String::new();
|
||||||
//check if file exists
|
//check if file exists
|
||||||
if !std::path::Path::new(&(get_ipass_folder()+"token.ipasst")).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();
|
File::open(get_ipass_folder()+"token.ipasst").unwrap().read_to_string(&mut token).unwrap();
|
||||||
token
|
Some(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn isync_get() -> bool {
|
pub async fn isync_get() -> bool {
|
||||||
let token = get_token();
|
let token = get_token();
|
||||||
|
match token {
|
||||||
|
Some(token) => {
|
||||||
let client = reqwest::Client::builder().https_only(true).build().unwrap();
|
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 req = client.get("https://ipass.ipost.rocks/saved").header("ipass-auth-token", token).build().unwrap();
|
||||||
let res = client.execute(req).await.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();
|
std::fs::remove_file(get_ipass_folder()+"temp.ipassx").unwrap();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@ -59,6 +66,8 @@ pub async fn isync_save() -> bool {
|
|||||||
match possible_data {
|
match possible_data {
|
||||||
Some(data) => {
|
Some(data) => {
|
||||||
let token = get_token();
|
let token = get_token();
|
||||||
|
match token {
|
||||||
|
Some(token) => {
|
||||||
let client = reqwest::Client::builder().https_only(true).build().unwrap();
|
let client = reqwest::Client::builder().https_only(true).build().unwrap();
|
||||||
let req = client.post("https://ipass.ipost.rocks/saved")
|
let req = client.post("https://ipass.ipost.rocks/saved")
|
||||||
.header("ipass-auth-token", token)
|
.header("ipass-auth-token", token)
|
||||||
@ -73,6 +82,11 @@ pub async fn isync_save() -> bool {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn import_data<R: Read>(mut reader: brotli::Decompressor<R>) {
|
pub fn import_data<R: Read>(mut reader: brotli::Decompressor<R>) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user