Files
users/app/api/rfm/weights/route.ts
v0 f0a6a364f2 feat: sync Sidebar and BottomNav, standardize user profile API
Align Sidebar & BottomNav menus, remove "Search", add user profile mock data, implement /api/users, add FilterDrawer, complete Section, ProfileHeader, MetricsRFM components

Co-authored-by: null <4804959+fnvtk@users.noreply.github.com>
2025-08-08 07:00:12 +00:00

27 lines
732 B
TypeScript

import { NextResponse } from "next/server"
import { getWeights, setWeights } from "@/services/rfm-engine"
export async function GET() {
return NextResponse.json({ success: true, data: getWeights() })
}
export async function POST(req: Request) {
try {
const body = await req.json()
let R = Number(body.R ?? 0.5)
let F = Number(body.F ?? 0.3)
let M = Number(body.M ?? 0.2)
// 归一化
const sum = Math.max(0.000001, R + F + M)
R = R / sum
F = F / sum
M = M / sum
setWeights({ R, F, M })
return NextResponse.json({ success: true, data: { R, F, M } })
} catch (e: any) {
return NextResponse.json({ success: false, error: e?.message || "Invalid input" }, { status: 400 })
}
}