-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from holaplex/main
Release 10/8
- Loading branch information
Showing
6 changed files
with
2,507 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Irys from "@irys/sdk"; | ||
|
||
/** | ||
* Class representing an Uploader. | ||
*/ | ||
class Uploader { | ||
/** | ||
* Create an uploader. | ||
* @param {Object} client - The client object. | ||
*/ | ||
constructor(client, gateway) { | ||
this.client = client; | ||
this.gateway = gateway; | ||
} | ||
|
||
/** | ||
* Upload a file. | ||
* @param {Buffer} buffer - The file data as a buffer. | ||
* @return {Object} The upload response containing the URI and CID. | ||
* @throws {Error} If an error occurs during upload. | ||
*/ | ||
async upload(buffer, contentType) { | ||
const tags = [{ name: "Content-Type", value: contentType }]; | ||
|
||
const response = await this.client.upload(buffer, { tags }); | ||
|
||
const cid = response.id; | ||
const uri = `${this.gateway}/${cid}`; | ||
|
||
return { uri, cid }; | ||
} | ||
|
||
async fund(bytes) { | ||
const price = await this.client.getPrice(bytes); | ||
|
||
const response = await this.client.fund(price); | ||
|
||
fastify.log.info(response); | ||
|
||
return price; | ||
} | ||
} | ||
|
||
export function irys(gateway, url, providerUrl, key) { | ||
const irys = new Irys({ | ||
url, // URL of the node you want to connect to | ||
token: "solana", // Token used for payment | ||
key, // ETH or SOL private key | ||
config: { | ||
providerUrl, | ||
}, | ||
}); | ||
|
||
return new Uploader(irys, gateway); | ||
} |
Oops, something went wrong.