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

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions .changes/feat-download-on-post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
upload: patch
upload-js: 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.

6 changes: 4 additions & 2 deletions plugins/upload/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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 @@ -61,7 +62,8 @@ async function download(
url,
filePath,
headers: headers ?? {},
onProgress
onProgress,
body
})
}

Expand Down
10 changes: 7 additions & 3 deletions plugins/upload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ async fn download(
file_path: &str,
headers: HashMap<String, String>,
on_progress: Channel<ProgressPayload>,
body: Option<String>,
) -> Result<()> {
let client = reqwest::Client::new();

let mut request = client.get(url);
// Loop through the headers keys and values
if let Some(body) = body {
client.post(url).body(body)
} 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