Skip to content

Commit

Permalink
feat: Added hot swap methods to Files class
Browse files Browse the repository at this point in the history
  • Loading branch information
stevedylandev committed Sep 20, 2024
1 parent 0863360 commit 343f67e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ export const deleteSwap = async (
};
}

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

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

try {
const request = await fetch(`${endpoint}/v3/ipfs/swap/${cid}`, {
const request = await fetch(`${endpoint}/files/swap/${cid}`, {
method: "DELETE",
headers: headers,
});
Expand Down
6 changes: 3 additions & 3 deletions src/core/gateway/swapCid.ts → src/core/files/swapCid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const swapCid = async (
}

const data = JSON.stringify({
swapCid: options.swapCid,
swap_cid: options.swapCid,
});

let headers: Record<string, string>;
Expand All @@ -64,14 +64,14 @@ export const swapCid = async (
};
}

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

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

try {
const request = await fetch(`${endpoint}/v3/ipfs/swap/${options.cid}`, {
const request = await fetch(`${endpoint}/files/swap/${options.cid}`, {
method: "PUT",
headers: headers,
body: data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ export const swapHistory = async (
};
}

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

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

try {
const request = await fetch(
`${endpoint}/v3/ipfs/swap/${options.cid}?domain=${options.domain}`,
`${endpoint}/files/swap/${options.cid}?domain=${options.domain}`,
{
method: "GET",
headers: headers,
Expand Down
42 changes: 15 additions & 27 deletions src/core/pinataSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ import { deleteGroup } from "./groups/deleteGroup";
// import { removeSignature } from "./signatures/removeSignature";
import { analyticsTopUsage } from "./gateway/analyticsTopUsage";
import { analyticsDateInterval } from "./gateway/analyticsDateInterval";
import { swapCid } from "./gateway/swapCid";
import { swapHistory } from "./gateway/swapHistory";
import { deleteSwap } from "./gateway/deleteSwap";
import { swapCid } from "./files/swapCid";
import { swapHistory } from "./files/swapHistory";
import { deleteSwap } from "./files/deleteSwap";
import { containsCID } from "../utils/gateway-tools";
import { createSignedURL } from "./gateway/createSignedURL";

Expand Down Expand Up @@ -146,6 +146,18 @@ class Files {
update(options: UpdateFileOptions): Promise<FileListItem> {
return updateFile(this.config, options);
}

addSwap(options: SwapCidOptions): Promise<SwapCidResponse> {
return swapCid(this.config, options);
}

getSwapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]> {
return swapHistory(this.config, options);
}

deleteSwap(cid: string): Promise<string> {
return deleteSwap(this.config, cid);
}
}

class UploadBuilder<T> {
Expand Down Expand Up @@ -383,18 +395,6 @@ class Gateways {
return new OptimizeImageCreateSignedURL(this.config, options);
}

// get(cid: string): OptimizeImage {
// return new OptimizeImage(this.config, cid);
// }

// convert(url: string, gatewayPrefix?: string): Promise<string> {
// return convertIPFSUrl(this.config, url, gatewayPrefix);
// }

// containsCID(cid: string): Promise<ContainsCIDResponse> {
// return containsCID(cid);
// }

// topUsageAnalytics(options: {
// domain: string;
// start: string;
Expand Down Expand Up @@ -432,18 +432,6 @@ class Gateways {
// options.interval,
// );
// }

// swapCid(options: SwapCidOptions): Promise<SwapCidResponse> {
// return swapCid(this.config, options);
// }

// swapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]> {
// return swapHistory(this.config, options);
// }

// deleteSwap(cid: string): Promise<string> {
// return deleteSwap(this.config, cid);
// }
}

class OptimizeImageGetCid {
Expand Down
4 changes: 2 additions & 2 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ export type SwapHistoryOptions = {
};

export type SwapCidResponse = {
mappedCid: string;
createdAt: string;
mapped_cid: string;
created_at: string;
};

export type ContainsCIDResponse = {
Expand Down

0 comments on commit 343f67e

Please sign in to comment.