import { NextRequest, NextResponse } from 'next/server' import { Auth_get_user } from '@/lib/auth' import { Drive_rename } from '@/lib/drive_server' // POST /api/rename - Rename a file or 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 old and new paths const body = await request.json() const { oldPath, newPath } = body if (!oldPath || typeof oldPath !== 'string' || oldPath.trim() === '') { return NextResponse.json({ error: 'Invalid old path provided' }, { status: 400 }) } if (!newPath || typeof newPath !== 'string' || newPath.trim() === '') { return NextResponse.json({ error: 'Invalid new path provided' }, { status: 400 }) } // Rename using Drive_rename try { await Drive_rename(oldPath.trim(), newPath.trim(), user.email) return NextResponse.json({ success: true, message: `Successfully renamed "${oldPath}" to "${newPath}"` }) } catch (error) { console.error(`Failed to rename ${oldPath} to ${newPath}:`, error) return NextResponse.json( { error: error instanceof Error ? error.message : 'Failed to rename item' }, { status: 500 } ) } } catch (error) { console.error('Rename API error:', error) return NextResponse.json( { error: error instanceof Error ? error.message : 'Internal server error' }, { status: 500 } ) } }