Skip to content

Commit 53f7c66

Browse files
chore: Changes per review
1 parent ccbb15e commit 53f7c66

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This repo and all plugins require a Rust version of at least **1.77.2**
3333
| [store](plugins/store) | Persistent key value storage. ||||||
3434
| [stronghold](plugins/stronghold) | Encrypted, secure database. |||| ? | ? |
3535
| [updater](plugins/updater) | In-app updates for Tauri applications. ||||||
36-
| [upload](plugins/upload) | Tauri plugin for file uploads through HTTP. |||| ? | ? |
36+
| [upload](plugins/upload) | Tauri plugin for file uploads through HTTP. |||| | |
3737
| [websocket](plugins/websocket) | Open a WebSocket connection using a Rust client in JS. |||| ? | ? |
3838
| [window-state](plugins/window-state) | Persist window sizes and positions. ||||||
3939

plugins/upload/src/lib.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,12 @@ struct ProgressPayload {
6666

6767
#[command]
6868
async fn download(
69-
url: &str,
70-
file_path: &str,
69+
url: String,
70+
file_path: String,
7171
headers: HashMap<String, String>,
7272
body: Option<String>,
7373
on_progress: Channel<ProgressPayload>,
7474
) -> Result<()> {
75-
let url = url.to_string();
76-
let file_path = file_path.to_string();
77-
7875
tokio::spawn(async move {
7976
let client = reqwest::Client::new();
8077
let mut request = if let Some(body) = body {
@@ -120,14 +117,11 @@ async fn download(
120117

121118
#[command]
122119
async fn upload(
123-
url: &str,
124-
file_path: &str,
120+
url: String,
121+
file_path: String,
125122
headers: HashMap<String, String>,
126123
on_progress: Channel<ProgressPayload>,
127124
) -> Result<String> {
128-
let url = url.to_string();
129-
let file_path = file_path.to_string();
130-
131125
tokio::spawn(async move {
132126
// Read the file
133127
let file = File::open(&file_path).await?;
@@ -198,15 +192,15 @@ mod tests {
198192
#[tokio::test]
199193
async fn should_error_on_download_if_status_not_success() {
200194
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;
202196
mocked_server.mocked_endpoint.assert();
203197
assert!(result.is_err());
204198
}
205199

206200
#[tokio::test]
207201
async fn should_download_file_successfully() {
208202
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;
210204
mocked_server.mocked_endpoint.assert();
211205
assert!(
212206
result.is_ok(),
@@ -218,7 +212,7 @@ mod tests {
218212
#[tokio::test]
219213
async fn should_error_on_upload_if_status_not_success() {
220214
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;
222216
mocked_server.mocked_endpoint.assert();
223217
assert!(result.is_err());
224218
match result.unwrap_err() {
@@ -230,15 +224,15 @@ mod tests {
230224
#[tokio::test]
231225
async fn should_error_on_upload_if_file_not_found() {
232226
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();
234228
let headers = HashMap::new();
235229
let sender: Channel<ProgressPayload> =
236230
Channel::new(|msg: InvokeResponseBody| -> tauri::Result<()> {
237231
let _ = msg;
238232
Ok(())
239233
});
240234

241-
let result = upload(&mocked_server.url, file_path, headers, sender).await;
235+
let result = upload(mocked_server.url, file_path, headers, sender).await;
242236
assert!(result.is_err());
243237
match result.unwrap_err() {
244238
Error::Io(_) => {}
@@ -249,7 +243,7 @@ mod tests {
249243
#[tokio::test]
250244
async fn should_upload_file_successfully() {
251245
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;
253247
mocked_server.mocked_endpoint.assert();
254248
assert!(
255249
result.is_ok(),
@@ -260,8 +254,8 @@ mod tests {
260254
assert_eq!(response_body, "upload successful");
261255
}
262256

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();
265259
let headers = HashMap::new();
266260
let sender: Channel<ProgressPayload> =
267261
Channel::new(|msg: InvokeResponseBody| -> tauri::Result<()> {
@@ -271,8 +265,8 @@ mod tests {
271265
download(url, file_path, headers, None, sender).await
272266
}
273267

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();
276270
let headers = HashMap::new();
277271
let sender: Channel<ProgressPayload> =
278272
Channel::new(|msg: InvokeResponseBody| -> tauri::Result<()> {

0 commit comments

Comments
 (0)