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

fix(api): Rename FormPart value to file to match docs and endpoint #4307

Merged
merged 1 commit into from
Jun 9, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/api-fix-form-body.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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