summaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-08-12 16:46:31 +0100
committerdiogo464 <[email protected]>2025-08-12 16:46:31 +0100
commit5c48d5cc58ce5d296d770c0e16cca13204b8200f (patch)
treea1024f90f39140012a0c5b1582bef788fbb6bb54 /frontend
parent4902a199b93fbdd9b265f9741c70e00eaf368939 (diff)
Fix URL encoding for paths with special characters
- Add URL decoding in upload endpoint for path parameter - Add URL decoding for path segments in drive page navigation - Ensures proper handling of directories/files with spaces and unicode chars 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Diffstat (limited to 'frontend')
-rw-r--r--frontend/app/api/upload/route.ts15
-rw-r--r--frontend/app/drive/[...path]/page.tsx4
2 files changed, 12 insertions, 7 deletions
diff --git a/frontend/app/api/upload/route.ts b/frontend/app/api/upload/route.ts
index 518c28e..07ab908 100644
--- a/frontend/app/api/upload/route.ts
+++ b/frontend/app/api/upload/route.ts
@@ -22,19 +22,21 @@ export async function POST(request: NextRequest) {
22 22
23 // Get the target path from query parameters 23 // Get the target path from query parameters
24 const url = new URL(request.url) 24 const url = new URL(request.url)
25 const targetPath = url.searchParams.get('path') || '/' 25 const rawPath = url.searchParams.get('path') || '/'
26 const targetPath = decodeURIComponent(rawPath)
27 console.log(`targetPath = ${targetPath}`)
26 28
27 // Handle multipart form data 29 // Handle multipart form data
28 const formData = await request.formData() 30 const formData = await request.formData()
29 const file = formData.get('file') as File 31 const file = formData.get('file') as File
30 32
31 if (!file) { 33 if (!file) {
32 return NextResponse.json({ error: 'No file provided' }, { status: 400 }) 34 return NextResponse.json({ error: 'No file provided' }, { status: 400 })
33 } 35 }
34 36
35 if (file.size > UPLOAD_MAX_FILE_SIZE) { 37 if (file.size > UPLOAD_MAX_FILE_SIZE) {
36 return NextResponse.json({ 38 return NextResponse.json({
37 error: `File exceeds maximum size of ${UPLOAD_MAX_FILE_SIZE / (1024 * 1024)}MB` 39 error: `File exceeds maximum size of ${UPLOAD_MAX_FILE_SIZE / (1024 * 1024)}MB`
38 }, { status: 400 }) 40 }, { status: 400 })
39 } 41 }
40 42
@@ -49,7 +51,8 @@ export async function POST(request: NextRequest) {
49 await writeFile(tempFilePath, fileBuffer) 51 await writeFile(tempFilePath, fileBuffer)
50 52
51 // Construct the final drive path 53 // Construct the final drive path
52 const finalPath = targetPath === '/' ? file.name : `${targetPath.replace(/^\/+|\/+$/g, '')}/${file.name}` 54 const finalPath = `${targetPath}/${file.name}`
55 console.log(`finalPath = ${finalPath}`)
53 56
54 // Import file using Drive_import (uses --mode move, so temp file is automatically deleted) 57 // Import file using Drive_import (uses --mode move, so temp file is automatically deleted)
55 await Drive_import(tempFilePath, finalPath, user.email) 58 await Drive_import(tempFilePath, finalPath, user.email)
@@ -68,4 +71,4 @@ export async function POST(request: NextRequest) {
68 { status: 500 } 71 { status: 500 }
69 ) 72 )
70 } 73 }
71} \ No newline at end of file 74}
diff --git a/frontend/app/drive/[...path]/page.tsx b/frontend/app/drive/[...path]/page.tsx
index b0c6d7d..8380a30 100644
--- a/frontend/app/drive/[...path]/page.tsx
+++ b/frontend/app/drive/[...path]/page.tsx
@@ -7,7 +7,9 @@ export default async function DriveDirectoryPage({
7 params: Promise<{ path: string[] }> 7 params: Promise<{ path: string[] }>
8}) { 8}) {
9 const { path: pathSegments } = await params 9 const { path: pathSegments } = await params
10 const currentPath = '/' + (pathSegments?.join('/') || '') 10 // URL decode each path segment to handle special characters
11 const decodedSegments = pathSegments?.map(segment => decodeURIComponent(segment)) || []
12 const currentPath = '/' + decodedSegments.join('/')
11 13
12 const files = await Drive_ls(currentPath, false) 14 const files = await Drive_ls(currentPath, false)
13 return <DriveDirectoryView path={currentPath} files={files} /> 15 return <DriveDirectoryView path={currentPath} files={files} />