File tree Expand file tree Collapse file tree
app/api/tools/file/manage Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,23 +43,33 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
4343 switch ( body . operation ) {
4444 case 'get' : {
4545 const { fileId, fileInput } = body
46-
47- if ( fileInput && typeof fileInput === 'object' && ! Array . isArray ( fileInput ) ) {
48- return NextResponse . json ( { success : true , data : { file : fileInput } } )
49- }
50-
51- if ( ! fileId ) {
46+ const selectedFileId =
47+ fileId ||
48+ ( fileInput && typeof fileInput === 'object' && ! Array . isArray ( fileInput )
49+ ? typeof fileInput . id === 'string'
50+ ? fileInput . id
51+ : typeof fileInput . fileId === 'string'
52+ ? fileInput . fileId
53+ : ''
54+ : '' )
55+
56+ if ( ! selectedFileId ) {
5257 return NextResponse . json ( { success : false , error : 'File is required' } , { status : 400 } )
5358 }
5459
55- const file = await getWorkspaceFile ( workspaceId , fileId )
60+ const file = await getWorkspaceFile ( workspaceId , selectedFileId )
5661 if ( ! file ) {
5762 return NextResponse . json (
58- { success : false , error : `File not found: "${ fileId } "` } ,
63+ { success : false , error : `File not found: "${ selectedFileId } "` } ,
5964 { status : 404 }
6065 )
6166 }
6267
68+ logger . info ( 'File retrieved' , {
69+ fileId : file . id ,
70+ name : file . name ,
71+ } )
72+
6373 return NextResponse . json ( {
6474 success : true ,
6575 data : {
Original file line number Diff line number Diff line change @@ -22,14 +22,18 @@ export const fileManageAppendBodySchema = z.object({
2222 content : z . string ( { error : 'content is required for append operation' } ) ,
2323} )
2424
25- export const fileManageGetBodySchema = z . object ( {
26- operation : z . literal ( 'get' ) ,
27- workspaceId : z . string ( ) . min ( 1 ) . optional ( ) ,
28- fileId : z . string ( ) . min ( 1 ) . optional ( ) ,
29- fileInput : z . any ( ) . optional ( ) ,
30- } )
25+ export const fileManageGetBodySchema = z
26+ . object ( {
27+ operation : z . literal ( 'get' ) ,
28+ workspaceId : z . string ( ) . min ( 1 ) . optional ( ) ,
29+ fileId : z . string ( ) . min ( 1 ) . optional ( ) ,
30+ fileInput : z . any ( ) . optional ( ) ,
31+ } )
32+ . refine ( ( data ) => data . fileId !== undefined || data . fileInput !== undefined , {
33+ message : 'Either fileId or fileInput is required for get operation' ,
34+ } )
3135
32- export const fileManageBodySchema = z . discriminatedUnion ( 'operation' , [
36+ export const fileManageBodySchema = z . union ( [
3337 fileManageWriteBodySchema ,
3438 fileManageAppendBodySchema ,
3539 fileManageGetBodySchema ,
You can’t perform that action at this time.
0 commit comments