Match distance query parameter behavior with PHP backend

This commit is contained in:
Maddie Zhan 2020-03-06 14:28:59 +08:00
parent f7ccda23e1
commit 275286cd79
6 changed files with 7 additions and 10 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
results/idObfuscation_salt.php results/idObfuscation_salt.php
backend/getIP_serverLocation.php backend/getIP_serverLocation.php
speedtest.db
.idea/

View file

@ -72,8 +72,6 @@ You need Go 1.13+ to compile the binary.
download_chunks=4 download_chunks=4
# ipinfo.io API key, if applicable # ipinfo.io API key, if applicable
ipinfo_api_key="" ipinfo_api_key=""
# distance unit used in frontend, available options: M (miles), K (kilometers), N (nautical miles), default is "K"
distance_unit="K"
# password for logging into statistics page, change this to enable stats page # password for logging into statistics page, change this to enable stats page
statistics_password="PASSWORD" statistics_password="PASSWORD"

View file

@ -10,7 +10,6 @@ type Config struct {
Port string `mapstructure:"listen_port"` Port string `mapstructure:"listen_port"`
DownloadChunks int `mapstructure:"download_chunks"` DownloadChunks int `mapstructure:"download_chunks"`
IPInfoAPIKey string `mapstructure:"ipinfo_api_key"` IPInfoAPIKey string `mapstructure:"ipinfo_api_key"`
DistanceUnit string `mapstructure:"distance_unit"`
StatsPassword string `mapstructure:"statistics_password"` StatsPassword string `mapstructure:"statistics_password"`
RedactIP bool `mapstructure:"redact_ip_addresses"` RedactIP bool `mapstructure:"redact_ip_addresses"`

View file

@ -6,8 +6,6 @@ listen_port=8989
download_chunks=4 download_chunks=4
# ipinfo.io API key, if applicable # ipinfo.io API key, if applicable
ipinfo_api_key="" ipinfo_api_key=""
# distance unit used in frontend, available options: M (miles), K (kilometers), N (nautical miles)
distance_unit="K"
# password for logging into statistics page # password for logging into statistics page
statistics_password="PASSWORD" statistics_password="PASSWORD"

View file

@ -143,10 +143,10 @@ func calculateDistance(clientLocation string, unit string) string {
unitString := " mi" unitString := " mi"
switch unit { switch unit {
case "K": case "km":
dist = dist * 1.609344 dist = dist * 1.609344
unitString = " km" unitString = " km"
case "N": case "NM":
dist = dist * 0.8684 dist = dist * 0.8684
unitString = " NM" unitString = " NM"
} }

View file

@ -155,7 +155,7 @@ func getIP(w http.ResponseWriter, r *http.Request) {
} }
getISPInfo := r.FormValue("isp") == "true" getISPInfo := r.FormValue("isp") == "true"
getDistance := r.FormValue("distance") == "true" distanceUnit := r.FormValue("distance")
ret.ProcessedString = clientIP ret.ProcessedString = clientIP
@ -174,8 +174,8 @@ func getIP(w http.ResponseWriter, r *http.Request) {
isp += ", " + ispInfo.Country isp += ", " + ispInfo.Country
} }
if ispInfo.Location != "" && getDistance { if ispInfo.Location != "" {
isp += " (" + calculateDistance(ispInfo.Location, config.LoadedConfig().DistanceUnit) + ")" isp += " (" + calculateDistance(ispInfo.Location, distanceUnit) + ")"
} }
ret.ProcessedString += " - " + isp ret.ProcessedString += " - " + isp