feat: Day 21-22 - knowledge base frontend completed, fix CORS and file upload issues

- Complete knowledge base list and detail pages
- Complete document upload component
- Fix CORS config (add PUT/DELETE method support)
- Fix file upload issues (disabled state and beforeUpload return value)
- Add detailed debug logs (cleaned up)
- Create Day 21-22 completion summary document
This commit is contained in:
AI Clinical Dev Team
2025-10-11 15:40:12 +08:00
parent 1613e4e517
commit 239c7ea85e
87 changed files with 383 additions and 6 deletions

34
backend/fix-cors.ps1 Normal file
View File

@@ -0,0 +1,34 @@
# 修复CORS配置脚本
Write-Host "🔧 正在修复CORS配置..." -ForegroundColor Green
$filePath = "src\index.ts"
$content = Get-Content $filePath -Raw
# 在CORS配置后添加日志
$content = $content -replace "(await fastify\.register\(cors, \{[^}]+\}\);)", "`$1`nconsole.log('✅ CORS已配置: 允许所有HTTP方法 (GET, POST, PUT, DELETE, PATCH, OPTIONS)');"
# 在multipart配置后添加日志
$content = $content -replace "(await fastify\.register\(multipart, \{[^}]+\}\);)", "`$1`nconsole.log('✅ 文件上传插件已配置: 最大文件大小 10MB');"
# 修改CORS配置为完整版本
$oldCors = "await fastify.register(cors, \{\s+origin: true, // 开发环境允许所有来源\s+credentials: true,\s+\}\);"
$newCors = @"
await fastify.register(cors, {
origin: true,
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'],
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With', 'Accept', 'Origin'],
exposedHeaders: ['Content-Range', 'X-Content-Range'],
maxAge: 600,
preflightContinue: false,
});
"@
$content = $content -replace $oldCors, $newCors
# 保存文件
Set-Content $filePath $content -Encoding UTF8
Write-Host "✅ CORS配置已修复请重启后端服务。" -ForegroundColor Green