An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix: Adjusting the file path structure
oussamadhouib5e044989417f
diff --git a/app/api/upload/route.ts b/app/api/upload/route.tsindex 543ddbe7..2f7c82e4 100644--- a/app/api/upload/route.ts+++ b/app/api/upload/route.ts@@ -21,7 +21,7 @@ export async function POST(req: NextRequest) {const formData = await req.formData()const file = formData.get('file') as File-+ const chatId = formData.get('chatId') as stringif (!file) {return NextResponse.json({ error: 'File is required' }, { status: 400 })}@@ -39,7 +39,7 @@ export async function POST(req: NextRequest) {{ status: 400 })}- const result = await uploadFileToSupabase(file)+ const result = await uploadFileToSupabase(file, userId, chatId)return NextResponse.json({ success: true, file: result }, { status: 200 })} catch (err: any) {console.error('Upload Error:', err)@@ -54,9 +54,13 @@ function sanitizeFilename(filename: string) {return filename.replace(/[^a-z0-9.\-_]/gi, '_').toLowerCase()}-async function uploadFileToSupabase(file: File) {+async function uploadFileToSupabase(+ file: File,+ userId: string,+ chatId: string+) {const sanitizedFileName = sanitizeFilename(file.name)- const filePath = `${Date.now()}-${sanitizedFileName}`+ const filePath = `${userId}/chats/${chatId}/${Date.now()}-${sanitizedFileName}`const supabase = await createClient()const { error } = await supabase.storage.from('user-uploads')diff --git a/components/chat.tsx b/components/chat.tsxindex 89218cfe..3bbebc87 100644--- a/components/chat.tsx+++ b/components/chat.tsx@@ -284,6 +284,7 @@ export function Chat({uploadedFiles.map(async file => {const formData = new FormData()formData.append('file', file)+ formData.append('chatId', id)const res = await fetch('/api/upload', {method: 'POST',body: formData