/**
 * 从请求对象中提取客户端 IP 和 UserAgent
 */
export function extractRequestInfo(req: any): { ipAddress: string; userAgent: string } {
  const forwarded =
    req.headers?.['x-forwarded-for'] ||
    req.headers?.['x-real-ip'] ||
    req.connection?.remoteAddress ||
    '';
  const ipAddress = String(forwarded).split(',')[0].trim() || 'unknown';
  const userAgent = (req.headers?.['user-agent'] || '').substring(0, 500);
  return { ipAddress, userAgent };
}
