Files
2026-03-16 04:28:16 -05:00

30 lines
1.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 });
}
}