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:
parent
6920152c90
commit
e954c7930a
1 changed files with 3 additions and 1 deletions
|
|
@ -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}
|
||||
|
||||
_ ->
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue