Skip to content

Commit

Permalink
fix(api): Rename FormPart value to file to match docs and endpoint (
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianLars committed Jun 9, 2022
1 parent 69ae6f1 commit 55f89d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changes/api-fix-form-body.md
@@ -0,0 +1,5 @@
---
"api": patch
---

Fix `FilePart` usage in `http.Body.form` by renaming the `value` property to `file`.
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions tooling/api/src/http.ts
Expand Up @@ -62,7 +62,7 @@ enum ResponseType {
}

interface FilePart<T> {
value: string | T
file: string | T
mime?: string
fileName?: string
}
Expand Down Expand Up @@ -96,7 +96,7 @@ class Body {
* Body.form({
* key: 'value',
* image: {
* file: '/path/to/file', // either a path of an array buffer of the file contents
* file: '/path/to/file', // either a path or an array buffer of the file contents
* mime: 'image/jpeg', // optional
* fileName: 'image.jpg' // optional
* }
Expand All @@ -117,10 +117,10 @@ class Body {
r = v
} else if (v instanceof Uint8Array || Array.isArray(v)) {
r = Array.from(v)
} else if (typeof v.value === 'string') {
r = { value: v.value, mime: v.mime, fileName: v.fileName }
} else if (typeof v.file === 'string') {
r = { file: v.file, mime: v.mime, fileName: v.fileName }
} else {
r = { value: Array.from(v.value), mime: v.mime, fileName: v.fileName }
r = { file: Array.from(v.file), mime: v.mime, fileName: v.fileName }
}
// eslint-disable-next-line security/detect-object-injection
form[key] = r
Expand Down

0 comments on commit 55f89d5

Please sign in to comment.