diff options
Diffstat (limited to 'frontend/app/api/rename/route.ts')
| -rw-r--r-- | frontend/app/api/rename/route.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/frontend/app/api/rename/route.ts b/frontend/app/api/rename/route.ts new file mode 100644 index 0000000..1e2abb4 --- /dev/null +++ b/frontend/app/api/rename/route.ts | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | import { NextRequest, NextResponse } from 'next/server' | ||
| 2 | import { Auth_get_user } from '@/lib/auth' | ||
| 3 | import { Drive_rename } from '@/lib/drive_server' | ||
| 4 | |||
| 5 | // POST /api/rename - Rename a file or directory | ||
| 6 | export async function POST(request: NextRequest) { | ||
| 7 | try { | ||
| 8 | // Check user authentication | ||
| 9 | const user = await Auth_get_user() | ||
| 10 | if (!user.isLoggedIn) { | ||
| 11 | return NextResponse.json({ error: 'User not authenticated' }, { status: 401 }) | ||
| 12 | } | ||
| 13 | |||
| 14 | // Parse request body to get old and new paths | ||
| 15 | const body = await request.json() | ||
| 16 | const { oldPath, newPath } = body | ||
| 17 | |||
| 18 | if (!oldPath || typeof oldPath !== 'string' || oldPath.trim() === '') { | ||
| 19 | return NextResponse.json({ error: 'Invalid old path provided' }, { status: 400 }) | ||
| 20 | } | ||
| 21 | |||
| 22 | if (!newPath || typeof newPath !== 'string' || newPath.trim() === '') { | ||
| 23 | return NextResponse.json({ error: 'Invalid new path provided' }, { status: 400 }) | ||
| 24 | } | ||
| 25 | |||
| 26 | // Rename using Drive_rename | ||
| 27 | try { | ||
| 28 | await Drive_rename(oldPath.trim(), newPath.trim(), user.email) | ||
| 29 | |||
| 30 | return NextResponse.json({ | ||
| 31 | success: true, | ||
| 32 | message: `Successfully renamed "${oldPath}" to "${newPath}"` | ||
| 33 | }) | ||
| 34 | |||
| 35 | } catch (error) { | ||
| 36 | console.error(`Failed to rename ${oldPath} to ${newPath}:`, error) | ||
| 37 | return NextResponse.json( | ||
| 38 | { | ||
| 39 | error: error instanceof Error ? error.message : 'Failed to rename item' | ||
| 40 | }, | ||
| 41 | { status: 500 } | ||
| 42 | ) | ||
| 43 | } | ||
| 44 | |||
| 45 | } catch (error) { | ||
| 46 | console.error('Rename API error:', error) | ||
| 47 | return NextResponse.json( | ||
| 48 | { error: error instanceof Error ? error.message : 'Internal server error' }, | ||
| 49 | { status: 500 } | ||
| 50 | ) | ||
| 51 | } | ||
| 52 | } \ No newline at end of file | ||
