'小红书解析
This commit is contained in:
@@ -28,8 +28,15 @@ export async function POST(request: NextRequest) {
|
||||
const city = String(formData.city || "").trim();
|
||||
const session = String(formData.session || "").trim();
|
||||
const ageRange = String(formData.age_range || "").trim();
|
||||
const wechatOrPhone = String(formData.wechat_or_phone || "").trim();
|
||||
const wechatOrPhone = String(formData.wechat_or_phone || formData.wechat || "").trim();
|
||||
const wechat = String(formData.wechat || "").trim();
|
||||
const phone = String(formData.phone || "").trim();
|
||||
const profession = String(formData.profession || "").trim();
|
||||
const education = String(formData.education || "").trim();
|
||||
const graduationYear = String(formData.graduation_year || formData.gradYear || "").trim();
|
||||
const xiaohongshuUrl = String(formData.xiaohongshu_url || "").trim();
|
||||
const xiaohongshuAvatarUrl = String(formData.xiaohongshu_avatar_url || formData.media || "").trim();
|
||||
const gender = String(formData.gender || "").trim() || "\u65e0";
|
||||
let intro = String(formData.intro || "").trim();
|
||||
const firstTime = String(formData.first_time || "").trim();
|
||||
const agreeRules = !!formData.agree_rules;
|
||||
@@ -43,32 +50,59 @@ export async function POST(request: NextRequest) {
|
||||
intro = extra;
|
||||
}
|
||||
|
||||
if (!nickname || !wechatOrPhone || !intro || !session || !agreeRules || !xiaohongshuUrl) {
|
||||
const isDigitalNomad = session === "digital-nomad";
|
||||
const contact = wechatOrPhone || wechat || phone;
|
||||
if (!nickname || !intro || !session || !agreeRules || !xiaohongshuUrl) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "请填写必填项(含小红书主页地址)" },
|
||||
{ ok: false, error: "请填写必填项(含小红书主页地址、自我介绍)" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
if (!contact) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "请填写微信号或手机号" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
if (isDigitalNomad && (!education || !graduationYear)) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "请选择学历和毕业时间" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const userId = getUserIdFromCookie(request) || generateAnonId();
|
||||
|
||||
const EDUCATION_GRAD_AGE: Record<string, number> = {
|
||||
"高中及以下": 18,
|
||||
大专: 21,
|
||||
本科: 22,
|
||||
硕士: 25,
|
||||
博士: 28,
|
||||
};
|
||||
const gradAge = EDUCATION_GRAD_AGE[education] ?? 22;
|
||||
const estimatedAge = new Date().getFullYear() - parseInt(graduationYear, 10) + gradAge;
|
||||
const ageRangeForRecord = isDigitalNomad && education && graduationYear
|
||||
? `推算约${estimatedAge}岁(学历${education}+${graduationYear}毕业)`
|
||||
: ageRange;
|
||||
|
||||
const record = {
|
||||
user_id: userId,
|
||||
nickname,
|
||||
occupation: city,
|
||||
occupation: isDigitalNomad ? profession : city,
|
||||
reason: intro,
|
||||
wechatId: wechatOrPhone,
|
||||
wechatId: wechat || wechatOrPhone,
|
||||
xiaohongshu_url: xiaohongshuUrl,
|
||||
gender: "",
|
||||
education: "",
|
||||
gradYear: "",
|
||||
phone: wechatOrPhone,
|
||||
gender,
|
||||
education: education,
|
||||
gradYear: graduationYear,
|
||||
phone: phone || wechatOrPhone,
|
||||
single: "",
|
||||
media: "",
|
||||
media: xiaohongshuAvatarUrl,
|
||||
type: session,
|
||||
order_id: "",
|
||||
amount: 0,
|
||||
age_range: ageRange,
|
||||
age_range: ageRangeForRecord,
|
||||
first_time: firstTime,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user