Revert to old uploadToPinata()

This commit is contained in:
AdityaSalunkhe21 2025-02-06 10:48:44 +05:30 committed by Adw8
parent 12a6174b13
commit affab021a3
5 changed files with 14 additions and 64 deletions

View File

@ -12,8 +12,7 @@
"@coral-xyz/anchor": "^0.30.1", "@coral-xyz/anchor": "^0.30.1",
"@fal-ai/client": "^1.2.1", "@fal-ai/client": "^1.2.1",
"@google/generative-ai": "^0.21.0", "@google/generative-ai": "^0.21.0",
"@pinata/sdk": "^2.1.0", "@solana/spl-token": "^0.3.8",
"@solana/spl-token": "^0.3.11",
"@solana/web3.js": "^1.78.4", "@solana/web3.js": "^1.78.4",
"big.js": "^6.2.2", "big.js": "^6.2.2",
"bn.js": "^5.2.0", "bn.js": "^5.2.0",

View File

@ -88,7 +88,6 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
// Extract the image URL from the response // Extract the image URL from the response
const imageUrl = result.data?.images?.[0]?.url const imageUrl = result.data?.images?.[0]?.url
console.log(imageUrl);
if (!imageUrl) { if (!imageUrl) {
console.error('No image URL in response:', result) console.error('No image URL in response:', result)

View File

@ -34,33 +34,6 @@ const provider = new anchor.AnchorProvider(
anchor.setProvider(provider); anchor.setProvider(provider);
export async function getMTMBalance (senderKeypair: anchor.web3.Keypair): Promise<BN> {
const mintPublicKey = new PublicKey(WSOL_MINT);
const publicKey = senderKeypair.publicKey;
const tokenAccounts = await connection.getTokenAccountsByOwner(publicKey, { mint: mintPublicKey });
let balance = new BN(0);
for (const tokenAccount of tokenAccounts.value) {
const accountInfo = await connection.getParsedAccountInfo(
tokenAccount.pubkey,
"confirmed"
);
if (!accountInfo.value || Buffer.isBuffer(accountInfo.value.data)) {
console.warn(
`Token account ${tokenAccount.pubkey.toBase58()} data is not parsed.`
);
continue;
}
const tokenAmount =
(accountInfo.value.data as any).parsed?.info?.tokenAmount?.amount || "0";
balance = balance.add(new BN(tokenAmount));
}
return balance;
};
export async function createLock(tokenLockerKeypair: anchor.web3.Keypair, recipientPubKey: anchor.web3.PublicKey, duration: BN, balance: BN): Promise<anchor.web3.PublicKey | void> { export async function createLock(tokenLockerKeypair: anchor.web3.Keypair, recipientPubKey: anchor.web3.PublicKey, duration: BN, balance: BN): Promise<anchor.web3.PublicKey | void> {
if (balance.eq(new BN(0))) { if (balance.eq(new BN(0))) {
@ -82,7 +55,7 @@ export async function createLock(tokenLockerKeypair: anchor.web3.Keypair, recipi
numberOfPeriod: new BN(1), // Only release tokens once numberOfPeriod: new BN(1), // Only release tokens once
recipient: recipientPubKey, recipient: recipientPubKey,
updateRecipientMode: 0, updateRecipientMode: 0,
cancelMode: 1, cancelMode: 1, // Only creator can cancel the lock
tokenProgram: TOKEN_PROGRAM_ID, tokenProgram: TOKEN_PROGRAM_ID,
}); });

View File

@ -1,47 +1,26 @@
import PinataClient from "@pinata/sdk" import { PinataSDK } from 'pinata-web3';
import 'dotenv/config'; import 'dotenv/config';
import assert from 'assert'; import assert from 'assert';
import { FluxGenerationResult } from '../services/fluxService'; import { FluxGenerationResult } from '../services/fluxService';
import axios from 'axios';
import FormData from 'form-data';
assert(process.env.PINATA_API_KEY, "PINATA_API_KEY is required"); assert(process.env.PINATA_JWT, "PINATA_JWT is required");
assert(process.env.PINATA_SECRET_KEY, "PINATA_SECRET_KEY is required"); assert(process.env.PINATA_GATEWAY, "PINATA_GATEWAY is required");
assert(process.env.PINATA_JWT, "PINATA_SECRET_KEY is required");
assert(process.env.PINATA_GATEWAY);
const pinata = new PinataClient({ const pinata = new PinataSDK({
pinataApiKey: process.env.PINATA_API_KEY, pinataJwt: process.env.PINATA_JWT,
pinataSecretApiKey: process.env.PINATA_SECRET_KEY, pinataGateway: process.env.PINATA_GATEWAY,
pinataJWTKey: process.env.PINATA_JWT
}); });
export async function uploadToPinata(imageUrl: string): Promise<FluxGenerationResult> { export async function uploadToPinata(imageUrl: string): Promise<FluxGenerationResult> {
try { try {
const response = await axios.get(imageUrl, { const upload = await pinata.upload.url(imageUrl);
responseType: 'arraybuffer'
});
// Create form data const publicURL = await pinata.gateways.convert(upload.IpfsHash);
const formData = new FormData();
formData.append('file', Buffer.from(response.data), {
filename: `image-${Date.now()}.jpg`,
contentType: 'image/jpeg',
});
// Use the correct Pinata method for file upload
const result = await pinata.pinFileToIPFS(formData);
if (!result.IpfsHash) {
throw new Error('IPFS hash not received from Pinata');
}
const publicURL = `${process.env.PINATA_GATEWAY}/ipfs/${result.IpfsHash}`;
return { imageUrl: publicURL }; return { imageUrl: publicURL };
} catch (error) { } catch (error) {
console.error('Error uploading to Pinata:', error); console.error('Error uploading to Pinata:', error)
return { return {
error: error instanceof Error ? error.message : 'Upload failed' error: error instanceof Error ? error.message : 'Upload failed'
}; };