'小红书解析

This commit is contained in:
eric
2026-03-16 04:28:16 -05:00
parent ff135563fb
commit ff31ef8001
15 changed files with 700 additions and 403 deletions

View File

@@ -0,0 +1,29 @@
import { NextRequest, NextResponse } from "next/server";
/** 支持:xiaohongshu.com/user/profile/xxx、xhslink.com/user/profile/xxx、xhslink.com/m/xxx 短链 */
const XH_PROFILE_PATTERN = /^https?:\/\/(www\.)?(xiaohongshu\.com|xhslink\.com)\/user\/profile\/[a-zA-Z0-9_-]+/i;
const XH_SHORT_PATTERN = /^https?:\/\/xhslink\.com\/m\/[a-zA-Z0-9_-]+/i;
function isValidUrl(url: string): boolean {
return XH_PROFILE_PATTERN.test(url) || XH_SHORT_PATTERN.test(url);
}
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const url = String(body?.url || "").trim();
if (!url) {
return NextResponse.json({ valid: false, error: "请输入小红书链接" }, { status: 400 });
}
const valid = isValidUrl(url);
if (!valid) {
return NextResponse.json({ valid: false, error: "小红书link异常" }, { status: 200 });
}
return NextResponse.json({ valid: true });
} catch {
return NextResponse.json({ valid: false, error: "校验失败" }, { status: 500 });
}
}