From d5423a0dc9c66b52a5bc30ac09630969c9379bf7 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 24 Sep 2024 13:35:36 -0400 Subject: [PATCH] fix: Add custom header options to gateway methods --- src/core/gateway/createSignedURL.ts | 17 +++++++++++++---- src/core/gateway/getCid.ts | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/core/gateway/createSignedURL.ts b/src/core/gateway/createSignedURL.ts index 478bda9..3d7ea7a 100644 --- a/src/core/gateway/createSignedURL.ts +++ b/src/core/gateway/createSignedURL.ts @@ -71,13 +71,22 @@ export const createSignedURL = async ( endpoint = config.endpointUrl; } + let headers: Record; + + if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { + headers = { ...config.customHeaders }; + } else { + headers = { + "Content-Type": "application/json", + Authorization: `Bearer ${config.pinataJwt}`, + Source: "sdk/createSignURL", + }; + } + try { const request = await fetch(`${endpoint}/files/sign`, { method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${config?.pinataJwt}`, - }, + headers: headers, body: payload, }); diff --git a/src/core/gateway/getCid.ts b/src/core/gateway/getCid.ts index 4ce1422..e5ceeeb 100644 --- a/src/core/gateway/getCid.ts +++ b/src/core/gateway/getCid.ts @@ -90,12 +90,21 @@ export const getCid = async ( endpoint = config.endpointUrl; } + let headers: Record; + + if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { + headers = { ...config.customHeaders }; + } else { + headers = { + "Content-Type": "application/json", + Authorization: `Bearer ${config.pinataJwt}`, + Source: "sdk/getCid", + }; + } + const signedUrlRequest = await fetch(`${endpoint}/files/sign`, { method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${config?.pinataJwt}`, - }, + headers: headers, body: payload, });