Skip to content

Commit

Permalink
add support for formPost extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tamland committed Oct 18, 2024
1 parent 9888679 commit 457c743
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/shared/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,26 @@ export class API {

constructor(private auth: AuthService) {
this.fetch = (path: string, params: any) => {
const url = `${this.auth.server}/${path}?${toQueryString({
...params,
v: '1.15.0',
f: 'json',
c: this.clientName,
})}&${this.auth.urlParams}`

return window
.fetch(url, {
params = { ...params, v: '1.15.0', f: 'json', c: this.clientName }

const request = auth.serverInfo?.extensions.includes('formPost')
? new Request(`${this.auth.server}/${path}`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `${toQueryString(params)}&${this.auth.urlParams}`
})
: new Request(`${this.auth.server}/${path}?${toQueryString(params)}&${this.auth.urlParams}`, {
method: 'GET',
headers: { Accept: 'application/json' }
headers: {
Accept: 'application/json',
}
})

return window
.fetch(request)
.then(response => {
if (response.ok) {
return response.json()
Expand Down

0 comments on commit 457c743

Please sign in to comment.