fix: 修复章节API的Next.js 16兼容性问题

- 更新chapter/[id]/route.ts使用Promise params (Next.js 16要求)
- 删除过时的app/api/db目录下的旧API文件(bookDB/userDB等不存在的导出)
- 添加部署脚本deploy-to-server.sh
- 添加章节迁移脚本migrate-chapters-to-db.ts
This commit is contained in:
卡若
2026-01-25 10:36:30 +08:00
parent 263da246c9
commit 153b8d9795
11 changed files with 300 additions and 656 deletions

View File

@@ -1,96 +0,0 @@
import { NextRequest, NextResponse } from 'next/server'
import { distributionDB, purchaseDB } from '@/lib/db'
// 获取分销数据
export async function GET(req: NextRequest) {
try {
const { searchParams } = new URL(req.url)
const type = searchParams.get('type')
const referrerId = searchParams.get('referrer_id')
// 获取佣金记录
if (type === 'commissions') {
const commissions = await distributionDB.getAllCommissions()
return NextResponse.json({ success: true, commissions })
}
// 获取指定推荐人的绑定
if (referrerId) {
const bindings = await distributionDB.getBindingsByReferrer(referrerId)
return NextResponse.json({ success: true, bindings })
}
// 获取所有绑定关系
const bindings = await distributionDB.getAllBindings()
return NextResponse.json({ success: true, bindings })
} catch (error: any) {
console.error('Get distribution data error:', error)
return NextResponse.json({
success: false,
error: error.message
}, { status: 500 })
}
}
// 创建绑定或佣金记录
export async function POST(req: NextRequest) {
try {
const body = await req.json()
const { type, data } = body
if (type === 'binding') {
const binding = await distributionDB.createBinding({
id: `binding_${Date.now()}`,
...data,
bound_at: new Date().toISOString(),
expires_at: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(), // 30天有效期
status: 'active'
})
return NextResponse.json({ success: true, binding })
}
if (type === 'commission') {
const commission = await distributionDB.createCommission({
id: `commission_${Date.now()}`,
...data,
status: 'pending'
})
return NextResponse.json({ success: true, commission })
}
return NextResponse.json({
success: false,
error: '未知操作类型'
}, { status: 400 })
} catch (error: any) {
console.error('Create distribution record error:', error)
return NextResponse.json({
success: false,
error: error.message
}, { status: 500 })
}
}
// 更新绑定状态
export async function PUT(req: NextRequest) {
try {
const body = await req.json()
const { id, status } = body
if (!id) {
return NextResponse.json({
success: false,
error: '缺少记录ID'
}, { status: 400 })
}
await distributionDB.updateBindingStatus(id, status)
return NextResponse.json({ success: true })
} catch (error: any) {
console.error('Update distribution status error:', error)
return NextResponse.json({
success: false,
error: error.message
}, { status: 500 })
}
}