import { NextRequest, NextResponse } from 'next/server' import { Auth_get_user } from '@/lib/auth' import { Drive_mkdir } from '@/lib/drive_server' // POST /api/mkdir - Create directory export async function POST(request: NextRequest) { try { // Check user authentication const user = await Auth_get_user() if (!user.isLoggedIn) { return NextResponse.json({ error: 'User not authenticated' }, { status: 401 }) } // Parse request body to get directory info const body = await request.json() const { path, name } = body if (!path || typeof path !== 'string') { return NextResponse.json({ error: 'Path is required' }, { status: 400 }) } if (!name || typeof name !== 'string' || name.trim() === '') { return NextResponse.json({ error: 'Directory name is required' }, { status: 400 }) } // Construct full directory path const dirName = name.trim() const fullPath = path === '/' ? `/${dirName}` : `${path}/${dirName}` // Create directory using Drive_mkdir try { await Drive_mkdir(fullPath, user.email) return NextResponse.json({ success: true, message: `Directory "${dirName}" created successfully`, path: fullPath }) } catch (error) { console.error(`Failed to create directory ${fullPath}:`, error) return NextResponse.json({ error: error instanceof Error ? error.message : 'Failed to create directory' }, { status: 500 }) } } catch (error) { console.error('Mkdir API error:', error) return NextResponse.json( { error: error instanceof Error ? error.message : 'Internal server error' }, { status: 500 } ) } }