hydrus_api/wrapper/builders/
delete_files_builder.rs1use crate::api_core::common::{
2 FileIdentifier, FileSelection, FileServiceSelection, ServiceIdentifier,
3};
4use crate::error::Result;
5use crate::Client;
6
7pub struct DeleteFilesBuilder {
8 client: Client,
9 hashes: Vec<String>,
10 ids: Vec<u64>,
11 reason: Option<String>,
12 service: Option<ServiceIdentifier>,
13}
14
15impl DeleteFilesBuilder {
16 pub(crate) fn new(client: Client) -> Self {
17 Self {
18 client,
19 hashes: Vec::new(),
20 ids: Vec::new(),
21 reason: None,
22 service: None,
23 }
24 }
25
26 pub fn add_file(mut self, identifier: FileIdentifier) -> Self {
28 match identifier {
29 FileIdentifier::ID(id) => self.ids.push(id),
30 FileIdentifier::Hash(hash) => self.hashes.push(hash),
31 }
32
33 self
34 }
35
36 pub fn add_files(self, ids: Vec<FileIdentifier>) -> Self {
38 ids.into_iter().fold(self, |acc, id| acc.add_file(id))
39 }
40
41 pub fn service(mut self, service: ServiceIdentifier) -> Self {
43 self.service = Some(service);
44
45 self
46 }
47
48 pub fn reason<S: ToString>(mut self, reason: S) -> Self {
50 self.reason = Some(reason.to_string());
51
52 self
53 }
54
55 pub async fn run(self) -> Result<()> {
57 let file_selection = FileSelection {
58 hashes: self.hashes,
59 file_ids: self.ids,
60 ..Default::default()
61 };
62 let service_selection = self
63 .service
64 .map(FileServiceSelection::from)
65 .unwrap_or_default();
66
67 self.client
68 .delete_files(file_selection, service_selection, self.reason)
69 .await
70 }
71}