Fix Gaiia webhook timestamp: Gaiia sends millis, not seconds

The timestamp check was comparing millisecond timestamps against
System.system_time(:second), causing every webhook to be rejected
as 'expired'. Now normalizes timestamps >10 digits to seconds.
This commit is contained in:
Graham McIntire 2026-02-14 17:15:17 -06:00
parent 6920152c90
commit e954c7930a

View file

@ -149,7 +149,9 @@ defmodule ToweropsWeb.Api.V1.GaiiaWebhookController do
defp check_timestamp(timestamp_str) do
case Integer.parse(timestamp_str) do
{ts, ""} ->
age = abs(System.system_time(:second) - ts)
# Gaiia sends timestamps in milliseconds — normalize to seconds
ts_seconds = if ts > 9_999_999_999, do: div(ts, 1000), else: ts
age = abs(System.system_time(:second) - ts_seconds)
if age <= @max_age_seconds, do: :ok, else: {:error, :expired}
_ ->