forked from mito-systems/sol-mem-gen
Verify payment on chain before generating meme (#3)
Part of https://www.notion.so/Implement-payment-gating-188a6b22d472806a9267c2bda72925cc Co-authored-by: Adw8 <adwaitgharpure@gmail.com> Reviewed-on: #3 Co-authored-by: adwait <adwait@noreply.git.vdb.to> Co-committed-by: adwait <adwait@noreply.git.vdb.to>
This commit was merged in pull request #3.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { fal } from "@fal-ai/client"
|
||||
import { FLUX_MODELS } from '../../../services/fluxService'
|
||||
|
||||
import { verifyPayment } from '../../../utils/verifyPayment'
|
||||
|
||||
if (!process.env.FAL_AI_KEY) {
|
||||
throw new Error('FAL_AI_KEY is not configured in environment variables')
|
||||
@@ -16,7 +19,7 @@ const IMAGE_HEIGHT: number = 1024
|
||||
|
||||
export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
try {
|
||||
const { prompt, modelId } = await req.json()
|
||||
const { prompt, modelId, transactionSignature } = await req.json()
|
||||
|
||||
if (!prompt || !modelId) {
|
||||
return NextResponse.json(
|
||||
@@ -25,6 +28,28 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
)
|
||||
}
|
||||
|
||||
if (!transactionSignature) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Transaction signature is required' },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
const model = FLUX_MODELS.find((model) => model.modelId === modelId)
|
||||
if (!model) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Invalid modelId' },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
const expectedAmount = model.cost;
|
||||
const isPaymentVerified = await verifyPayment(transactionSignature, expectedAmount)
|
||||
|
||||
if (!isPaymentVerified) {
|
||||
throw new Error('Payment verification failed');
|
||||
}
|
||||
|
||||
console.log('Generating with Flux model:', modelId)
|
||||
console.log('Prompt:', prompt)
|
||||
|
||||
|
||||
+3
-1
@@ -49,8 +49,10 @@ const Page: React.FC = (): React.ReactElement => {
|
||||
return { error: paymentResult.error }
|
||||
}
|
||||
|
||||
const transactionSignature = paymentResult.transactionSignature;
|
||||
|
||||
// Then generate image with specified model
|
||||
return generateWithFlux(prompt, modelId)
|
||||
return generateWithFlux(prompt, modelId, transactionSignature)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user