Skip to content

Commit

Permalink
fix: Add custom header options to gateway methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stevedylandev committed Sep 24, 2024
1 parent 3f8b4b8 commit d5423a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
17 changes: 13 additions & 4 deletions src/core/gateway/createSignedURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,22 @@ export const createSignedURL = async (
endpoint = config.endpointUrl;
}

let headers: Record<string, string>;

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,
});

Expand Down
17 changes: 13 additions & 4 deletions src/core/gateway/getCid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,21 @@ export const getCid = async (
endpoint = config.endpointUrl;
}

let headers: Record<string, string>;

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,
});

Expand Down

0 comments on commit d5423a0

Please sign in to comment.