1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
use hydrus_api::async_lib::{client::*, traits::*};
use hydrus_api::types::*;
use std::path::PathBuf;
fn init_client() -> HydrusClient {
let keyfile = PathBuf::from("secrets");
let key = std::fs::read_to_string(keyfile).unwrap().trim().to_string();
let mut client: HydrusClient = HydrusClient::new("http://127.0.0.1:45869/");
client.set_api_key(key);
client
}
#[tokio::test]
async fn test_service_name_info() {
let client = init_client();
let _ = client.get_service_name("all my files").await.unwrap();
}
#[tokio::test]
async fn test_service_key_info() {
let client = init_client();
let _ = client
.get_service_key("616c6c206c6f63616c206d65646961")
.await
.unwrap();
}
#[tokio::test]
async fn test_get_services() {
let client = init_client();
let res = client.get_services().await.unwrap();
assert!(!res.is_empty())
}
#[tokio::test]
async fn add_and_delete_file() {
let client = init_client();
let path = PathBuf::from("./assets/img.png").canonicalize().unwrap();
let file = client
.add_file_via_path(path.clone(), None, None)
.await
.unwrap();
if client
.add_file_via_path(path.clone(), None, None)
.await
.unwrap()
.status
!= AddFileStatus::AlreadyInDatabase
{
panic!();
}
let trash_service = Some(FileDomain::FileServiceKey(
client
.get_service_name("all my files")
.await
.unwrap()
.service_key,
));
client
.delete_files(HydrusFile::Hash(file.hash.clone()), None, None)
.await
.unwrap();
client
.delete_files(HydrusFile::Hash(file.hash.clone()), trash_service, None)
.await
.unwrap();
client
.clear_file_deletion_records(HydrusFile::Hash(file.hash))
.await
.unwrap();
let file = client.add_file_via_file(path.clone()).await.unwrap();
if client.add_file_via_file(path).await.unwrap().status != AddFileStatus::AlreadyInDatabase {
panic!();
}
client
.delete_files(HydrusFile::Hash(file.hash.clone()), None, None)
.await
.unwrap();
client
.delete_files(HydrusFile::Hash(file.hash.clone()), None, None)
.await
.unwrap();
client
.clear_file_deletion_records(HydrusFile::Hash(file.hash))
.await
.unwrap();
}
|