feat(core): switch to native fetch API for all HTTP requests
This commit is contained in:
@@ -47,17 +47,19 @@ export class BunqAttachment {
|
||||
'X-Bunq-Client-Authentication': this.bunqAccount.apiContext.getSession().getContext().sessionToken
|
||||
};
|
||||
|
||||
const requestOptions = {
|
||||
method: 'PUT' as const,
|
||||
headers: headers,
|
||||
requestBody: options.body
|
||||
};
|
||||
|
||||
await plugins.smartrequest.request(
|
||||
const response = await fetch(
|
||||
`${this.bunqAccount.apiContext.getBaseUrl()}${uploadUrl}`,
|
||||
requestOptions
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: headers,
|
||||
body: options.body
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to upload attachment: HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
return attachmentUuid;
|
||||
}
|
||||
|
||||
@@ -67,7 +69,7 @@ export class BunqAttachment {
|
||||
public async getContent(attachmentUuid: string): Promise<Buffer> {
|
||||
await this.bunqAccount.apiContext.ensureValidSession();
|
||||
|
||||
const response = await plugins.smartrequest.request(
|
||||
const response = await fetch(
|
||||
`${this.bunqAccount.apiContext.getBaseUrl()}/v1/attachment-public/${attachmentUuid}/content`,
|
||||
{
|
||||
method: 'GET',
|
||||
@@ -77,7 +79,12 @@ export class BunqAttachment {
|
||||
}
|
||||
);
|
||||
|
||||
return Buffer.from(response.body);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get attachment: HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
return Buffer.from(arrayBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user