Skip to content

Commit 05c62d7

Browse files
enri90FabianLars
andauthored
feat(upload): Added body to download function (#1523)
Co-authored-by: FabianLars <[email protected]>
1 parent ce83d53 commit 05c62d7

File tree

8 files changed

+24
-12
lines changed

8 files changed

+24
-12
lines changed

.changes/feat-download-on-post.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
upload: patch
3+
upload-js: patch
4+
---
5+
6+
Added post request on download function

plugins/fs/src/file_path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'de> serde::Deserialize<'de> for FilePath {
138138
{
139139
struct FilePathVisitor;
140140

141-
impl<'de> serde::de::Visitor<'de> for FilePathVisitor {
141+
impl serde::de::Visitor<'_> for FilePathVisitor {
142142
type Value = FilePath;
143143

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

172-
impl<'de> serde::de::Visitor<'de> for SafeFilePathVisitor {
172+
impl serde::de::Visitor<'_> for SafeFilePathVisitor {
173173
type Value = SafeFilePath;
174174

175175
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {

plugins/os/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ struct InitJavascript<'a> {
110110
exe_extension: &'a str,
111111
}
112112

113-
impl<'a> InitJavascript<'a> {
113+
impl InitJavascript<'_> {
114114
fn new() -> Self {
115115
Self {
116116
#[cfg(windows)]

plugins/shell/src/scope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl OpenScope {
224224
}
225225
}
226226

227-
impl<'a> ShellScope<'a> {
227+
impl ShellScope<'_> {
228228
/// Validates argument inputs and creates a Tauri sidecar [`Command`].
229229
pub fn prepare_sidecar(
230230
&self,

plugins/stronghold/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'de> Deserialize<'de> for KeyType {
125125
{
126126
struct KeyTypeVisitor;
127127

128-
impl<'de> Visitor<'de> for KeyTypeVisitor {
128+
impl Visitor<'_> for KeyTypeVisitor {
129129
type Value = KeyType;
130130

131131
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {

plugins/upload/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/upload/guest-js/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ async function download(
4545
url: string,
4646
filePath: string,
4747
progressHandler?: ProgressHandler,
48-
headers?: Map<string, string>
48+
headers?: Map<string, string>,
49+
body?: string
4950
): Promise<void> {
5051
const ids = new Uint32Array(1)
5152
window.crypto.getRandomValues(ids)
@@ -61,7 +62,8 @@ async function download(
6162
url,
6263
filePath,
6364
headers: headers ?? {},
64-
onProgress
65+
onProgress,
66+
body
6567
})
6668
}
6769

plugins/upload/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ async fn download(
6969
url: &str,
7070
file_path: &str,
7171
headers: HashMap<String, String>,
72+
body: Option<String>,
7273
on_progress: Channel<ProgressPayload>,
7374
) -> Result<()> {
7475
let client = reqwest::Client::new();
75-
76-
let mut request = client.get(url);
77-
// Loop through the headers keys and values
76+
let mut request = if let Some(body) = body {
77+
client.post(url).body(body)
78+
} else {
79+
client.get(url)
80+
};
81+
// Loop trought the headers keys and values
7882
// and add them to the request object.
7983
for (key, value) in headers {
8084
request = request.header(&key, value);
@@ -206,7 +210,7 @@ mod tests {
206210
let _ = msg;
207211
Ok(())
208212
});
209-
download(url, file_path, headers, sender).await
213+
download(url, file_path, headers, None, sender).await
210214
}
211215

212216
async fn spawn_server_mocked(return_status: usize) -> MockedServer {

0 commit comments

Comments
 (0)