Minor changes

This commit is contained in:
Eduard Urbach 2017-10-21 17:07:25 +02:00
parent 26422408ce
commit 1a693fec05

View File

@ -1,17 +1,16 @@
package middleware
import (
"encoding/json"
"net/http"
"strconv"
"strings"
"github.com/aerogo/aero"
"github.com/aerogo/http/client"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/utils"
"github.com/fatih/color"
"github.com/mssola/user_agent"
"github.com/parnurzeal/gorequest"
)
// 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) {
user.IP = newIP
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 len(err) > 0 && err[0] != nil {
color.Red("Couldn't fetch location data | Error: %s | IP: %s", err[0].Error(), user.IP)
if err != nil {
color.Red("Couldn't fetch location data | Error: %s | IP: %s", err.Error(), user.IP)
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)
return
}
newLocation := arn.IPInfoDBLocation{}
json.Unmarshal(data, &newLocation)
response.Unmarshal(&newLocation)
if newLocation.CountryName != "-" {
user.Location.CountryName = newLocation.CountryName