hydrus_api/api_core/endpoints/
adding_urls.rs1use crate::api_core::common::ServiceIdentifier;
2use crate::api_core::endpoints::Endpoint;
3use serde::Serialize;
4use std::collections::HashMap;
5
6pub static URL_TYPE_POST: u8 = 0;
7pub static URL_TYPE_FILE: u8 = 1;
8pub static URL_TYPE_GALLERY: u8 = 2;
9pub static URL_TYPE_WATCHABLE: u8 = 4;
10pub static URL_TYPE_UNKNOWN: u8 = 5;
11
12#[derive(Clone, Debug, Deserialize)]
13pub struct GetUrlFilesResponse {
14 pub normalised_url: String,
15 pub url_file_statuses: Vec<UrlFileStatus>,
16}
17
18#[derive(Clone, Debug, Deserialize)]
19pub struct UrlFileStatus {
20 pub status: u8,
21 pub hash: String,
22 pub note: String,
23}
24
25pub struct GetUrlFiles;
26
27impl Endpoint for GetUrlFiles {
28 type Request = ();
29 type Response = GetUrlFilesResponse;
30
31 fn path() -> String {
32 String::from("add_urls/get_url_files")
33 }
34}
35
36#[derive(Clone, Debug, Deserialize)]
37pub struct GetUrlInfoResponse {
38 pub normalised_url: String,
39 pub url_type: u8,
40 pub url_type_string: String,
41 pub match_name: String,
42 pub can_parse: bool,
43}
44
45pub struct GetUrlInfo;
46
47impl Endpoint for GetUrlInfo {
48 type Request = ();
49 type Response = GetUrlInfoResponse;
50
51 fn path() -> String {
52 String::from("add_urls/get_url_info")
53 }
54}
55
56#[derive(Clone, Default, Debug, Serialize)]
57pub struct AddUrlRequest {
58 pub url: String,
59
60 #[serde(skip_serializing_if = "Option::is_none")]
61 pub destination_page_key: Option<String>,
62
63 #[serde(skip_serializing_if = "Option::is_none")]
64 pub destination_page_name: Option<String>,
65
66 pub show_destination_page: bool,
67 pub service_names_to_additional_tags: HashMap<String, Vec<String>>,
68 pub service_keys_to_additional_tags: HashMap<String, Vec<String>>,
69 pub filterable_tags: Vec<String>,
70}
71
72#[derive(Default)]
88pub struct AddUrlRequestBuilder {
89 inner: AddUrlRequest,
90}
91
92impl AddUrlRequestBuilder {
93 pub fn url<S: ToString>(mut self, url: S) -> Self {
94 self.inner.url = url.to_string();
95
96 self
97 }
98
99 pub fn destination_page_key<S: ToString>(mut self, page_key: S) -> Self {
100 self.inner.destination_page_key = Some(page_key.to_string());
101
102 self
103 }
104
105 pub fn destination_page_name<S: ToString>(mut self, page_name: S) -> Self {
106 self.inner.destination_page_name = Some(page_name.to_string());
107
108 self
109 }
110
111 pub fn show_destination_page(mut self, show: bool) -> Self {
112 self.inner.show_destination_page = show;
113
114 self
115 }
116
117 pub fn add_tags(mut self, service_id: ServiceIdentifier, mut tags: Vec<String>) -> Self {
118 let (service, mappings) = match service_id {
119 ServiceIdentifier::Name(name) => {
120 (name, &mut self.inner.service_names_to_additional_tags)
121 }
122 ServiceIdentifier::Key(key) => (key, &mut self.inner.service_keys_to_additional_tags),
123 };
124 if let Some(entry) = mappings.get_mut(&service) {
125 entry.append(&mut tags);
126 } else {
127 mappings.insert(service, tags);
128 }
129
130 self
131 }
132
133 pub fn add_filter_tags(mut self, mut filter_tags: Vec<String>) -> Self {
134 self.inner.filterable_tags.append(&mut filter_tags);
135
136 self
137 }
138
139 pub fn build(self) -> AddUrlRequest {
140 self.inner
141 }
142}
143
144#[derive(Clone, Debug, Deserialize)]
145pub struct AddUrlResponse {
146 pub human_result_text: String,
147 pub normalised_url: String,
148}
149
150pub struct AddUrl;
151
152impl Endpoint for AddUrl {
153 type Request = AddUrlRequest;
154 type Response = AddUrlResponse;
155
156 fn path() -> String {
157 String::from("add_urls/add_url")
158 }
159}
160
161#[derive(Clone, Debug, Serialize)]
162pub struct AssociateUrlRequest {
163 pub urls_to_add: Vec<String>,
164 pub urls_to_delete: Vec<String>,
165 pub hashes: Vec<String>,
166}
167pub struct AssociateUrl;
168
169impl Endpoint for AssociateUrl {
170 type Request = AssociateUrlRequest;
171 type Response = ();
172
173 fn path() -> String {
174 String::from("add_urls/associate_url")
175 }
176}