blob: 1e2abb44867b38fd1a00097b8f9c0e613bff6bde (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
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 }
)
}
}
|