Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/strong-dolphins-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@thirdweb-dev/solana": patch
"@thirdweb-dev/storage": patch
---

Update API for instantiating storage
6 changes: 3 additions & 3 deletions packages/solana/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export class ThirdwebSDK {

constructor(
connection: Connection,
storage: ThirdwebStorage = new ThirdwebStorage(
new IpfsUploader({ uploadWithGatewayUrl: true }),
),
storage: ThirdwebStorage = new ThirdwebStorage({
uploader: new IpfsUploader({ uploadWithGatewayUrl: true }),
}),
) {
this.connection = connection;
this.storage = storage;
Expand Down
3 changes: 1 addition & 2 deletions packages/storage/src/core/downloaders/storage-downloader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { prepareGatewayUrls } from "../../common/urls";
import { replaceSchemeWithGatewayUrl } from "../../common/utils";
import { GatewayUrls, IStorageDownloader } from "../../types";
import fetch from "cross-fetch";
Expand All @@ -10,7 +9,7 @@ import fetch from "cross-fetch";
* ```jsx
* // Can instantiate the downloader with the default gateway URLs
* const downloader = new StorageDownloader();
* const storage = new ThirdwebStorage(undefined, downloader);
* const storage = new ThirdwebStorage({ downloader });
* ```
*
* @public
Expand Down
15 changes: 6 additions & 9 deletions packages/storage/src/core/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
IStorageDownloader,
IStorageUploader,
Json,
ThirdwebStorageOptions,
UploadOptions,
} from "../types";
import { StorageDownloader } from "./downloaders/storage-downloader";
Expand Down Expand Up @@ -42,7 +43,7 @@ import { IpfsUploader } from "./uploaders/ipfs-uploader";
* };
* const downloader = new StorageDownloader();
* const uploader = new IpfsUploader();
* const storage = new ThirdwebStorage(uploader, downloader, gatewayUrls)
* const storage = new ThirdwebStorage({ uploader, downloader, gatewayUrls })
* ```
*
* @public
Expand All @@ -52,14 +53,10 @@ export class ThirdwebStorage<T extends UploadOptions = IpfsUploadBatchOptions> {
private downloader: IStorageDownloader;
public gatewayUrls: GatewayUrls;

constructor(
uploader: IStorageUploader<T> = new IpfsUploader(),
downloader: IStorageDownloader = new StorageDownloader(),
gatewayUrls?: GatewayUrls,
) {
this.uploader = uploader;
this.downloader = downloader;
this.gatewayUrls = prepareGatewayUrls(gatewayUrls);
constructor(options?: ThirdwebStorageOptions<T>) {
this.uploader = options?.uploader || new IpfsUploader();
this.downloader = options?.downloader || new StorageDownloader();
this.gatewayUrls = prepareGatewayUrls(options?.gatewayUrls);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/storage/src/core/uploaders/ipfs-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import FormData from "form-data";
* ```jsx
* // Can instantiate the uploader with default configuration
* const uploader = new StorageUploader();
* const storage = new ThirdwebStorage(uploader);
* const storage = new ThirdwebStorage({ uploader });
*
* // Or optionally, can pass configuration
* const options = {
* // Upload objects with resolvable URLs
* uploadWithGatewayUrl: true,
* }
* const storage = new ThirdwebStorage(options);
* const uploader = new StorageUploader(options);
* const storage = new ThirdwebStorage({ uploader });
* ```
*
* @public
Expand Down
9 changes: 9 additions & 0 deletions packages/storage/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { GatewayUrls, IStorageDownloader } from "./download";
import { IStorageUploader, UploadOptions } from "./upload";

export type ThirdwebStorageOptions<T extends UploadOptions> = {
uploader?: IStorageUploader<T>;
downloader?: IStorageDownloader;
gatewayUrls?: GatewayUrls;
};

export * from "./upload";
export * from "./download";
export * from "./data";
6 changes: 3 additions & 3 deletions packages/storage/test/ipfs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ describe("IPFS", async () => {
});

it("Should upload without directory if specified on class", async () => {
const solanaStorage = new ThirdwebStorage(
new IpfsUploader({ uploadWithGatewayUrl: true }),
);
const solanaStorage = new ThirdwebStorage({
uploader: new IpfsUploader({ uploadWithGatewayUrl: true }),
});

const uri = await solanaStorage.upload(
{
Expand Down