-
Notifications
You must be signed in to change notification settings - Fork 134
/
index.ts
35 lines (30 loc) · 932 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import axios from "axios"
import { UnknownIpFetcherServiceError } from "@domain/ipfetcher"
import { PROXY_CHECK_APIKEY } from "@config"
export const IpFetcher = (): IIpFetcherService => {
const fetchIPInfo = async (ip: string): Promise<IPInfo | IpFetcherServiceError> => {
try {
const params: { [id: string]: string } = {
vpn: "1",
asn: "1",
time: "1",
risk: "1",
}
if (PROXY_CHECK_APIKEY) {
params["key"] = PROXY_CHECK_APIKEY
}
const { data } = await axios.request({
url: `https://proxycheck.io/v2/${ip}`,
params,
})
const proxy = !!(data[ip] && data[ip].proxy && data[ip].proxy === "yes")
const isoCode = data[ip] && data[ip].isocode
return { ...data[ip], isoCode, proxy, status: data.status }
} catch (err) {
return new UnknownIpFetcherServiceError(err)
}
}
return {
fetchIPInfo,
}
}