Download src/app/api/gmail/draft/route.ts from luguog/over: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/spaces/luguog/over/resolve/main/src/app/api/gmail/draft/route.ts
- Command line
-
hf download hf://spaces/luguog/over/src/app/api/gmail/draft/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/luguog/over/resolve/main/src/app/api/gmail/draft/route.ts
1.35 kB
| import { NextRequest, NextResponse } from "next/server"; | |
| import { createDraftREST } from "@/lib/gmail/rest-client"; | |
| import { normalizeOrigin, getRequestOrigin } from "@/lib/utils"; | |
| export const dynamic = "force-dynamic"; | |
| export const maxDuration = 30; | |
| export async function POST(request: NextRequest) { | |
| try { | |
| const body = await request.json().catch(() => ({})); | |
| const clientId = process.env.GMAIL_CLIENT_ID || ""; | |
| const clientSecret = process.env.GMAIL_CLIENT_SECRET || ""; | |
| const refreshToken = body.refreshToken || request.cookies.get("gmail-refresh-token")?.value || ""; | |
| if (!clientId || !refreshToken) { | |
| return NextResponse.json({ error: "Gmail not connected" }, { status: 401 }); | |
| } | |
| if (!body.to || !body.subject || !body.body) { | |
| return NextResponse.json({ error: "to, subject, and body are required" }, { status: 400 }); | |
| } | |
| const redirectUri = `${normalizeOrigin(getRequestOrigin(request))}/api/gmail/callback`; | |
| const result = await createDraftREST( | |
| { clientId, clientSecret, redirectUri, refreshToken, emailAddress: "" }, | |
| { to: body.to, cc: body.cc, subject: body.subject, body: body.body, isHtml: body.isHtml } | |
| ); | |
| return NextResponse.json({ success: true, ...result }); | |
| } catch (e: any) { | |
| return NextResponse.json({ error: e.message }, { status: 500 }); | |
| } | |
| } | |