forked from mito-systems/sol-mem-gen
Update example env for account handle
This commit is contained in:
parent
af864b4670
commit
20b4fe3182
@ -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=
|
||||
|
@ -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:
|
||||
|
@ -5,6 +5,7 @@ import { initializeDataSource } from '../../../data-source';
|
||||
|
||||
export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
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<NextResponse> {
|
||||
|
||||
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(/<a href="(https:\/\/t.co\/[^"]+)">/);
|
||||
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,
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user