mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-12-06 01:12:34 -05:00
Merge branch 'main' into shreyas-formatting
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { NextRequest } from 'next/server';
|
||||
import { notificationDetailsSchema } from '@farcaster/frame-sdk';
|
||||
import { z } from 'zod';
|
||||
import { setUserNotificationDetails } from '~/lib/kv';
|
||||
import { sendNeynarMiniAppNotification } from '~/lib/neynar';
|
||||
import { sendMiniAppNotification } from '~/lib/notifs';
|
||||
import { notificationDetailsSchema } from "@farcaster/miniapp-sdk";
|
||||
import { NextRequest } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { setUserNotificationDetails } from "~/lib/kv";
|
||||
import { sendMiniAppNotification } from "~/lib/notifs";
|
||||
import { sendNeynarMiniAppNotification } from "~/lib/neynar";
|
||||
|
||||
const requestSchema = z.object({
|
||||
fid: z.number(),
|
||||
@@ -13,8 +13,7 @@ const requestSchema = z.object({
|
||||
export async function POST(request: NextRequest) {
|
||||
// If Neynar is enabled, we don't need to store notification details
|
||||
// as they will be managed by Neynar's system
|
||||
const neynarEnabled =
|
||||
process.env.NEYNAR_API_KEY && process.env.NEYNAR_CLIENT_ID;
|
||||
const neynarEnabled = process.env.NEYNAR_API_KEY && process.env.NEYNAR_CLIENT_ID;
|
||||
|
||||
const requestJson = await request.json();
|
||||
const requestBody = requestSchema.safeParse(requestJson);
|
||||
@@ -22,7 +21,7 @@ export async function POST(request: NextRequest) {
|
||||
if (requestBody.success === false) {
|
||||
return Response.json(
|
||||
{ success: false, errors: requestBody.error.errors },
|
||||
{ status: 400 },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,31 +29,29 @@ export async function POST(request: NextRequest) {
|
||||
if (!neynarEnabled) {
|
||||
await setUserNotificationDetails(
|
||||
Number(requestBody.data.fid),
|
||||
requestBody.data.notificationDetails,
|
||||
requestBody.data.notificationDetails
|
||||
);
|
||||
}
|
||||
|
||||
// Use appropriate notification function based on Neynar status
|
||||
const sendNotification = neynarEnabled
|
||||
? sendNeynarMiniAppNotification
|
||||
: sendMiniAppNotification;
|
||||
const sendNotification = neynarEnabled ? sendNeynarMiniAppNotification : sendMiniAppNotification;
|
||||
const sendResult = await sendNotification({
|
||||
fid: Number(requestBody.data.fid),
|
||||
title: 'Test notification',
|
||||
body: 'Sent at ' + new Date().toISOString(),
|
||||
title: "Test notification",
|
||||
body: "Sent at " + new Date().toISOString(),
|
||||
});
|
||||
|
||||
if (sendResult.state === 'error') {
|
||||
if (sendResult.state === "error") {
|
||||
return Response.json(
|
||||
{ success: false, error: sendResult.error },
|
||||
{ status: 500 },
|
||||
{ status: 500 }
|
||||
);
|
||||
} else if (sendResult.state === 'rate_limit') {
|
||||
} else if (sendResult.state === "rate_limit") {
|
||||
return Response.json(
|
||||
{ success: false, error: 'Rate limited' },
|
||||
{ status: 429 },
|
||||
{ success: false, error: "Rate limited" },
|
||||
{ status: 429 }
|
||||
);
|
||||
}
|
||||
|
||||
return Response.json({ success: true });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user