11export const dynamic = 'force-dynamic' // defaults to auto
2- import { NextRequest } from 'next/server'
2+ import { NextRequest , NextResponse } from 'next/server'
33import { type Block , Text } from '@gptscript-ai/gptscript'
44import { promises as fs } from 'fs' ;
55import path from 'path' ;
@@ -17,26 +17,12 @@ export async function DELETE(
1717 try {
1818 const { name } = params as any ;
1919 await fs . unlink ( path . join ( `${ SCRIPTS_PATH ( ) } /${ name } .gpt` ) ) ;
20- return Response . json ( { success : true } ) ;
20+ return NextResponse . json ( { success : true } ) ;
2121 } catch ( e ) {
22- return Response . json ( { error : e } , { status : 500 } ) ;
22+ return NextResponse . json ( { error : e } , { status : 500 } ) ;
2323 }
2424}
2525
26- // export async function PUT(req: Request) {
27- // try {
28- // const scriptsPath = process.env.SCRIPTS_PATH() || 'gptscripts';
29- // const { name } = req.params as any;
30- // const content = await req.text();
31-
32- // await fs.rename(`${scriptsPath}/${name}`, `${scriptsPath}/${name}.bak`);
33- // await fs.writeFile(`${scriptsPath}/${name}`, content);
34- // return Response.json({ success: true });
35- // } catch (e) {
36- // return Response.json({ error: e }, { status: 500 });
37- // }
38- // }
39-
4026export async function GET (
4127 req : NextRequest ,
4228 { params } : { params : { slug : string } }
@@ -46,14 +32,14 @@ export async function GET(
4632 const script = await gpt ( ) . parse ( path . join ( SCRIPTS_PATH ( ) , `${ name } .gpt` ) ) ;
4733 if ( req . nextUrl . searchParams . get ( 'nodeify' ) === 'true' ) {
4834 const { nodes, edges } = await nodeify ( script ) ;
49- return Response . json ( { nodes : nodes , edges : edges } ) ;
35+ return NextResponse . json ( { nodes : nodes , edges : edges } ) ;
5036 }
51- return Response . json ( script ) ;
37+ return NextResponse . json ( script ) ;
5238 } catch ( e ) {
5339 if ( `${ e } ` . includes ( 'no such file' ) ) {
54- return Response . json ( { error : '.gpt file not found' } , { status : 404 } ) ;
40+ return NextResponse . json ( { error : '.gpt file not found' } , { status : 404 } ) ;
5541 }
56- return Response . json ( { error : e } , { status : 500 } ) ;
42+ return NextResponse . json ( { error : e } , { status : 500 } ) ;
5743 }
5844}
5945
@@ -67,12 +53,12 @@ export async function PUT(
6753 const script = denodeify ( nodes ) ;
6854
6955 await fs . writeFile ( path . join ( SCRIPTS_PATH ( ) , `${ name } .gpt` ) , await gpt ( ) . stringify ( script ) ) ;
70- return Response . json ( await gpt ( ) . parse ( path . join ( SCRIPTS_PATH ( ) , `${ name } .gpt` ) ) ) ;
56+ return NextResponse . json ( await gpt ( ) . parse ( path . join ( SCRIPTS_PATH ( ) , `${ name } .gpt` ) ) ) ;
7157 } catch ( e ) {
7258 if ( `${ e } ` . includes ( 'no such file' ) ) {
73- return Response . json ( { error : '.gpt file not found' } , { status : 404 } ) ;
59+ return NextResponse . json ( { error : '.gpt file not found' } , { status : 404 } ) ;
7460 }
75- return Response . json ( { error : e } , { status : 500 } ) ;
61+ return NextResponse . json ( { error : e } , { status : 500 } ) ;
7662 }
7763}
7864
0 commit comments