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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*use actix_multipart::form::MultipartForm;
use actix_web::{web, HttpRequest, HttpResponse};
use actix_web::web::Data;
use ant_core::data::Wallet;
use log::debug;
use crate::service::public_archive_service::{PublicArchiveForm, PublicArchiveService, Upload, ArchiveResponse};
use crate::error::public_archive_error::PublicArchiveError;
use crate::controller::get_store_type;
#[utoipa::path(
post,
path = "/anttp-0/multipart/public_archive",
request_body(
content = PublicArchiveForm,
content_type = "multipart/form-data"
),
responses(
(status = CREATED, description = "Public archive created successfully", body = ArchiveResponse)
),
params(
("x-store-type", Header, description = "Only persist to cache and do not publish (memory|disk|none)",
example = "memory"),
),
)]
pub async fn post_public_archive_root(
public_archive_form: MultipartForm<PublicArchiveForm>,
public_archive_service: Data<PublicArchiveService>,
evm_wallet_data: Data<Wallet>,
request: HttpRequest
) -> Result<HttpResponse, PublicArchiveError> {
let evm_wallet = evm_wallet_data.get_ref().clone();
debug!("Creating new archive from multipart POST");
Ok(HttpResponse::Created().json(
public_archive_service.create_public_archive(None, public_archive_form, evm_wallet, get_store_type(&request)).await?
))
}
#[utoipa::path(
post,
path = "/anttp-0/multipart/public_archive/{path}",
request_body(
content = PublicArchiveForm,
content_type = "multipart/form-data"
),
responses(
(status = CREATED, description = "Public archive created successfully", body = ArchiveResponse)
),
params(
("path" = String, Path, description = "Target path (directory) for all uploads"),
("x-store-type", Header, description = "Only persist to cache and do not publish (memory|disk|none)",
example = "memory"),
),
)]
pub async fn post_public_archive(
path_params: web::Path<String>,
public_archive_form: MultipartForm<PublicArchiveForm>,
public_archive_service: Data<PublicArchiveService>,
evm_wallet_data: Data<Wallet>,
request: HttpRequest
) -> Result<HttpResponse, PublicArchiveError> {
let mut path = path_params.into_inner();
path = path.replace("%2F", "/");
let evm_wallet = evm_wallet_data.get_ref().clone();
debug!("Creating new archive from multipart POST at path [{}]", path);
Ok(HttpResponse::Created().json(
public_archive_service.create_public_archive(Some(path), public_archive_form, evm_wallet, get_store_type(&request)).await?
))
}
#[utoipa::path(
put,
path = "/anttp-0/multipart/public_archive/{address}",
request_body(
content = PublicArchiveForm,
content_type = "multipart/form-data"
),
responses(
(status = OK, description = "Public archive updated successfully", body = ArchiveResponse)
),
params(
("address" = String, Path, description = "Public archive address"),
("x-store-type", Header, description = "Only persist to cache and do not publish (memory|disk|none)",
example = "memory"),
),
)]
pub async fn put_public_archive_root(
path: web::Path<String>,
public_archive_form: MultipartForm<PublicArchiveForm>,
public_archive_service: Data<PublicArchiveService>,
evm_wallet_data: Data<Wallet>,
request: HttpRequest,
) -> Result<HttpResponse, PublicArchiveError> {
let address = path.into_inner();
let evm_wallet = evm_wallet_data.get_ref().clone();
debug!("Updating [{}] archive from multipart PUT with store type [{:?}]", address, get_store_type(&request));
Ok(HttpResponse::Ok().json(
public_archive_service.update_public_archive(address, None, public_archive_form, evm_wallet, get_store_type(&request)).await?
))
}
#[utoipa::path(
put,
path = "/anttp-0/multipart/public_archive/{address}/{path}",
request_body(
content = PublicArchiveForm,
content_type = "multipart/form-data"
),
responses(
(status = OK, description = "Public archive updated successfully", body = ArchiveResponse)
),
params(
("address" = String, Path, description = "Public archive address"),
("path" = String, Path, description = "Target path (directory) for all uploads"),
("x-store-type", Header, description = "Only persist to cache and do not publish (memory|disk|none)",
example = "memory"),
),
)]
pub async fn put_public_archive(
path_params: web::Path<(String, String)>,
public_archive_form: MultipartForm<PublicArchiveForm>,
public_archive_service: Data<PublicArchiveService>,
evm_wallet_data: Data<Wallet>,
request: HttpRequest,
) -> Result<HttpResponse, PublicArchiveError> {
let (address, mut path) = path_params.into_inner();
path = path.replace("%2F", "/");
let evm_wallet = evm_wallet_data.get_ref().clone();
debug!("Updating [{}] archive from multipart PUT at path [{}] with store type [{:?}]", address, path, get_store_type(&request));
Ok(HttpResponse::Ok().json(
public_archive_service.update_public_archive(address, Some(path), public_archive_form, evm_wallet, get_store_type(&request)).await?
))
}
#[utoipa::path(
get,
path = "/anttp-0/public_archive/{address}",
responses(
(status = OK, description = "Public archive retrieved successfully", body = ArchiveResponse)
),
params(
("address" = String, Path, description = "Public archive address"),
),
)]
pub async fn get_public_archive_root(
path_params: web::Path<String>,
public_archive_service: Data<PublicArchiveService>,
) -> Result<HttpResponse, PublicArchiveError> {
let address = path_params.into_inner();
debug!("Getting public archive root for address [{}]", address);
Ok(HttpResponse::Ok().json(
public_archive_service.get_public_archive(address, None).await?
))
}
#[utoipa::path(
get,
path = "/anttp-0/public_archive/{address}/{path}",
responses(
(status = OK, description = "Public archive retrieved successfully", body = ArchiveResponse)
),
params(
("address" = String, Path, description = "Public archive address"),
("path" = String, Path, description = "Path to directory or file within the archive"),
),
)]
pub async fn get_public_archive(
path_params: web::Path<(String, String)>,
public_archive_service: Data<PublicArchiveService>,
) -> Result<HttpResponse, PublicArchiveError> {
let (address, mut path) = path_params.into_inner();
path = path.replace("%2F", "/");
debug!("Getting public archive for address [{}] and path [{}]", address, path);
Ok(HttpResponse::Ok().json(
public_archive_service.get_public_archive(address, Some(path)).await?
))
}
#[utoipa::path(
delete,
path = "/anttp-0/public_archive/{address}/{path}",
responses(
(status = OK, description = "Public archive truncated successfully", body = Upload)
),
params(
("address" = String, Path, description = "Public archive address"),
("path" = String, Path, description = "Path to directory or file within the archive to be deleted"),
("x-store-type", Header, description = "Only persist to cache and do not publish (memory|disk|none)",
example = "memory"),
),
)]
pub async fn delete_public_archive(
path_params: web::Path<(String, String)>,
public_archive_service: Data<PublicArchiveService>,
evm_wallet_data: Data<Wallet>,
request: HttpRequest,
) -> Result<HttpResponse, PublicArchiveError> {
let (address, mut path) = path_params.into_inner();
path = path.replace("%2F", "/");
let evm_wallet = evm_wallet_data.get_ref().clone();
debug!("Truncating public archive at address [{}] and path [{}]", address, path);
Ok(HttpResponse::Ok().json(
public_archive_service.truncate_public_archive(address, path, evm_wallet, get_store_type(&request)).await?
))
}
#[utoipa::path(
post,
path = "/anttp-0/public_archive/{address}",
responses(
(status = OK, description = "Public archive pushed successfully", body = Upload)
),
params(
("address" = String, Path, description = "Public archive address"),
("x-store-type", Header, description = "Target store type (memory|disk|network)", example = "network"),
),
)]
pub async fn push_public_archive(
path: web::Path<String>,
public_archive_service: Data<PublicArchiveService>,
evm_wallet_data: Data<Wallet>,
request: HttpRequest,
) -> Result<HttpResponse, PublicArchiveError> {
let address = path.into_inner();
let evm_wallet = evm_wallet_data.get_ref().clone();
debug!("Pushing public archive [{}] to target store type [{:?}]", address, get_store_type(&request));
Ok(HttpResponse::Ok().json(
public_archive_service.push_public_archive(address, evm_wallet, get_store_type(&request)).await?
))
}
*/