blob: 18e1bbca936cd8a803300a1fc6186de98fdcbeef (
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
53
54
|
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 }
)
}
}
|