@@ -9,7 +9,7 @@ export const dynamic = "force-dynamic";
99 * AI README Generation Endpoint
1010 * Optimized for data accuracy, clean prompt interpolation, and multi-language support.
1111 *
12- * @param {Request } req - The incoming request object containing the repo URL and optional language.
12+ * @param {Request } req - The incoming Fastify request object containing the repo URL and optional language.
1313 * @returns {Promise<NextResponse> } A JSON response containing the generated Markdown or an error message.
1414 */
1515export async function POST ( req : Request ) {
@@ -18,13 +18,7 @@ export async function POST(req: Request) {
1818 try {
1919 const body = await req . json ( ) ;
2020 rawUrl = body . url ;
21- const rawLanguage =
22- typeof body . language === "string" ? body . language . trim ( ) : "" ;
23- const normalized =
24- rawLanguage . charAt ( 0 ) . toUpperCase ( ) + rawLanguage . slice ( 1 ) . toLowerCase ( ) ;
25- language = ( SUPPORTED_LANGUAGES as readonly string [ ] ) . includes ( normalized )
26- ? normalized
27- : "English" ;
21+ language = body . language || "English" ;
2822 } catch {
2923 return NextResponse . json ( { error : "Invalid JSON body" } , { status : 400 } ) ;
3024 }
@@ -157,9 +151,12 @@ export async function POST(req: Request) {
157151
158152 const result = await model . generateContent ( prompt ) ;
159153 const response = await result . response ;
160- const markdown = response . text ( ) ;
154+ const markdown = response . text ( ) . trim ( ) ;
155+ const cleanMarkdown = markdown
156+ . replace ( / ^ ` ` ` ( m a r k d o w n | m d ) ? \n / , "" )
157+ . replace ( / \n ` ` ` $ / , "" ) ;
161158
162- return NextResponse . json ( { markdown } ) ;
159+ return NextResponse . json ( { markdown : cleanMarkdown } ) ;
163160 } catch ( error : unknown ) {
164161 const message =
165162 error instanceof Error ? error . message : "Internal Server Error" ;
0 commit comments