Skip to content

Commit

Permalink
Merge pull request #10 from thiagorochatr/ipfs
Browse files Browse the repository at this point in the history
fx: pinata receiving correct data
  • Loading branch information
PedroRosalba authored Oct 7, 2024
2 parents 09a8c29 + 44d54e4 commit 4924fb1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
41 changes: 22 additions & 19 deletions packages/nextjs/app/api/forms-ipfs/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { pinataClient } from '~~/utils/simpleNFT/pinataClient';

export async function POST(request: NextRequest){
try{
const mockedData = {
title: 'mocktitle',
description: 'mockdescription',
authors: 'mockauthors',
ipType: 'mockiptype',
uploadFile:''
};
// const mockedData = {
// title: 'mocktitle',
// description: 'mockdescription',
// authors: 'mockauthors',
// ipType: 'mockiptype',
// uploadFile:''
// };

// const data4 = JSON.parse(await request.json());
// console.log(data4);
Expand All @@ -27,8 +27,8 @@ export async function POST(request: NextRequest){
const title = data.get('title') as unknown as string;
const description = data.get('description') as unknown as string;
const authors = data.getAll('authors');
const ipType = data.get('ipType');
const uploadFile: File | null = data.get('uploadFile') as unknown as File;
const ipType = data.get('ipType') as string;
const uploadFile = data.get('uploadFile') as File | null;

// const data2 = request.body;
// console.log(data2);
Expand All @@ -38,27 +38,30 @@ export async function POST(request: NextRequest){
// console.log(data3);

//const file: File | null = data.get("file") as unknown as File;

// const uploadMockedData = await pinataClient.upload.json(mockedData);
// const mockedUrl = await pinataClient.gateways.convert(uploadMockedData.IpfsHash);
// console.log(mockedUrl);

// console.log('Received data:', { title, description, authors, ipType, uploadFile: uploadFile?.name });

const userObject = {
title: title,
description: description,
authors: authors,
ipType: ipType,
uploadFile: uploadFile
title,
description,
authors,
ipType,
uploadFile: uploadFile ? uploadFile.name : null,
};

// console.log('Attempting to upload to Pinata:', userObject);

const uploadData = await pinataClient.upload.json(userObject);
// console.log('Pinata upload successful:', uploadData);
const url = await pinataClient.gateways.convert(uploadData.IpfsHash);

console.log(url);
// console.log('Converted IPFS URL:', url);

//aqui eu chamo a função de MINTAR

return NextResponse.json(url, { status: 200 });

return NextResponse.json({ ipfsHash: uploadData.IpfsHash, url }, { status: 200 });
// const data = await request.formData();
} catch (e) {
console.log(e);
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/app/uploadIP/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const uploadIP = () => {

const data = await response.json();
console.log(data);
setipfsHash(data.metadataHash);
setipfsHash(data.ipfsHash);


} catch (err) {
Expand Down

0 comments on commit 4924fb1

Please sign in to comment.