Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(upload): Added body to download function #1523

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/feat-download-on-post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
upload: patch
---

Added post request on download function
2 changes: 1 addition & 1 deletion plugins/upload/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions plugins/upload/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ async function download(
url: string,
filePath: string,
progressHandler?: ProgressHandler,
headers?: Map<string, string>
headers?: Map<string, string>,
body?: string,
): Promise<void> {
const ids = new Uint32Array(1)
window.crypto.getRandomValues(ids)
Expand All @@ -59,8 +60,9 @@ async function download(
url,
filePath,
headers: headers ?? {},
onProgress
})
onProgress,
body: body ?? null,
});
}

export { download, upload }
2 changes: 1 addition & 1 deletion plugins/upload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "^2.0.0"
"@tauri-apps/api": "^2.0.3"
}
}
10 changes: 7 additions & 3 deletions plugins/upload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ async fn download(
file_path: &str,
headers: HashMap<String, String>,
on_progress: Channel<ProgressPayload>,
body: String,
) -> Result<()> {
let client = reqwest::Client::new();

let mut request = client.get(url);
// Loop through the headers keys and values
let mut request = if !body.is_empty() {
client.post(url).body(body.to_owned())
} else {
client.get(url)
};
// Loop trought the headers keys and values
// and add them to the request object.
for (key, value) in headers {
request = request.header(&key, value);
Expand Down
Loading