@@ -3,6 +3,10 @@ import { NextResponse } from 'next/server';
33import { createSupabaseServerClient } from '@/lib/supabase.js' ;
44import { postQuantumEncryption } from '@/lib/crypto/post-quantum-encryption.js' ;
55
6+ async function resolveRouteParams ( params ) {
7+ return ( await params ) || { } ;
8+ }
9+
610export async function GET ( request , { params } = { } ) {
711 try {
812 // Create Supabase server client
@@ -14,7 +18,7 @@ export async function GET(request, { params } = {}) {
1418 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } ) ;
1519 }
1620
17- const fileId = params . fileId ;
21+ const { fileId } = await resolveRouteParams ( params ) ;
1822 console . log ( `📁 [FILE-DOWNLOAD] Download request from auth user: ${ user . id } for file: ${ fileId } ` ) ;
1923
2024 // Get the internal user ID from the users table using auth_user_id
@@ -117,7 +121,7 @@ export async function GET(request, { params } = {}) {
117121 const metadataObj = JSON . parse ( decryptedMetadata ) ;
118122 mimeType = metadataObj . mimeType || 'application/octet-stream' ;
119123 }
120- } catch ( metaError ) {
124+ } catch {
121125 console . warn ( '📁 [FILE-DOWNLOAD] Could not decrypt metadata for mimeType' ) ;
122126 }
123127
@@ -146,7 +150,7 @@ export async function GET(request, { params } = {}) {
146150}
147151
148152// Get file info without downloading the actual file content
149- export async function HEAD ( event ) {
153+ export async function HEAD ( request , { params } = { } ) {
150154 try {
151155 // Create Supabase server client
152156 const supabase = await createSupabaseServerClient ( ) ;
@@ -158,7 +162,7 @@ export async function HEAD(event) {
158162 }
159163
160164 const userId = user . id ;
161- const fileId = params . fileId ;
165+ const { fileId } = await resolveRouteParams ( params ) ;
162166
163167 // Get file metadata from database
164168 const { data : fileData , error : fileError } = await supabase
@@ -212,7 +216,7 @@ export async function POST(request, { params } = {}) {
212216 }
213217
214218 const userId = user . id ;
215- const fileId = params . fileId ;
219+ const { fileId } = await resolveRouteParams ( params ) ;
216220
217221 console . log ( `📁 [FILE-INFO] Info request from user: ${ userId } for file: ${ fileId } ` ) ;
218222
@@ -259,10 +263,3 @@ export async function POST(request, { params } = {}) {
259263 }
260264}
261265
262- function formatFileSize ( bytes ) {
263- if ( bytes === 0 ) return '0 Bytes' ;
264- const k = 1024 ;
265- const sizes = [ 'Bytes' , 'KB' , 'MB' , 'GB' ] ;
266- const i = Math . floor ( Math . log ( bytes ) / Math . log ( k ) ) ;
267- return parseFloat ( ( bytes / Math . pow ( k , i ) ) . toFixed ( 2 ) ) + ' ' + sizes [ i ] ;
268- }
0 commit comments