This commit is contained in:
syuilo
2021-05-23 12:32:58 +09:00
parent e7eac5baa7
commit 8d3f9d7e34
2 changed files with 40 additions and 6 deletions

View File

@@ -33,14 +33,12 @@ export class APIClient {
endpoint: E, data: Endpoints[E]['req'] = {}, credential?: string | null | undefined,
): Promise<Endpoints[E]['res']> {
const promise = new Promise<Endpoints[E]['res']>((resolve, reject) => {
// Append a credential
if (this.credential) (data as Record<string, any>).i = this.credential;
if (credential) (data as Record<string, any>).i = credential;
// Send request
this.fetch(`${this.origin}/api/${endpoint}`, {
method: 'POST',
body: JSON.stringify(data),
body: JSON.stringify({
...data,
i: credential !== undefined ? credential : this.credential
}),
credentials: 'omit',
cache: 'no-cache'
}).then(async (res) => {