simple ab store and add batch operation toast
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
f5cf291f55
commit
2f5ae54c08
@ -309,6 +309,7 @@ class _PeerTabPageState extends State<PeerTabPage>
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
gFFI.peerTabModel.closeSelection();
|
gFFI.peerTabModel.closeSelection();
|
||||||
|
showToast(translate('Successful'));
|
||||||
}
|
}
|
||||||
|
|
||||||
deletePeerConfirmDialog(onSubmit);
|
deletePeerConfirmDialog(onSubmit);
|
||||||
@ -334,6 +335,7 @@ class _PeerTabPageState extends State<PeerTabPage>
|
|||||||
}
|
}
|
||||||
await bind.mainStoreFav(favs: favs);
|
await bind.mainStoreFav(favs: favs);
|
||||||
gFFI.peerTabModel.closeSelection();
|
gFFI.peerTabModel.closeSelection();
|
||||||
|
showToast(translate('Successful'));
|
||||||
},
|
},
|
||||||
child: Tooltip(
|
child: Tooltip(
|
||||||
message: translate('Add to Favorites'),
|
message: translate('Add to Favorites'),
|
||||||
@ -354,6 +356,7 @@ class _PeerTabPageState extends State<PeerTabPage>
|
|||||||
gFFI.abModel.addPeers(peers);
|
gFFI.abModel.addPeers(peers);
|
||||||
gFFI.abModel.pushAb();
|
gFFI.abModel.pushAb();
|
||||||
gFFI.peerTabModel.closeSelection();
|
gFFI.peerTabModel.closeSelection();
|
||||||
|
showToast(translate('Successful'));
|
||||||
},
|
},
|
||||||
child: Tooltip(
|
child: Tooltip(
|
||||||
message: translate('Add to Address Book'),
|
message: translate('Add to Address Book'),
|
||||||
@ -377,6 +380,7 @@ class _PeerTabPageState extends State<PeerTabPage>
|
|||||||
peers.map((p) => p.id).toList(), selectedTags);
|
peers.map((p) => p.id).toList(), selectedTags);
|
||||||
gFFI.abModel.pushAb();
|
gFFI.abModel.pushAb();
|
||||||
gFFI.peerTabModel.closeSelection();
|
gFFI.peerTabModel.closeSelection();
|
||||||
|
showToast(translate('Successful'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: Tooltip(
|
child: Tooltip(
|
||||||
|
@ -61,7 +61,7 @@ class AbModel {
|
|||||||
authHeaders['Accept-Encoding'] = "gzip";
|
authHeaders['Accept-Encoding'] = "gzip";
|
||||||
final resp = await http.get(Uri.parse(api), headers: authHeaders);
|
final resp = await http.get(Uri.parse(api), headers: authHeaders);
|
||||||
if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") {
|
if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") {
|
||||||
Map<String, dynamic> json = jsonDecode(resp.body);
|
Map<String, dynamic> json = jsonDecode(utf8.decode(resp.bodyBytes));
|
||||||
if (json.containsKey('error')) {
|
if (json.containsKey('error')) {
|
||||||
abError.value = json['error'];
|
abError.value = json['error'];
|
||||||
} else if (json.containsKey('data')) {
|
} else if (json.containsKey('data')) {
|
||||||
|
@ -23,7 +23,7 @@ use crate::{
|
|||||||
log,
|
log,
|
||||||
password_security::{
|
password_security::{
|
||||||
decrypt_str_or_original, decrypt_vec_or_original, encrypt_str_or_original,
|
decrypt_str_or_original, decrypt_vec_or_original, encrypt_str_or_original,
|
||||||
encrypt_vec_or_original,
|
encrypt_vec_or_original, symmetric_crypt,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1504,13 +1504,14 @@ impl Ab {
|
|||||||
pub fn store(json: String) {
|
pub fn store(json: String) {
|
||||||
if let Ok(mut file) = std::fs::File::create(Self::path()) {
|
if let Ok(mut file) = std::fs::File::create(Self::path()) {
|
||||||
let data = compress(json.as_bytes());
|
let data = compress(json.as_bytes());
|
||||||
let max_len = 32 * 1024 * 1024;
|
let max_len = 64 * 1024 * 1024;
|
||||||
if data.len() > max_len {
|
if data.len() > max_len {
|
||||||
// not store original
|
// maxlen of function decompress
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let data = encrypt_vec_or_original(&data, PASSWORD_ENC_VERSION, max_len);
|
if let Ok(data) = symmetric_crypt(&data, true) {
|
||||||
file.write_all(&data).ok();
|
file.write_all(&data).ok();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1518,8 +1519,7 @@ impl Ab {
|
|||||||
if let Ok(mut file) = std::fs::File::open(Self::path()) {
|
if let Ok(mut file) = std::fs::File::open(Self::path()) {
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
if file.read_to_end(&mut data).is_ok() {
|
if file.read_to_end(&mut data).is_ok() {
|
||||||
let (data, succ, _) = decrypt_vec_or_original(&data, PASSWORD_ENC_VERSION);
|
if let Ok(data) = symmetric_crypt(&data, false) {
|
||||||
if succ {
|
|
||||||
let data = decompress(&data);
|
let data = decompress(&data);
|
||||||
if let Ok(ab) = serde_json::from_str::<Ab>(&String::from_utf8_lossy(&data)) {
|
if let Ok(ab) = serde_json::from_str::<Ab>(&String::from_utf8_lossy(&data)) {
|
||||||
return ab;
|
return ab;
|
||||||
@ -1527,6 +1527,7 @@ impl Ab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Self::remove();
|
||||||
Ab::default()
|
Ab::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ fn decrypt(v: &[u8]) -> Result<Vec<u8>, ()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn symmetric_crypt(data: &[u8], encrypt: bool) -> Result<Vec<u8>, ()> {
|
pub fn symmetric_crypt(data: &[u8], encrypt: bool) -> Result<Vec<u8>, ()> {
|
||||||
use sodiumoxide::crypto::secretbox;
|
use sodiumoxide::crypto::secretbox;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user