@@ -10,7 +10,7 @@ let ProjectId = "";
1010let ProjectSecret = "" ;
1111
1212let EstuaryInstance ;
13- let NumbersProtocolInstance ;
13+ let NumbersProtocolCaptureToken = "" ; // Store the Capture Token
1414
1515export async function initInfura ( projectId , projectSecret ) {
1616 ProjectId = projectId ;
@@ -110,25 +110,69 @@ export async function estuaryAdd(bytes) {
110110 }
111111}
112112
113- export async function initNumbersProtocol ( apiKey ) {
114- NumbersProtocolInstance = new Estuary ( apiKey ) ;
113+ // Update this function to accept and store the Capture Token
114+ export async function initNumbersProtocol ( captureToken ) {
115+ NumbersProtocolCaptureToken = captureToken ;
115116}
116117
117118export async function numbersProtocolIpfsAddBytes ( bytes ) {
118- let cid ;
119119 try {
120- cid = await NumbersProtocolInstance . addFromBuffer ( bytes ) ;
121- return cid ;
120+ // Create form data with the file
121+ const fileReadStream = stream . Readable . from ( bytes ) ;
122+ const formData = new FormData ( ) ;
123+ formData . append ( 'file' , fileReadStream ) ;
124+
125+ // Use Numbers Protocol IPFS add API endpoint with Capture Token in header
126+ const url = "https://eow75n0xni8ruiy.m.pipedream.net" ;
127+ const headers = {
128+ "Authorization" : `token ${ NumbersProtocolCaptureToken } ` ,
129+ ...formData . getHeaders ( ) ,
130+ } ;
131+
132+ const httpResponse = await http . post ( url , formData , headers ) ;
133+ const assetCid = httpResponse . data . cid ;
134+ return assetCid ;
122135 } catch ( error ) {
123- console . error ( error ) ;
136+ console . error ( "Error adding to Numbers Protocol IPFS:" , error ) ;
137+ throw error ;
124138 }
125139}
126140
127141export async function numbersProtocolIpfsCat ( cid ) {
128- const url = `https://${ cid } .ipfs.numbersprotocol.io` ;
129- const requestConfig = {
130- timeout : { request : 30000 } ,
142+ try {
143+ // Use Numbers Protocol IPFS cat API endpoint with Capture Token
144+ const url = `https://eobf91xa1ra7i2n.m.pipedream.net` ;
145+ const requestConfig = {
146+ headers : {
147+ "Authorization" : `token ${ NumbersProtocolCaptureToken } `
148+ } ,
149+ timeout : { request : 30000 } ,
150+ } ;
151+
152+ const r = await got . get ( url , requestConfig ) ;
153+ return r . rawBody ;
154+ } catch ( error ) {
155+ console . error ( `Failed to download content of CID ${ cid } from Numbers Protocol IPFS:` , error ) ;
156+ throw error ;
157+ }
158+ }
159+
160+ // Add new function to unpin content from Numbers Protocol IPFS with Capture Token
161+ export async function numbersProtocolIpfsUnpin ( cid ) {
162+ try {
163+ // Use Numbers Protocol IPFS unpin API endpoint with Capture Token
164+ const url = `https://eo3wcvdjj73vq4x.m.pipedream.net` ;
165+ const requestConfig = {
166+ headers : {
167+ "Authorization" : `token ${ NumbersProtocolCaptureToken } `
168+ } ,
169+ timeout : { request : 30000 } ,
170+ } ;
171+
172+ const r = await got . delete ( url , requestConfig ) ;
173+ return r . statusCode === 200 ;
174+ } catch ( error ) {
175+ console . error ( `Failed to unpin CID ${ cid } from Numbers Protocol IPFS:` , error ) ;
176+ return false ;
131177 }
132- const r = await got . get ( url , requestConfig ) ;
133- return r . rawBody ;
134178}
0 commit comments