@@ -66,15 +66,12 @@ struct ProgressPayload {
66
66
67
67
#[ command]
68
68
async fn download (
69
- url : & str ,
70
- file_path : & str ,
69
+ url : String ,
70
+ file_path : String ,
71
71
headers : HashMap < String , String > ,
72
72
body : Option < String > ,
73
73
on_progress : Channel < ProgressPayload > ,
74
74
) -> Result < ( ) > {
75
- let url = url. to_string ( ) ;
76
- let file_path = file_path. to_string ( ) ;
77
-
78
75
tokio:: spawn ( async move {
79
76
let client = reqwest:: Client :: new ( ) ;
80
77
let mut request = if let Some ( body) = body {
@@ -120,14 +117,11 @@ async fn download(
120
117
121
118
#[ command]
122
119
async fn upload (
123
- url : & str ,
124
- file_path : & str ,
120
+ url : String ,
121
+ file_path : String ,
125
122
headers : HashMap < String , String > ,
126
123
on_progress : Channel < ProgressPayload > ,
127
124
) -> Result < String > {
128
- let url = url. to_string ( ) ;
129
- let file_path = file_path. to_string ( ) ;
130
-
131
125
tokio:: spawn ( async move {
132
126
// Read the file
133
127
let file = File :: open ( & file_path) . await ?;
@@ -198,15 +192,15 @@ mod tests {
198
192
#[ tokio:: test]
199
193
async fn should_error_on_download_if_status_not_success ( ) {
200
194
let mocked_server = spawn_server_mocked ( 400 ) . await ;
201
- let result = download_file ( & mocked_server. url ) . await ;
195
+ let result = download_file ( mocked_server. url ) . await ;
202
196
mocked_server. mocked_endpoint . assert ( ) ;
203
197
assert ! ( result. is_err( ) ) ;
204
198
}
205
199
206
200
#[ tokio:: test]
207
201
async fn should_download_file_successfully ( ) {
208
202
let mocked_server = spawn_server_mocked ( 200 ) . await ;
209
- let result = download_file ( & mocked_server. url ) . await ;
203
+ let result = download_file ( mocked_server. url ) . await ;
210
204
mocked_server. mocked_endpoint . assert ( ) ;
211
205
assert ! (
212
206
result. is_ok( ) ,
@@ -218,7 +212,7 @@ mod tests {
218
212
#[ tokio:: test]
219
213
async fn should_error_on_upload_if_status_not_success ( ) {
220
214
let mocked_server = spawn_upload_server_mocked ( 500 ) . await ;
221
- let result = upload_file ( & mocked_server. url ) . await ;
215
+ let result = upload_file ( mocked_server. url ) . await ;
222
216
mocked_server. mocked_endpoint . assert ( ) ;
223
217
assert ! ( result. is_err( ) ) ;
224
218
match result. unwrap_err ( ) {
@@ -230,15 +224,15 @@ mod tests {
230
224
#[ tokio:: test]
231
225
async fn should_error_on_upload_if_file_not_found ( ) {
232
226
let mocked_server = spawn_upload_server_mocked ( 200 ) . await ;
233
- let file_path = "/nonexistent/file.txt" ;
227
+ let file_path = "/nonexistent/file.txt" . to_string ( ) ;
234
228
let headers = HashMap :: new ( ) ;
235
229
let sender: Channel < ProgressPayload > =
236
230
Channel :: new ( |msg : InvokeResponseBody | -> tauri:: Result < ( ) > {
237
231
let _ = msg;
238
232
Ok ( ( ) )
239
233
} ) ;
240
234
241
- let result = upload ( & mocked_server. url , file_path, headers, sender) . await ;
235
+ let result = upload ( mocked_server. url , file_path, headers, sender) . await ;
242
236
assert ! ( result. is_err( ) ) ;
243
237
match result. unwrap_err ( ) {
244
238
Error :: Io ( _) => { }
@@ -249,7 +243,7 @@ mod tests {
249
243
#[ tokio:: test]
250
244
async fn should_upload_file_successfully ( ) {
251
245
let mocked_server = spawn_upload_server_mocked ( 200 ) . await ;
252
- let result = upload_file ( & mocked_server. url ) . await ;
246
+ let result = upload_file ( mocked_server. url ) . await ;
253
247
mocked_server. mocked_endpoint . assert ( ) ;
254
248
assert ! (
255
249
result. is_ok( ) ,
@@ -260,8 +254,8 @@ mod tests {
260
254
assert_eq ! ( response_body, "upload successful" ) ;
261
255
}
262
256
263
- async fn download_file ( url : & str ) -> Result < ( ) > {
264
- let file_path = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/test/test.txt" ) ;
257
+ async fn download_file ( url : String ) -> Result < ( ) > {
258
+ let file_path = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/test/test.txt" ) . to_string ( ) ;
265
259
let headers = HashMap :: new ( ) ;
266
260
let sender: Channel < ProgressPayload > =
267
261
Channel :: new ( |msg : InvokeResponseBody | -> tauri:: Result < ( ) > {
@@ -271,8 +265,8 @@ mod tests {
271
265
download ( url, file_path, headers, None , sender) . await
272
266
}
273
267
274
- async fn upload_file ( url : & str ) -> Result < String > {
275
- let file_path = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/test/test.txt" ) ;
268
+ async fn upload_file ( url : String ) -> Result < String > {
269
+ let file_path = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/test/test.txt" ) . to_string ( ) ;
276
270
let headers = HashMap :: new ( ) ;
277
271
let sender: Channel < ProgressPayload > =
278
272
Channel :: new ( |msg : InvokeResponseBody | -> tauri:: Result < ( ) > {
0 commit comments