檔案上傳新增至資料庫
This commit is contained in:
@@ -135,25 +135,56 @@ export default function UploadPage() {
|
||||
setIsAnalyzing(true)
|
||||
|
||||
try {
|
||||
console.log('🚀 開始 AI 評審流程...')
|
||||
console.log('🚀 開始上傳和評審流程...')
|
||||
console.log('📝 專案標題:', projectTitle)
|
||||
console.log('📋 專案描述:', projectDescription)
|
||||
console.log('📁 上傳文件數量:', files.length)
|
||||
console.log('🌐 網站連結:', websiteUrl)
|
||||
|
||||
// 準備表單數據
|
||||
let projectId = null;
|
||||
|
||||
// 如果有文件,先上傳到資料庫
|
||||
if (files.length > 0) {
|
||||
console.log('📤 上傳文件到資料庫...')
|
||||
const firstFile = files[0]
|
||||
if (firstFile.file) {
|
||||
const uploadFormData = new FormData()
|
||||
uploadFormData.append('projectTitle', projectTitle)
|
||||
uploadFormData.append('projectDescription', projectDescription)
|
||||
uploadFormData.append('file', firstFile.file)
|
||||
|
||||
const uploadResponse = await fetch('/api/upload', {
|
||||
method: 'POST',
|
||||
body: uploadFormData,
|
||||
})
|
||||
|
||||
const uploadResult = await uploadResponse.json()
|
||||
|
||||
if (uploadResult.success) {
|
||||
projectId = uploadResult.data.projectId
|
||||
console.log('✅ 文件上傳成功,專案 ID:', projectId)
|
||||
toast({
|
||||
title: "文件上傳成功",
|
||||
description: `專案已創建,ID: ${projectId}`,
|
||||
})
|
||||
} else {
|
||||
throw new Error(uploadResult.error || '文件上傳失敗')
|
||||
}
|
||||
} else {
|
||||
throw new Error('文件對象遺失,請重新上傳')
|
||||
}
|
||||
}
|
||||
|
||||
// 準備 AI 評審數據
|
||||
const formData = new FormData()
|
||||
formData.append('projectTitle', projectTitle)
|
||||
formData.append('projectDescription', projectDescription)
|
||||
|
||||
if (files.length > 0) {
|
||||
// 只處理第一個文件(可以後續擴展支援多文件)
|
||||
const firstFile = files[0]
|
||||
if (firstFile.file) {
|
||||
formData.append('file', firstFile.file)
|
||||
console.log('📄 處理文件:', firstFile.name, '大小:', firstFile.size)
|
||||
} else {
|
||||
throw new Error('文件對象遺失,請重新上傳')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,8 +193,8 @@ export default function UploadPage() {
|
||||
console.log('🌐 處理網站連結:', websiteUrl)
|
||||
}
|
||||
|
||||
// 發送評審請求
|
||||
console.log('📤 發送評審請求到 API...')
|
||||
// 發送 AI 評審請求
|
||||
console.log('🤖 開始 AI 評審...')
|
||||
const response = await fetch('/api/evaluate', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
@@ -195,9 +226,9 @@ export default function UploadPage() {
|
||||
throw new Error(result.error || '評審失敗')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ AI 評審失敗:', error)
|
||||
console.error('❌ 上傳或評審失敗:', error)
|
||||
toast({
|
||||
title: "評審失敗",
|
||||
title: "操作失敗",
|
||||
description: error instanceof Error ? error.message : "請稍後再試",
|
||||
variant: "destructive",
|
||||
})
|
||||
|
Reference in New Issue
Block a user