diff --git a/src/app/api/tweet/route.ts b/src/app/api/tweet/route.ts index dd27fe8..26a0be3 100644 --- a/src/app/api/tweet/route.ts +++ b/src/app/api/tweet/route.ts @@ -1,6 +1,7 @@ import { NextRequest, NextResponse } from 'next/server'; import { processTweet, verifySignatureInTweet } from '../../../utils/verifyTweet'; +import { extractData } from '../../../utils/tweetMessage'; export async function POST(req: NextRequest): Promise { try { @@ -41,19 +42,3 @@ export async function POST(req: NextRequest): Promise { ) } } - -const extractData = (tweet: string | object) => { - const tweetText = typeof tweet === 'string' ? tweet : JSON.stringify(tweet); - - const decodedTweet = tweetText.replace(/'/g, "'").replace(/"/g, '"'); - - const urlMatch = decodedTweet.match(//); - const txSignatureMatch = decodedTweet.match(/TX Hash: '([^']+)'/); - const handleMatch = decodedTweet.match(/@([A-Za-z0-9_]+)/); - - return { - memeUrl: urlMatch ? urlMatch[1] : null, - txSignature: txSignatureMatch ? txSignatureMatch[1].trim() : null, - handle: handleMatch ? handleMatch[1] : null, - }; -}; diff --git a/src/components/AIServiceCard.tsx b/src/components/AIServiceCard.tsx index 73638cc..52d94dd 100644 --- a/src/components/AIServiceCard.tsx +++ b/src/components/AIServiceCard.tsx @@ -5,6 +5,8 @@ import BN from 'bn.js'; import Big from 'big.js'; import dynamic from 'next/dynamic' +import { generateTweetText } from '../utils/tweetMessage'; + interface AIServiceCardProps { title: string description: string @@ -95,7 +97,7 @@ const AIServiceCard: React.FC = ({ const cid = imageUrl.split("/image/")[1]; const memePageUrl = `${baseUrl}memes/${cid}`; - const tweetText = `Check out this meme that I generated! \n TX Hash: '${transactionSignature}' \n @${process.env.NEXT_PUBLIC_TWITTER_HANDLE} \n`; + const tweetText = generateTweetText(transactionSignature, process.env.NEXT_PUBLIC_TWITTER_HANDLE) return `https://twitter.com/intent/tweet?text=${encodeURIComponent(tweetText)}&url=${encodeURIComponent(memePageUrl)}`; }; diff --git a/src/utils/tweetMessage.ts b/src/utils/tweetMessage.ts new file mode 100644 index 0000000..77eb453 --- /dev/null +++ b/src/utils/tweetMessage.ts @@ -0,0 +1,19 @@ +export const generateTweetText = (transactionSignature: string, handle: string | undefined) => { + return `Check out this meme that I generated! \n TX Hash: '${transactionSignature}' \n @${handle} \n`; +}; + +export const extractData = (tweet: string | object) => { + const tweetText = typeof tweet === 'string' ? tweet : JSON.stringify(tweet); + + const decodedTweet = tweetText.replace(/'/g, "'").replace(/"/g, '"'); + + const urlMatch = decodedTweet.match(//); + const txSignatureMatch = decodedTweet.match(/TX Hash: '([^']+)'/); + const handleMatch = decodedTweet.match(/@([A-Za-z0-9_]+)/); + + return { + memeUrl: urlMatch ? urlMatch[1] : null, + txSignature: txSignatureMatch ? txSignatureMatch[1].trim() : null, + handle: handleMatch ? handleMatch[1] : null, + }; +};