-
Notifications
You must be signed in to change notification settings - Fork 27
/
connection.js
76 lines (72 loc) · 1.67 KB
/
connection.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
export { fetchAPI, getConnection };
// Gets connection values
const fetchAPI = (setData) => {
fetch('https://api.vytal.io/ip/')
.then((response) => response.json())
.then((json) => {
setData(json);
});
};
// Returns object with connection data
const getConnection = (connectionData, workerData) => {
const timeZoneIssue = compareTimeZone(
connectionData.timezone,
workerData.timeZone
);
const isProxy = checkProxy(connectionData.proxy);
const data = [
{
key: 'IP address',
value: connectionData.query,
issues: [timeZoneIssue, isProxy],
},
{
key: 'Country',
value: connectionData.country,
issues: [timeZoneIssue, isProxy],
},
{
key: 'Region',
value: connectionData.regionName,
issues: [timeZoneIssue, isProxy],
},
{
key: 'City',
value: connectionData.city,
issues: [timeZoneIssue, isProxy],
},
{
key: 'Time zone',
value: connectionData.timezone,
issues: [timeZoneIssue, isProxy],
},
{
key: 'Zip code',
value: connectionData.zip,
issues: [timeZoneIssue, isProxy],
},
{
key: 'Latitude',
value: connectionData.lat,
issues: [timeZoneIssue, isProxy],
},
{
key: 'Longitude',
value: connectionData.lon,
issues: [timeZoneIssue, isProxy],
},
];
return data;
};
const compareTimeZone = (connectionTimeZone, workerTimeZone) => {
if (connectionTimeZone !== workerTimeZone) {
return "Connection data doesn't match system data";
}
return null;
};
const checkProxy = (proxy) => {
if (proxy) {
return 'VPN/proxy has been detected';
}
return null;
};