Skip to content

Commit

Permalink
Merge pull request #24 from PinataCloud/fix/create-signed-url-endpoint
Browse files Browse the repository at this point in the history
fix/create signed url endpoint
  • Loading branch information
stevedylandev authored Sep 3, 2024
2 parents d6fb1e9 + 524499f commit 8a104ed
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 79 deletions.
158 changes: 80 additions & 78 deletions postinstall.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,84 @@
const colors = {
reset: "\x1b[0m",
bright: "\x1b[1m",
fg: {
yellow: "\x1b[33m",
cyan: "\x1b[36m",
green: "\x1b[32m",
},
dim: "\x1b[2m",
};
(function () {
const colors = {
reset: "\x1b[0m",
bright: "\x1b[1m",
fg: {
yellow: "\x1b[33m",
cyan: "\x1b[36m",
green: "\x1b[32m",
},
dim: "\x1b[2m",
};

const boxWidth = 70;
const horizontalBorder = "+" + "=".repeat(boxWidth - 2) + "+";
const emptyLine = "|" + " ".repeat(boxWidth - 2) + "|";
const boxWidth = 70;
const horizontalBorder = "+" + "=".repeat(boxWidth - 2) + "+";
const emptyLine = "|" + " ".repeat(boxWidth - 2) + "|";

function stripAnsi(str) {
return str.replace(/\x1b\[[0-9;]*m/g, "");
}
function stripAnsi(str) {
return str.replace(/\x1b\[[0-9;]*m/g, "");
}

function centeredText(text, width) {
const visibleLength = stripAnsi(text).length;
const padding = Math.max(0, width - visibleLength);
const leftPad = Math.floor(padding / 2);
const rightPad = padding - leftPad;
return "|" + " ".repeat(leftPad) + text + " ".repeat(rightPad) + "|";
}
function centeredText(text, width) {
const visibleLength = stripAnsi(text).length;
const padding = Math.max(0, width - visibleLength);
const leftPad = Math.floor(padding / 2);
const rightPad = padding - leftPad;
return "|" + " ".repeat(leftPad) + text + " ".repeat(rightPad) + "|";
}

console.log("\n" + colors.fg.yellow + horizontalBorder + colors.reset);
console.log(colors.fg.yellow + emptyLine + colors.reset);
console.log(
colors.fg.yellow +
centeredText(
colors.bright +
colors.fg.yellow +
"🚨 ATTENTION IPFS USERS! 🚨" +
colors.reset,
boxWidth - 2,
) +
colors.reset,
);
console.log(colors.fg.yellow + emptyLine + colors.reset);
console.log(
colors.fg.yellow +
centeredText(
colors.fg.cyan +
"If you're looking to use IPFS please install pinata-web3 instead." +
colors.reset,
boxWidth - 2,
) +
colors.reset,
);
console.log(colors.fg.yellow + emptyLine + colors.reset);
console.log(
colors.fg.yellow +
centeredText(
colors.fg.green + "npm install pinata-web3" + colors.reset,
boxWidth - 2,
) +
colors.reset,
);
console.log(colors.fg.yellow + emptyLine + colors.reset);
console.log(
colors.fg.yellow +
centeredText(
colors.dim +
"For more information please see our documentation at" +
colors.reset,
boxWidth - 2,
) +
colors.reset,
);
console.log(
colors.fg.yellow +
centeredText(
colors.dim + "https://docs.pinata.cloud/web3/sdk" + colors.reset,
boxWidth - 2,
) +
colors.reset,
);
console.log(colors.fg.yellow + emptyLine + colors.reset);
console.log(colors.fg.yellow + horizontalBorder + colors.reset);
console.log("\n");
console.log("\n" + colors.fg.yellow + horizontalBorder + colors.reset);
console.log(colors.fg.yellow + emptyLine + colors.reset);
console.log(
colors.fg.yellow +
centeredText(
colors.bright +
colors.fg.yellow +
"🚨 ATTENTION IPFS USERS! 🚨" +
colors.reset,
boxWidth - 2,
) +
colors.reset,
);
console.log(colors.fg.yellow + emptyLine + colors.reset);
console.log(
colors.fg.yellow +
centeredText(
colors.fg.cyan +
"If you're looking to use IPFS please install pinata-web3 instead." +
colors.reset,
boxWidth - 2,
) +
colors.reset,
);
console.log(colors.fg.yellow + emptyLine + colors.reset);
console.log(
colors.fg.yellow +
centeredText(
colors.fg.green + "npm install pinata-web3" + colors.reset,
boxWidth - 2,
) +
colors.reset,
);
console.log(colors.fg.yellow + emptyLine + colors.reset);
console.log(
colors.fg.yellow +
centeredText(
colors.dim +
"For more information please see our documentation at" +
colors.reset,
boxWidth - 2,
) +
colors.reset,
);
console.log(
colors.fg.yellow +
centeredText(
colors.dim + "https://docs.pinata.cloud/web3/sdk" + colors.reset,
boxWidth - 2,
) +
colors.reset,
);
console.log(colors.fg.yellow + emptyLine + colors.reset);
console.log(colors.fg.yellow + horizontalBorder + colors.reset);
console.log("\n");
})();
8 changes: 7 additions & 1 deletion src/core/gateway/createSignedURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export const createSignedURL = async (
method: "GET",
});

let endpoint: string = "https://api.pinata.cloud/v3";

if (config.endpointUrl) {
endpoint = config.endpointUrl;
}

// const params = new URLSearchParams();
// if (config?.pinataGatewayKey) {
// params.append("pinataGatewayToken", config.pinataGatewayKey);
Expand Down Expand Up @@ -57,7 +63,7 @@ export const createSignedURL = async (
// }

try {
const request = await fetch("https://api.pinata.cloud/v3/files/sign", {
const request = await fetch(`${endpoint}/files/sign`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down

0 comments on commit 8a104ed

Please sign in to comment.