ipfs_api_prelude/request/
files.rs

1// Copyright 2017 rust-ipfs-api Developers
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7//
8
9use crate::request::ApiRequest;
10use serde::Serialize;
11
12#[derive(Serialize, Default)]
13pub struct FilesCp<'a> {
14    #[serde(rename = "arg")]
15    pub path: &'a str,
16
17    #[serde(rename = "arg")]
18    pub dest: &'a str,
19
20    pub flush: Option<bool>,
21}
22
23impl<'a> ApiRequest for FilesCp<'a> {
24    const PATH: &'static str = "/files/cp";
25}
26
27#[derive(Serialize)]
28pub struct FilesFlush<'a> {
29    #[serde(rename = "arg")]
30    pub path: Option<&'a str>,
31}
32
33impl<'a> ApiRequest for FilesFlush<'a> {
34    const PATH: &'static str = "/files/flush";
35}
36
37#[cfg_attr(feature = "with-builder", derive(TypedBuilder))]
38#[derive(Serialize, Default)]
39pub struct FilesLs<'a> {
40    #[serde(rename = "arg")]
41    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
42    pub path: Option<&'a str>,
43
44    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
45    pub long: Option<bool>,
46
47    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
48    #[serde(rename = "U")]
49    pub unsorted: Option<bool>,
50}
51
52impl<'a> ApiRequest for FilesLs<'a> {
53    const PATH: &'static str = "/files/ls";
54}
55
56#[cfg_attr(feature = "with-builder", derive(TypedBuilder))]
57#[derive(Serialize, Default)]
58#[serde(rename_all = "kebab-case")]
59pub struct FilesMkdir<'a> {
60    #[serde(rename = "arg")]
61    pub path: &'a str,
62
63    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
64    pub parents: Option<bool>,
65
66    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
67    pub hash: Option<&'a str>,
68
69    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
70    pub cid_version: Option<i32>,
71
72    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
73    pub flush: Option<bool>,
74}
75
76impl<'a> ApiRequest for FilesMkdir<'a> {
77    const PATH: &'static str = "/files/mkdir";
78}
79
80#[derive(Serialize, Default)]
81pub struct FilesMv<'a> {
82    #[serde(rename = "arg")]
83    pub path: &'a str,
84
85    #[serde(rename = "arg")]
86    pub dest: &'a str,
87
88    pub flush: Option<bool>,
89}
90
91impl<'a> ApiRequest for FilesMv<'a> {
92    const PATH: &'static str = "/files/mv";
93}
94
95#[cfg_attr(feature = "with-builder", derive(TypedBuilder))]
96#[derive(Serialize, Default)]
97pub struct FilesRead<'a> {
98    #[serde(rename = "arg")]
99    pub path: &'a str,
100
101    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
102    pub offset: Option<i64>,
103
104    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
105    pub count: Option<i64>,
106}
107
108impl<'a> ApiRequest for FilesRead<'a> {
109    const PATH: &'static str = "/files/read";
110}
111
112#[cfg_attr(feature = "with-builder", derive(TypedBuilder))]
113#[derive(Serialize, Default)]
114pub struct FilesRm<'a> {
115    #[serde(rename = "arg")]
116    pub path: &'a str,
117
118    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
119    pub recursive: Option<bool>,
120
121    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
122    pub flush: Option<bool>,
123}
124
125impl<'a> ApiRequest for FilesRm<'a> {
126    const PATH: &'static str = "/files/rm";
127}
128
129#[derive(Serialize, Default)]
130#[serde(rename_all = "kebab-case")]
131pub struct FilesStat<'a> {
132    #[serde(rename = "arg")]
133    pub path: &'a str,
134
135    pub with_local: Option<bool>,
136}
137
138impl<'a> ApiRequest for FilesStat<'a> {
139    const PATH: &'static str = "/files/stat";
140}
141
142#[cfg_attr(feature = "with-builder", derive(TypedBuilder))]
143#[derive(Serialize, Default)]
144#[serde(rename_all = "kebab-case")]
145pub struct FilesWrite<'a> {
146    #[serde(rename = "arg")]
147    pub path: &'a str,
148
149    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
150    pub create: Option<bool>,
151
152    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
153    pub truncate: Option<bool>,
154
155    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
156    pub parents: Option<bool>,
157
158    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
159    pub offset: Option<i64>,
160
161    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
162    pub count: Option<i64>,
163
164    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
165    pub raw_leaves: Option<bool>,
166
167    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
168    pub hash: Option<&'a str>,
169
170    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
171    pub cid_version: Option<i32>,
172
173    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
174    pub flush: Option<bool>,
175}
176
177impl<'a> ApiRequest for FilesWrite<'a> {
178    const PATH: &'static str = "/files/write";
179}
180
181#[cfg_attr(feature = "with-builder", derive(TypedBuilder))]
182#[derive(Serialize, Default)]
183#[serde(rename_all = "kebab-case")]
184pub struct FilesChcid<'a> {
185    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
186    #[serde(rename = "arg")]
187    pub path: Option<&'a str>,
188
189    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
190    pub hash: Option<&'a str>,
191
192    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
193    pub cid_version: Option<i32>,
194
195    #[cfg_attr(feature = "with-builder", builder(default, setter(strip_option)))]
196    pub flush: Option<bool>,
197}
198
199impl<'a> ApiRequest for FilesChcid<'a> {
200    const PATH: &'static str = "/files/chcid";
201}