From 20b4fe3182b6790dcdc394aec7307315c8eb8f37 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Wed, 5 Feb 2025 19:14:43 +0530 Subject: [PATCH] Update example env for account handle --- .env.example | 2 +- README.md | 5 ++++- src/app/api/tweet/route.ts | 15 ++++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 2e739a6..d0d1d01 100644 --- a/.env.example +++ b/.env.example @@ -16,4 +16,4 @@ PINATA_GATEWAY= # Change to your website URL # For development: set to http://localhost:3000 SITE_URL=https://memes.markto.market -ACCOUNT_HANDLE=mark_2_market1 +NEXT_PUBLIC_ACCOUNT_HANDLE= diff --git a/README.md b/README.md index ebc347a..9ea9eef 100644 --- a/README.md +++ b/README.md @@ -40,13 +40,16 @@ This project is a Solana-based meme generator that allows users to connect their - Copy the JWT that is displayed - - Add the following to `.env.example`: + - Add the following to `.env`: ```env PINATA_JWT= # Get the gateway from https://app.pinata.cloud/gateway PINATA_GATEWAY= + + # Add the account handle to be set in the tweet + NEXT_PUBLIC_ACCOUNT_HANDLE= ``` - Run the development server: diff --git a/src/app/api/tweet/route.ts b/src/app/api/tweet/route.ts index e22c0bb..82108cd 100644 --- a/src/app/api/tweet/route.ts +++ b/src/app/api/tweet/route.ts @@ -5,6 +5,7 @@ import { initializeDataSource } from '../../../data-source'; export async function POST(req: NextRequest): Promise { try { + // TODO: Move initialization to server file await initializeDataSource(); const { tweetUrl } = await req.json(); @@ -13,23 +14,23 @@ export async function POST(req: NextRequest): Promise { const response = await fetch(url); const data = await response.json(); - const { handle, txHash } = extractData(data.html); - if (!handle || !txHash) { + const { handle, txSignature } = extractData(data.html); + if (!handle || !txSignature) { return NextResponse.json( { error: 'Verification failed' }, { status: 500 } ) } - const isSigVerified = await verifySignatureInTweet(txHash); - const isHandleCorrect = handle === process.env.ACCOUNT_HANDLE; + const isSigVerified = await verifySignatureInTweet(txSignature); + const isHandleCorrect = handle === process.env.NEXT_PUBLIC_ACCOUNT_HANDLE; const isVerified = isSigVerified && isHandleCorrect; if (!isVerified) { throw new Error('Tweet is not valid'); } - const { isFourth } = await saveTweet({ transactionSignature: txHash }); + const { isFourth } = await saveTweet({ transactionSignature: txSignature }); if (isFourth) { createTokenLockForRecipient(); } @@ -50,12 +51,12 @@ const extractData = (tweet: string | object) => { const decodedTweet = tweetText.replace(/'/g, "'").replace(/"/g, '"'); const urlMatch = decodedTweet.match(//); - const txHashMatch = decodedTweet.match(/TX Hash: '([^']+)'/); + const txSignatureMatch = decodedTweet.match(/TX Hash: '([^']+)'/); const handleMatch = decodedTweet.match(/@([A-Za-z0-9_]+)/); return { memeUrl: urlMatch ? urlMatch[1] : null, - txHash: txHashMatch ? txHashMatch[1].trim() : null, + txSignature: txSignatureMatch ? txSignatureMatch[1].trim() : null, handle: handleMatch ? handleMatch[1] : null, }; };