mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-07-06 16:11:56 +08:00
73435497a2
- Load balancing (can connect to multiple accounts, automatically switch accounts when there is no quota) - AI call log - Model rate configuration
22 lines
657 B
TypeScript
22 lines
657 B
TypeScript
export const extractIPFromURL = (url: string | string[]) => {
|
|
if (Array.isArray(url)) {
|
|
url = url[0] // 获取第一个 URL
|
|
}
|
|
if (typeof url !== 'string' || !url.includes('://')) {
|
|
console.warn('Invalid URL format')
|
|
return null
|
|
}
|
|
const match = url.match(/https?:\/\/([\d.]+):\d+/)
|
|
return match ? match[1] : null
|
|
}
|
|
|
|
export const isPrivateIP = (ip: string) => {
|
|
if (typeof ip !== 'string') {
|
|
console.error('Invalid IP format')
|
|
return false
|
|
}
|
|
const privateIpRegex =
|
|
/^(10\.\d{1,3}\.\d{1,3}\.\d{1,3})$|^(172\.(1[6-9]|2[0-9]|3[0-1])\.\d{1,3}\.\d{1,3})$|^(192\.168\.\d{1,3}\.\d{1,3})$/
|
|
return privateIpRegex.test(ip)
|
|
}
|