mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-07-12 16:36:33 +02:00
feat(upload): Add HTTP method selection for upload (#2991)
Co-authored-by: Fabian-Lars <github@fabianlars.de>
This commit is contained in:
committed by
GitHub
parent
6b854421a1
commit
ad910b1135
@@ -13,11 +13,19 @@ interface ProgressPayload {
|
||||
|
||||
type ProgressHandler = (progress: ProgressPayload) => void
|
||||
|
||||
enum HttpMethod {
|
||||
Post = 'POST',
|
||||
Put = 'PUT',
|
||||
Patch = 'PATCH'
|
||||
}
|
||||
|
||||
async function upload(
|
||||
url: string,
|
||||
filePath: string,
|
||||
progressHandler?: ProgressHandler,
|
||||
headers?: Map<string, string>
|
||||
// TODO: V3 - Combine headers and methods into one `options` object
|
||||
headers?: Map<string, string>,
|
||||
method?: HttpMethod
|
||||
): Promise<string> {
|
||||
const ids = new Uint32Array(1)
|
||||
window.crypto.getRandomValues(ids)
|
||||
@@ -33,6 +41,7 @@ async function upload(
|
||||
url,
|
||||
filePath,
|
||||
headers: headers ?? {},
|
||||
method: method ?? HttpMethod.Post,
|
||||
onProgress
|
||||
})
|
||||
}
|
||||
@@ -67,4 +76,4 @@ async function download(
|
||||
})
|
||||
}
|
||||
|
||||
export { download, upload }
|
||||
export { download, upload, HttpMethod }
|
||||
|
||||
Reference in New Issue
Block a user