Skip to content

Commit

Permalink
Fix geo lookup CU-86c0p0yb9
Browse files Browse the repository at this point in the history
  • Loading branch information
jacooobi committed Oct 24, 2024
1 parent 0e6f9d1 commit bc78478
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/plausible_web/controllers/api/external_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,11 @@ defmodule PlausibleWeb.Api.ExternalController do
ip = PlausibleWeb.RemoteIp.get(conn)

case :locus.lookup(:geolocation, ip) do
{:ok, result} -> get_location_details(result)
_ -> get_location_details(%{})
{:ok, result} ->
get_location_details(result)

_ ->
get_location_details(nil)
end
end

Expand All @@ -467,7 +470,7 @@ defmodule PlausibleWeb.Api.ExternalController do
}
end

defp get_country_code(%{}), do: ""
defp get_country_code(nil), do: ""

defp get_country_code(geo_data) do
geo_data
Expand All @@ -476,7 +479,7 @@ defmodule PlausibleWeb.Api.ExternalController do
|> ignore_unknown_country()
end

defp get_city_geoname_id(%{}), do: ""
defp get_city_geoname_id(nil), do: ""

defp get_city_geoname_id(geo_data) do
city =
Expand All @@ -487,7 +490,7 @@ defmodule PlausibleWeb.Api.ExternalController do
Map.get(@city_overrides, city, city)
end

defp get_subdivision_code(%{}, _), do: ""
defp get_subdivision_code(nil, _), do: ""

defp get_subdivision_code(geo_data, n) do
subdivisions = Map.get(geo_data, "subdivision", [])
Expand Down

0 comments on commit bc78478

Please sign in to comment.