Download services/ipService.ts from Lianjx/ai: direct link, hf CLI and curl.
- Browser
- Download file 700 Bytes
-
https://huggingface.co/spaces/Lianjx/ai/resolve/main/services/ipService.ts
- Command line
-
hf download hf://spaces/Lianjx/ai/services/ipService.ts
-
curl -L -o ipService.ts https://huggingface.co/spaces/Lianjx/ai/resolve/main/services/ipService.ts
700 Bytes
| export const ipService = { | |
| currentIp: 'Unknown', | |
| currentLocation: 'Unknown', | |
| trackVisit: async () => { | |
| try { | |
| // Use a free IP API (ipapi.co or similar that supports CORS for simple frontend use) | |
| const response = await fetch('https://ipapi.co/json/'); | |
| if (response.ok) { | |
| const data = await response.json(); | |
| ipService.currentIp = data.ip || 'Unknown'; | |
| // Combine city and region/country | |
| const loc = [data.city, data.region_code, data.country_name].filter(Boolean).join(', '); | |
| ipService.currentLocation = loc || 'Unknown'; | |
| } | |
| } catch (error) { | |
| console.warn('Failed to track IP, using default.', error); | |
| } | |
| } | |
| }; | |