Skip to content

Commit

Permalink
feat: add quicknode ipfs (#30)
Browse files Browse the repository at this point in the history
* feat: add quicknode ipfs

* fix: don't inline api key
  • Loading branch information
sakulstra authored Feb 28, 2024
1 parent 1879b2b commit dbeb2c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/ipfs/upload.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, it, expect } from 'vitest';
import { uploadToQuicknode } from './upload';

describe('upload', () => {
it('upload to quicknode', async () => {
if (!process.env.QUICKNODE_API_KEY) return;
const response = await uploadToQuicknode('BoredGhosts');
console.log(response);
});
});
22 changes: 21 additions & 1 deletion src/ipfs/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,25 @@ export async function uploadToTheGraph(source: string) {
method: 'POST',
body: data,
});
return await res.json();
return res.json();
}

export async function uploadToQuicknode(source: string, key?: string) {
const apiKey = process.env.QUICKNODE_API_KEY!;
const headers = new Headers();
headers.append('x-api-key', apiKey);
const data = new FormData();
data.append('Body', new Blob([source]));
data.append('Key', key || 'unknownKey');
data.append('ContentType', 'text/plain');
const res = await fetch(
'https://api.quicknode.com/ipfs/rest/v1/s3/put-object',
{
method: 'POST',
headers,
body: data,
redirect: 'follow',
},
);
return res.text();
}

0 comments on commit dbeb2c1

Please sign in to comment.