Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Conversation

adam-maj
Copy link
Contributor

No description provided.

@adam-maj adam-maj changed the title am/ipfs ipfs bug fixes May 12, 2022
Copy link
Member

@jnsdls jnsdls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left an initial batch of reviews

Comment on lines +26 to +31
constructor(
gatewayUrl: string = DEFAULT_IPFS_GATEWAY,
uploader: IStorageUpload = new IpfsUploader(),
) {
this.gatewayUrl = `${gatewayUrl.replace(/\/$/, "")}/`;
this.uploader = uploader;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we could not have 2 params here, can the gatewayUrl be part of the IpfsUploader() interface and then we just pass that in here by itself? this api just doesn't feel clean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are separate concerns though - the uploader is just for uploading files, whereas the gateway is for file download - these are two separate things may want to specify (ie I want filebase upload + pinata gateway download) - it doesn't seem right for gateway to be on the uploader considering its used in the main IpfsStorage interface.

Also fwiw, this is an internal interface - the public storage interface is now different (src/core/classes/storage.ts)

Copy link
Member

@joaquim-verges joaquim-verges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so nice to have upload progress now 🔥 xhr FTW

return this.storage.get(hash);
}

public async upload(data: FileOrBuffer[] | JsonObject[]): Promise<string> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm can this be (FileOrBuffer | JsonObject)[] | (FileOrBuffer | JsonObject)

so i can pass a single thing if i want to?

also the return type should give me both the base uri and the individual uris i think right?

Copy link
Member

@joaquim-verges joaquim-verges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple of nits - let's merge an iterate

/**
* @internal
*/
export const TW_FILEBASE_SERVER_URL = "http://localhost:3002";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this used for?

*/
public async upload(
data: FileOrBuffer[] | JsonObject[] | FileOrBuffer | JsonObject,
): Promise<string> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would still be nice to also return the individual uris here, or at least something like the total number of files uploaded?

@lgtm-com
Copy link

lgtm-com bot commented May 14, 2022

This pull request introduces 1 alert when merging 27fa534 into 79d199d - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

/**
* IPFS Storage implementation, accepts custom IPFS gateways
* @public
*/
export class IpfsStorage implements IStorage {
private gatewayUrl: string;
private failedUrls: string[] = [];
public uploader: IStorageUpload;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't need to be public right?

* @returns - The one time use token that can be passed to the Pinata API.
*/
getUploadToken(contractAddress: string): Promise<string>;
uploader: IStorageUpload;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also doesn't need to be in the interface, it's an implementation detail


data.append("pinataMetadata", JSON.stringify(metadata));

if (typeof window === "undefined") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man i would reaaaaally love this for the thirdweb CLI - what would it take to make it happen?

@lgtm-com
Copy link

lgtm-com bot commented May 16, 2022

This pull request introduces 1 alert when merging a122f98 into 79d199d - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@jnsdls jnsdls self-requested a review May 26, 2022 02:27
Copy link
Member

@joaquim-verges joaquim-verges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like there was a bad merge in the ThirdwebSDK constructor!

src/core/sdk.ts Outdated
this.storage = storage;
this.deployer = new ContractDeployer(rpc, options, storage);
this.wallet = new UserWallet(rpc, options);
super(network, options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened to my getProviderForNetwork here?

package.json Outdated
@@ -91,6 +92,7 @@
"form-data": "^4.0.0",
"keccak256": "^1.0.6",
"merkletreejs": "^0.2.24",
"request": "^2.88.2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're not using this are we?

Copy link
Member

@joaquim-verges joaquim-verges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bunch of minor things + still an issue in ThirdwebSDK post merge

package.json Outdated
@@ -52,6 +52,7 @@
"@types/lodash.isequal": "^4.5.5",
"@types/mocha": "^9.1.1",
"@types/node": "^17.0.0",
"@types/request": "^2.48.8",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adam-maj what about this one? don't see it being used either?

}

/**
* Upload any data to an IPFS directory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add here that we handle pinning for you?

* fs.readFileSync("file2.png"),
* fs.readFileSync("file3.png"),
* ]
* const uri = await sdk.storage.upload(files);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be interesting to also show an example of uploading a single json object and maybe passing the upload progress option (with a disclaimer) to show the different capabilities.

Would also add a comment on what the expected response looks like : ipfs://hash/0, ipfs://hash/1...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add an example uploading just regular JSON, and one example with a progress upload callback?

// eslint-disable-next-line @typescript-eslint/no-var-requires
globalThis.FormData = require("form-data");
}
export class IpfsUploader implements IStorageUpload {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets mark this class as @internal for now. It's not added to the index.ts of the folder is it?

import { UploadProgressEvent } from "../../types/events";
import { IStorage } from "../interfaces/IStorage";

interface StorageUpload {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one can be exported though - add it to the index.ts of the folder, and add a top level doc with @public

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, should this interface be moved to IStorageUpload ? also feels like it could be a type instead of an interface, but nbd

/**
* @internal
*/
export interface UploadBatchResult {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between this interface and StorageUpload defined above? looks the same?

fileNames: string[];
}

export interface IStorageUpload {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be @internal

src/core/sdk.ts Outdated
@@ -133,16 +134,22 @@ export class ThirdwebSDK extends RPCConnectionHandler {
*/
public wallet: UserWallet;

/**
* Upload and download files from IPFS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add 'or from your own storage service'

src/core/sdk.ts Outdated
this.storageHandler = storage;
this.storage = new Storage(storage);
this.deployer = new ContractDeployer(network, options, storage);
this.wallet = new UserWallet(network, options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adam-maj careful here - you're passingnetwork instead of the transformed provider rpc (should prob be renamed)

this will def break things

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm good catch - typing doesn't throw here understandably (maybe because of overlapping types?)

@@ -0,0 +1,11 @@
export interface UploadProgressEvent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure this gets exported properly (add to types/index.ts)

@adam-maj adam-maj changed the title ipfs bug fixes add sdk storage interface May 26, 2022
*/
uris: string[];
}
export class Storage {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adam-maj you're still not exporting this class for docs, needs to be declared in core/classes/index.ts - also add a top level class documentation 🙏

* fs.readFileSync("file2.png"),
* fs.readFileSync("file3.png"),
* ]
* const uri = await sdk.storage.upload(files);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add an example uploading just regular JSON, and one example with a progress upload callback?

options?: {
onProgress: (event: UploadProgressEvent) => void;
},
): Promise<StorageUpload>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i actually kinda liked that the type has Result in it, like StorageUploadResult, but nbd

* director and the URIs of the uploaded files.
* @public
*/
export type StorageUpload = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure this is exported in docs (add to core/interfaces/index.ts)

@joaquim-verges joaquim-verges merged commit 5032ae9 into main May 27, 2022
@joaquim-verges joaquim-verges deleted the am/ipfs branch May 27, 2022 23:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants