diff options
| author | diogo464 <[email protected]> | 2025-08-11 16:28:59 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-08-11 16:28:59 +0100 |
| commit | 2e02765e4b79d0d145520f9005c75d382805dc2e (patch) | |
| tree | 08e0279988c804ad9e4e9301a2e23648decf292d /frontend/app/api/delete | |
| parent | 68afafc281103c32b193d5f116d87f74187bdc63 (diff) | |
implement RESTful API and remove legacy endpoints
- Created unified /api/fs/[...path] endpoint with full REST methods:
- GET: List directory contents or file info
- POST: Create directories using Drive_mkdir()
- PUT: Upload files with multipart form data
- DELETE: Remove files/directories using Drive_remove()
- Added /api/fs route for root directory listing
- Added Drive_mkdir() function to drive_server.ts using fctdrive mkdir command
- Removed legacy /api/delete and /api/upload endpoints
- Updated CLAUDE.md with comprehensive API documentation and examples
- All endpoints support authentication with AUTH: 1 header in development
- Proper error handling, file size validation, and cache revalidation
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
Diffstat (limited to 'frontend/app/api/delete')
| -rw-r--r-- | frontend/app/api/delete/route.ts | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/frontend/app/api/delete/route.ts b/frontend/app/api/delete/route.ts deleted file mode 100644 index b4a27d4..0000000 --- a/frontend/app/api/delete/route.ts +++ /dev/null | |||
| @@ -1,48 +0,0 @@ | |||
| 1 | import { NextRequest, NextResponse } from 'next/server' | ||
| 2 | import { Auth_get_user, Auth_user_can_upload } from '@/lib/auth' | ||
| 3 | import { Drive_remove } from '@/lib/drive_server' | ||
| 4 | import { revalidatePath } from 'next/cache' | ||
| 5 | |||
| 6 | export async function POST(request: NextRequest) { | ||
| 7 | try { | ||
| 8 | // Check user authentication and permissions | ||
| 9 | const user = await Auth_get_user() | ||
| 10 | if (!user.isLoggedIn) { | ||
| 11 | return NextResponse.json({ error: 'User not authenticated' }, { status: 401 }) | ||
| 12 | } | ||
| 13 | |||
| 14 | if (!Auth_user_can_upload(user)) { | ||
| 15 | return NextResponse.json({ error: 'User does not have upload permissions' }, { status: 403 }) | ||
| 16 | } | ||
| 17 | |||
| 18 | // Parse JSON body | ||
| 19 | const body = await request.json() | ||
| 20 | const path = body.path | ||
| 21 | |||
| 22 | // Validate path | ||
| 23 | if (!path || typeof path !== 'string') { | ||
| 24 | return NextResponse.json({ error: 'Path is required and must be a string' }, { status: 400 }) | ||
| 25 | } | ||
| 26 | |||
| 27 | // Remove file/directory using Drive_remove | ||
| 28 | await Drive_remove(path, user.email) | ||
| 29 | |||
| 30 | // Revalidate the parent directory to refresh listings | ||
| 31 | const parentPath = path.split('/').slice(0, -1).join('/') || '/' | ||
| 32 | revalidatePath(`/drive${parentPath}`) | ||
| 33 | revalidatePath('/drive') | ||
| 34 | |||
| 35 | return NextResponse.json({ | ||
| 36 | success: true, | ||
| 37 | message: 'Path deleted successfully', | ||
| 38 | deletedPath: path | ||
| 39 | }) | ||
| 40 | |||
| 41 | } catch (error) { | ||
| 42 | console.error('Delete error:', error) | ||
| 43 | return NextResponse.json( | ||
| 44 | { error: error instanceof Error ? error.message : 'Internal server error' }, | ||
| 45 | { status: 500 } | ||
| 46 | ) | ||
| 47 | } | ||
| 48 | } \ No newline at end of file | ||
