Part of https://www.notion.so/Deploy-memes-markto-market-188a6b22d47280e38324efab1d3de55f - Use pinata URL in frontend Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-authored-by: Adw8 <adwaitgharpure@gmail.com> Reviewed-on: deep-stack/sol-mem-gen#9 Co-authored-by: adwait <adwait@noreply.git.vdb.to> Co-committed-by: adwait <adwait@noreply.git.vdb.to>
29 lines
832 B
TypeScript
29 lines
832 B
TypeScript
import { PinataSDK } from 'pinata-web3';
|
|
import 'dotenv/config';
|
|
import assert from 'assert';
|
|
|
|
import { FluxGenerationResult } from '../services/fluxService';
|
|
|
|
assert(process.env.PINATA_JWT, "PINATA_JWT is required");
|
|
assert(process.env.PINATA_GATEWAY, "PINATA_GATEWAY is required");
|
|
|
|
const pinata = new PinataSDK({
|
|
pinataJwt: process.env.PINATA_JWT,
|
|
pinataGateway: process.env.PINATA_GATEWAY,
|
|
});
|
|
|
|
export async function uploadToPinata(imageUrl: string): Promise<FluxGenerationResult> {
|
|
try {
|
|
const upload = await pinata.upload.url(imageUrl);
|
|
|
|
const publicURL = await pinata.gateways.convert(upload.IpfsHash);
|
|
|
|
return { imageUrl: publicURL };
|
|
} catch (error) {
|
|
console.error('Error uploading to Pinata:', error)
|
|
return {
|
|
error: error instanceof Error ? error.message : 'Upload failed'
|
|
};
|
|
}
|
|
}
|