forked from mito-systems/sol-mem-gen
Revert to old uploadToPinata()
This commit is contained in:
parent
12a6174b13
commit
affab021a3
@ -12,8 +12,7 @@
|
||||
"@coral-xyz/anchor": "^0.30.1",
|
||||
"@fal-ai/client": "^1.2.1",
|
||||
"@google/generative-ai": "^0.21.0",
|
||||
"@pinata/sdk": "^2.1.0",
|
||||
"@solana/spl-token": "^0.3.11",
|
||||
"@solana/spl-token": "^0.3.8",
|
||||
"@solana/web3.js": "^1.78.4",
|
||||
"big.js": "^6.2.2",
|
||||
"bn.js": "^5.2.0",
|
||||
|
@ -88,7 +88,6 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
|
||||
// Extract the image URL from the response
|
||||
const imageUrl = result.data?.images?.[0]?.url
|
||||
console.log(imageUrl);
|
||||
|
||||
if (!imageUrl) {
|
||||
console.error('No image URL in response:', result)
|
||||
|
@ -64,4 +64,4 @@ export async function GET(req: NextRequest) {
|
||||
console.error('API route error:', error);
|
||||
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,33 +34,6 @@ const provider = new anchor.AnchorProvider(
|
||||
|
||||
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> {
|
||||
|
||||
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
|
||||
recipient: recipientPubKey,
|
||||
updateRecipientMode: 0,
|
||||
cancelMode: 1,
|
||||
cancelMode: 1, // Only creator can cancel the lock
|
||||
tokenProgram: TOKEN_PROGRAM_ID,
|
||||
});
|
||||
|
||||
|
@ -1,49 +1,28 @@
|
||||
import PinataClient from "@pinata/sdk"
|
||||
import { PinataSDK } from 'pinata-web3';
|
||||
import 'dotenv/config';
|
||||
import assert from 'assert';
|
||||
|
||||
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_SECRET_KEY, "PINATA_SECRET_KEY is required");
|
||||
assert(process.env.PINATA_JWT, "PINATA_SECRET_KEY is required");
|
||||
assert(process.env.PINATA_GATEWAY);
|
||||
assert(process.env.PINATA_JWT, "PINATA_JWT is required");
|
||||
assert(process.env.PINATA_GATEWAY, "PINATA_GATEWAY is required");
|
||||
|
||||
const pinata = new PinataClient({
|
||||
pinataApiKey: process.env.PINATA_API_KEY,
|
||||
pinataSecretApiKey: process.env.PINATA_SECRET_KEY,
|
||||
pinataJWTKey: process.env.PINATA_JWT
|
||||
const pinata = new PinataSDK({
|
||||
pinataJwt: process.env.PINATA_JWT,
|
||||
pinataGateway: process.env.PINATA_GATEWAY,
|
||||
});
|
||||
|
||||
|
||||
export async function uploadToPinata(imageUrl: string): Promise<FluxGenerationResult> {
|
||||
try {
|
||||
const response = await axios.get(imageUrl, {
|
||||
responseType: 'arraybuffer'
|
||||
});
|
||||
const upload = await pinata.upload.url(imageUrl);
|
||||
|
||||
// Create form data
|
||||
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}`;
|
||||
const publicURL = await pinata.gateways.convert(upload.IpfsHash);
|
||||
|
||||
return { imageUrl: publicURL };
|
||||
} catch (error) {
|
||||
console.error('Error uploading to Pinata:', error);
|
||||
console.error('Error uploading to Pinata:', error)
|
||||
return {
|
||||
error: error instanceof Error ? error.message : 'Upload failed'
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user