Minor changes
This commit is contained in:
parent
26422408ce
commit
1a693fec05
@ -1,17 +1,16 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/aerogo/http/client"
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
"github.com/animenotifier/notify.moe/utils"
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/mssola/user_agent"
|
"github.com/mssola/user_agent"
|
||||||
"github.com/parnurzeal/gorequest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// UserInfo updates user related information after each request.
|
// UserInfo updates user related information after each request.
|
||||||
@ -73,21 +72,20 @@ func updateUserInfo(ctx *aero.Context, user *arn.User) {
|
|||||||
func updateUserLocation(user *arn.User, newIP string) {
|
func updateUserLocation(user *arn.User, newIP string) {
|
||||||
user.IP = newIP
|
user.IP = newIP
|
||||||
locationAPI := "https://api.ipinfodb.com/v3/ip-city/?key=" + arn.APIKeys.IPInfoDB.ID + "&ip=" + user.IP + "&format=json"
|
locationAPI := "https://api.ipinfodb.com/v3/ip-city/?key=" + arn.APIKeys.IPInfoDB.ID + "&ip=" + user.IP + "&format=json"
|
||||||
|
response, err := client.Get(locationAPI).End()
|
||||||
|
|
||||||
response, data, err := gorequest.New().Get(locationAPI).EndBytes()
|
if err != nil {
|
||||||
|
color.Red("Couldn't fetch location data | Error: %s | IP: %s", err.Error(), user.IP)
|
||||||
if len(err) > 0 && err[0] != nil {
|
|
||||||
color.Red("Couldn't fetch location data | Error: %s | IP: %s", err[0].Error(), user.IP)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if response.StatusCode != http.StatusOK {
|
if response.StatusCode() != http.StatusOK {
|
||||||
color.Red("Couldn't fetch location data | Status: %d | IP: %s", response.StatusCode, user.IP)
|
color.Red("Couldn't fetch location data | Status: %d | IP: %s", response.StatusCode, user.IP)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
newLocation := arn.IPInfoDBLocation{}
|
newLocation := arn.IPInfoDBLocation{}
|
||||||
json.Unmarshal(data, &newLocation)
|
response.Unmarshal(&newLocation)
|
||||||
|
|
||||||
if newLocation.CountryName != "-" {
|
if newLocation.CountryName != "-" {
|
||||||
user.Location.CountryName = newLocation.CountryName
|
user.Location.CountryName = newLocation.CountryName
|
||||||
|
Loading…
Reference in New Issue
Block a user