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 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
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
4 changes: 2 additions & 2 deletions plugins/fs/src/file_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<'de> serde::Deserialize<'de> for FilePath {
{
struct FilePathVisitor;

impl<'de> serde::de::Visitor<'de> for FilePathVisitor {
impl serde::de::Visitor<'_> for FilePathVisitor {
type Value = FilePath;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down Expand Up @@ -169,7 +169,7 @@ impl<'de> serde::Deserialize<'de> for SafeFilePath {
{
struct SafeFilePathVisitor;

impl<'de> serde::de::Visitor<'de> for SafeFilePathVisitor {
impl serde::de::Visitor<'_> for SafeFilePathVisitor {
type Value = SafeFilePath;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion plugins/os/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct InitJavascript<'a> {
exe_extension: &'a str,
}

impl<'a> InitJavascript<'a> {
impl InitJavascript<'_> {
fn new() -> Self {
Self {
#[cfg(windows)]
Expand Down
2 changes: 1 addition & 1 deletion plugins/shell/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl OpenScope {
}
}

impl<'a> ShellScope<'a> {
impl ShellScope<'_> {
/// Validates argument inputs and creates a Tauri sidecar [`Command`].
pub fn prepare_sidecar(
&self,
Expand Down
2 changes: 1 addition & 1 deletion plugins/stronghold/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<'de> Deserialize<'de> for KeyType {
{
struct KeyTypeVisitor;

impl<'de> Visitor<'de> for KeyTypeVisitor {
impl Visitor<'_> for KeyTypeVisitor {
type Value = KeyType;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down
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
12 changes: 8 additions & 4 deletions plugins/upload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ async fn download(
url: &str,
file_path: &str,
headers: HashMap<String, String>,
body: Option<String>,
on_progress: Channel<ProgressPayload>,
) -> Result<()> {
let client = reqwest::Client::new();

let mut request = client.get(url);
// Loop through the headers keys and values
let mut request = 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 Expand Up @@ -206,7 +210,7 @@ mod tests {
let _ = msg;
Ok(())
});
download(url, file_path, headers, sender).await
download(url, file_path, headers, None, sender).await
}

async fn spawn_server_mocked(return_status: usize) -> MockedServer {
Expand Down
Loading