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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use thiserror::Error;
/// various errors
#[derive(Error, Debug)]
pub enum HydrusError {
#[error("failed to connect to Hydrus")]
NetworkError(reqwest::Error),
#[error("failed to encode/Deserialize data")]
DeserializeError(serde_json::Error),
#[error("io error")]
IOError(std::io::Error),
#[error("api or session key needed")]
KeyNotSupplied,
}
impl From<serde_json::Error> for HydrusError {
fn from(value: serde_json::Error) -> Self {
HydrusError::DeserializeError(value)
}
}
impl From<std::io::Error> for HydrusError {
fn from(value: std::io::Error) -> Self {
HydrusError::IOError(value)
}
}
impl From<reqwest::Error> for HydrusError {
fn from(value: reqwest::Error) -> Self {
HydrusError::NetworkError(value)
}
}
/// hydrus permissions
#[derive(PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum HydrusPermissions {
ImportAndEditURLs = 0,
ImportAndEditFiles,
EditFileTags,
SearchAndFetchFiles,
ManagePages,
ManageCookiesAndHeaders,
ManageDatabase,
EditFileNotes,
EditFileRelationships,
EditFileRatings,
ManagePopups,
EditFileTimes,
CommitPending,
SeeLocalPaths,
Null = 255,
}
/// hydrus key information struct
#[derive(Deserialize, Debug)]
pub struct KeyInfo {
pub name: String,
pub permits_everything: bool,
pub basic_permissions: Vec<HydrusPermissions>,
pub human_permissions: String,
}
/// hydrus service type struct
#[derive(PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum ServiceType {
TagRepository = 0,
FileRepository,
LocalFileDomain,
LocalTagDomain = 5,
NumericalRating,
BoolRating,
AllKnownTags = 10,
AllKnownFiles,
LocalBooru,
IPFS,
Trash,
AllLocalFiles,
FileNotes = 17,
ClientAPI,
DeletedFromAnywhere,
LocalUpdates,
AllMyFiles,
IncDecRating,
ServerAdmin = 99,
Null = 255,
}
/// hydrus service struct
#[derive(Deserialize, Debug)]
pub struct Service {
pub name: String,
#[serde(default)]
pub service_key: String,
pub r#type: ServiceType,
pub type_pretty: String,
#[serde(default)]
pub star_shape: Option<String>,
#[serde(default)]
pub min_stars: Option<u8>,
#[serde(default)]
pub max_stars: Option<u8>,
}
/// hydrus file domains
pub enum FileDomain {
FileServiceKey(String),
FileServiceKeys(Vec<String>),
DeletedFileServiceKey(String),
DeletedFileServiceKeys(Vec<String>),
}
/// payload for importing a file via providing a local path
#[derive(Serialize, Debug, Default)]
pub struct AddFileRequest {
pub path: PathBuf,
#[serde(skip)]
pub delete_after_successful_import: Option<bool>,
#[serde(skip)]
pub file_service_key: Option<String>,
#[serde(skip)]
pub file_service_keys: Option<Vec<String>>,
#[serde(skip)]
pub deleted_file_service_key: Option<String>,
#[serde(skip)]
pub deleted_file_service_keys: Option<Vec<String>>,
}
/// file importing status
#[derive(PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum AddFileStatus {
SuccessfulImport = 1,
AlreadyInDatabase,
PreviouslyDeleted,
FailedToImport,
FileVetoed = 7,
}
/// file importing api response
#[derive(Deserialize)]
pub struct AddFileResponse {
pub status: AddFileStatus,
pub hash: String,
pub note: String,
}
/// payload for deleting a file
#[derive(Serialize, Debug, Default)]
pub struct DeleteFileRequest {
pub path: String,
#[serde(skip)]
pub file_service_key: Option<String>,
#[serde(skip)]
pub file_service_keys: Option<Vec<String>>,
#[serde(skip)]
pub deleted_file_service_key: Option<String>,
#[serde(skip)]
pub deleted_file_service_keys: Option<Vec<String>>,
#[serde(skip)]
pub reason: Option<String>,
}
|