File tree Expand file tree Collapse file tree 1 file changed +12
-18
lines changed
Expand file tree Collapse file tree 1 file changed +12
-18
lines changed Original file line number Diff line number Diff line change 1- import fetch from 'node-fetch'
1+ import { File , FilebaseClient } from '@filebase/client' ;
2+
3+ const filebase = new FilebaseClient ( {
4+ token : process . env . FILEBASE_TOKEN ?? "" ,
5+ bucket : process . env . FILEBASE_BUCKET ?? ""
6+ } ) ;
27
38/**
4- * Send file to IPFS network via the Kleros IPFS node
9+ * Send file to IPFS network via Filebase
510 * @param {string } fileName - The name that will be used to store the file. This is useful to preserve extension type.
611 * @param {ArrayBuffer } data - The raw data from the file to upload.
712 * @returns {object } ipfs response. Should include the hash and path of the stored item.
813 */
914async function ipfsPublish (
1015 fileName : string ,
1116 data : ArrayBuffer | Buffer ,
12- ) : Promise < Record < string , string > [ ] > {
13- data = await Buffer . from ( data )
17+ ) : Promise < { hash : string ; path : string } [ ] > { // Return an array of objects with a hash property
18+ const buffer = Buffer . from ( data ) ;
1419
15- return (
16- await (
17- await fetch ( `${ process . env . IPFS_GATEWAY } /add` , {
18- method : 'POST' ,
19- body : JSON . stringify ( {
20- fileName,
21- buffer : data ,
22- } ) ,
23- headers : {
24- 'content-type' : 'application/json' ,
25- } ,
26- } )
27- ) . json ( )
28- ) . data
20+ const cid = await filebase . storeDirectory ( [ new File ( [ buffer ] , fileName ) ] ) ;
21+
22+ return [ { hash : cid , path : `${ cid } /${ fileName } ` } ] ; // Return an array
2923}
3024
3125export default ipfsPublish
You can’t perform that action at this time.
0 commit comments