From 0d3a3f42553e044b1ee224bcb076c01c0b9c211d Mon Sep 17 00:00:00 2001 From: FabianLars Date: Tue, 3 Dec 2024 13:37:50 +0100 Subject: [PATCH] fix optional value --- .changes/feat-download-on-post.md | 1 + plugins/upload/api-iife.js | 2 +- plugins/upload/guest-js/index.ts | 6 +++--- plugins/upload/package.json | 2 +- plugins/upload/src/lib.rs | 6 +++--- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.changes/feat-download-on-post.md b/.changes/feat-download-on-post.md index aebebb630..8f2fe206e 100644 --- a/.changes/feat-download-on-post.md +++ b/.changes/feat-download-on-post.md @@ -1,5 +1,6 @@ --- upload: patch +upload-js: patch --- Added post request on download function \ No newline at end of file diff --git a/plugins/upload/api-iife.js b/plugins/upload/api-iife.js index ffd056d46..5918901f7 100644 --- a/plugins/upload/api-iife.js +++ b/plugins/upload/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_PLUGIN_UPLOAD__=function(t){"use strict";function e(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function n(t,e,n,o,s){if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(t,n),n}var o,s,r;"function"==typeof SuppressedError&&SuppressedError;const i="__TAURI_TO_IPC_KEY__";class a{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,o.set(this,(()=>{})),s.set(this,0),r.set(this,{}),this.id=function(t,e=!1){return window.__TAURI_INTERNALS__.transformCallback(t,e)}((({message:t,id:i})=>{if(i===e(this,s,"f")){n(this,s,i+1),e(this,o,"f").call(this,t);const a=Object.keys(e(this,r,"f"));if(a.length>0){let t=i+1;for(const n of a.sort()){if(parseInt(n)!==t)break;{const s=e(this,r,"f")[n];delete e(this,r,"f")[n],e(this,o,"f").call(this,s),t+=1}}n(this,s,t)}}else e(this,r,"f")[i.toString()]=t}))}set onmessage(t){n(this,o,t)}get onmessage(){return e(this,o,"f")}[(o=new WeakMap,s=new WeakMap,r=new WeakMap,i)](){return`__CHANNEL__:${this.id}`}toJSON(){return this[i]()}}async function _(t,e={},n){return window.__TAURI_INTERNALS__.invoke(t,e,n)}return t.download=async function(t,e,n,o,s){const r=new Uint32Array(1);window.crypto.getRandomValues(r);const i=r[0],c=new a;n&&(c.onmessage=n),await _("plugin:upload|download",{id:i,url:t,filePath:e,headers:o??{},onProgress:c,body:s??null})},t.upload=async function(t,e,n,o){const s=new Uint32Array(1);window.crypto.getRandomValues(s);const r=s[0],i=new a;return n&&(i.onmessage=n),await _("plugin:upload|upload",{id:r,url:t,filePath:e,headers:o??{},onProgress:i})},t}({});Object.defineProperty(window.__TAURI__,"upload",{value:__TAURI_PLUGIN_UPLOAD__})} +if("__TAURI__"in window){var __TAURI_PLUGIN_UPLOAD__=function(t){"use strict";function e(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function n(t,e,n,o,s){if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(t,n),n}var o,s,r;"function"==typeof SuppressedError&&SuppressedError;const i="__TAURI_TO_IPC_KEY__";class a{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,o.set(this,(()=>{})),s.set(this,0),r.set(this,{}),this.id=function(t,e=!1){return window.__TAURI_INTERNALS__.transformCallback(t,e)}((({message:t,id:i})=>{if(i===e(this,s,"f")){n(this,s,i+1),e(this,o,"f").call(this,t);const a=Object.keys(e(this,r,"f"));if(a.length>0){let t=i+1;for(const n of a.sort()){if(parseInt(n)!==t)break;{const s=e(this,r,"f")[n];delete e(this,r,"f")[n],e(this,o,"f").call(this,s),t+=1}}n(this,s,t)}}else e(this,r,"f")[i.toString()]=t}))}set onmessage(t){n(this,o,t)}get onmessage(){return e(this,o,"f")}[(o=new WeakMap,s=new WeakMap,r=new WeakMap,i)](){return`__CHANNEL__:${this.id}`}toJSON(){return this[i]()}}async function _(t,e={},n){return window.__TAURI_INTERNALS__.invoke(t,e,n)}return t.download=async function(t,e,n,o,s){const r=new Uint32Array(1);window.crypto.getRandomValues(r);const i=r[0],c=new a;n&&(c.onmessage=n),await _("plugin:upload|download",{id:i,url:t,filePath:e,headers:o??{},onProgress:c,body:s})},t.upload=async function(t,e,n,o){const s=new Uint32Array(1);window.crypto.getRandomValues(s);const r=s[0],i=new a;return n&&(i.onmessage=n),await _("plugin:upload|upload",{id:r,url:t,filePath:e,headers:o??{},onProgress:i})},t}({});Object.defineProperty(window.__TAURI__,"upload",{value:__TAURI_PLUGIN_UPLOAD__})} diff --git a/plugins/upload/guest-js/index.ts b/plugins/upload/guest-js/index.ts index 2e98351e2..0ffeaf2a9 100644 --- a/plugins/upload/guest-js/index.ts +++ b/plugins/upload/guest-js/index.ts @@ -46,7 +46,7 @@ async function download( filePath: string, progressHandler?: ProgressHandler, headers?: Map, - body?: string, + body?: string ): Promise { const ids = new Uint32Array(1) window.crypto.getRandomValues(ids) @@ -63,8 +63,8 @@ async function download( filePath, headers: headers ?? {}, onProgress, - body: body ?? null, - }); + body: body + }) } export { download, upload } diff --git a/plugins/upload/package.json b/plugins/upload/package.json index 29d9fa777..b7f6b5857 100644 --- a/plugins/upload/package.json +++ b/plugins/upload/package.json @@ -25,6 +25,6 @@ "LICENSE" ], "dependencies": { - "@tauri-apps/api": "^2.0.3" + "@tauri-apps/api": "^2.0.0" } } diff --git a/plugins/upload/src/lib.rs b/plugins/upload/src/lib.rs index cf2d88c67..7945ed8e9 100644 --- a/plugins/upload/src/lib.rs +++ b/plugins/upload/src/lib.rs @@ -70,11 +70,11 @@ async fn download( file_path: &str, headers: HashMap, on_progress: Channel, - body: String, + body: Option, ) -> Result<()> { let client = reqwest::Client::new(); - let mut request = if !body.is_empty() { - client.post(url).body(body.to_owned()) + if let Some(body) = body { + client.post(url).body(body) } else { client.get(url) };