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
|
# Change to your website URL
|
||||||
# For development: set to http://localhost:3000
|
# For development: set to http://localhost:3000
|
||||||
SITE_URL=https://memes.markto.market
|
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
|
- Copy the JWT that is displayed
|
||||||
|
|
||||||
- Add the following to `.env.example`:
|
- Add the following to `.env`:
|
||||||
|
|
||||||
```env
|
```env
|
||||||
PINATA_JWT=
|
PINATA_JWT=
|
||||||
|
|
||||||
# Get the gateway from https://app.pinata.cloud/gateway
|
# Get the gateway from https://app.pinata.cloud/gateway
|
||||||
PINATA_GATEWAY=
|
PINATA_GATEWAY=
|
||||||
|
|
||||||
|
# Add the account handle to be set in the tweet
|
||||||
|
NEXT_PUBLIC_ACCOUNT_HANDLE=
|
||||||
```
|
```
|
||||||
|
|
||||||
- Run the development server:
|
- Run the development server:
|
||||||
|
@ -5,6 +5,7 @@ import { initializeDataSource } from '../../../data-source';
|
|||||||
|
|
||||||
export async function POST(req: NextRequest): Promise<NextResponse> {
|
export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||||
try {
|
try {
|
||||||
|
// TODO: Move initialization to server file
|
||||||
await initializeDataSource();
|
await initializeDataSource();
|
||||||
|
|
||||||
const { tweetUrl } = await req.json();
|
const { tweetUrl } = await req.json();
|
||||||
@ -13,23 +14,23 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
|||||||
|
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const { handle, txHash } = extractData(data.html);
|
const { handle, txSignature } = extractData(data.html);
|
||||||
if (!handle || !txHash) {
|
if (!handle || !txSignature) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: 'Verification failed' },
|
{ error: 'Verification failed' },
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSigVerified = await verifySignatureInTweet(txHash);
|
const isSigVerified = await verifySignatureInTweet(txSignature);
|
||||||
const isHandleCorrect = handle === process.env.ACCOUNT_HANDLE;
|
const isHandleCorrect = handle === process.env.NEXT_PUBLIC_ACCOUNT_HANDLE;
|
||||||
|
|
||||||
const isVerified = isSigVerified && isHandleCorrect;
|
const isVerified = isSigVerified && isHandleCorrect;
|
||||||
if (!isVerified) {
|
if (!isVerified) {
|
||||||
throw new Error('Tweet is not valid');
|
throw new Error('Tweet is not valid');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { isFourth } = await saveTweet({ transactionSignature: txHash });
|
const { isFourth } = await saveTweet({ transactionSignature: txSignature });
|
||||||
if (isFourth) {
|
if (isFourth) {
|
||||||
createTokenLockForRecipient();
|
createTokenLockForRecipient();
|
||||||
}
|
}
|
||||||
@ -50,12 +51,12 @@ const extractData = (tweet: string | object) => {
|
|||||||
const decodedTweet = tweetText.replace(/'/g, "'").replace(/"/g, '"');
|
const decodedTweet = tweetText.replace(/'/g, "'").replace(/"/g, '"');
|
||||||
|
|
||||||
const urlMatch = decodedTweet.match(/<a href="(https:\/\/t.co\/[^"]+)">/);
|
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_]+)/);
|
const handleMatch = decodedTweet.match(/@([A-Za-z0-9_]+)/);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
memeUrl: urlMatch ? urlMatch[1] : null,
|
memeUrl: urlMatch ? urlMatch[1] : null,
|
||||||
txHash: txHashMatch ? txHashMatch[1].trim() : null,
|
txSignature: txSignatureMatch ? txSignatureMatch[1].trim() : null,
|
||||||
handle: handleMatch ? handleMatch[1] : null,
|
handle: handleMatch ? handleMatch[1] : null,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user