From 53a56401e0070772b71fa99509e35a011e8057f2 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Sun, 10 Jul 2016 11:48:53 -0400 Subject: [PATCH] Change POST /grants|ipBans|punishments to use `expiresIn` (a relative field in seconds) instead of `expiresAt` (absolute time) --- .../java/net/frozenorb/apiv3/route/grants/POSTGrants.java | 5 +++-- .../java/net/frozenorb/apiv3/route/ipBans/POSTIpBans.java | 5 +++-- .../frozenorb/apiv3/route/punishments/POSTPunishments.java | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java b/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java index 5991f6a..f09ea0e 100644 --- a/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java +++ b/src/main/java/net/frozenorb/apiv3/route/grants/POSTGrants.java @@ -65,8 +65,9 @@ public final class POSTGrants implements Handler { Instant expiresAt = null; - if (requestBody.containsKey("expiresAt") && requestBody.getLong("expiresAt") != -1) { - expiresAt = Instant.ofEpochMilli(requestBody.getLong("expiresAt")); + if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) { + long expiresInMillis = requestBody.getLong("expiresIn") * 1000; + expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis); } if (expiresAt != null && expiresAt.isBefore(Instant.now())) { diff --git a/src/main/java/net/frozenorb/apiv3/route/ipBans/POSTIpBans.java b/src/main/java/net/frozenorb/apiv3/route/ipBans/POSTIpBans.java index 82f2b08..364a65c 100644 --- a/src/main/java/net/frozenorb/apiv3/route/ipBans/POSTIpBans.java +++ b/src/main/java/net/frozenorb/apiv3/route/ipBans/POSTIpBans.java @@ -35,8 +35,9 @@ public final class POSTIpBans implements Handler { Instant expiresAt = null; - if (requestBody.containsKey("expiresAt") && requestBody.getLong("expiresAt") != -1) { - expiresAt = Instant.ofEpochMilli(requestBody.getLong("expiresAt")); + if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) { + long expiresInMillis = requestBody.getLong("expiresIn") * 1000; + expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis); } if (expiresAt != null && expiresAt.isBefore(Instant.now())) { diff --git a/src/main/java/net/frozenorb/apiv3/route/punishments/POSTPunishments.java b/src/main/java/net/frozenorb/apiv3/route/punishments/POSTPunishments.java index 8e91985..2840158 100644 --- a/src/main/java/net/frozenorb/apiv3/route/punishments/POSTPunishments.java +++ b/src/main/java/net/frozenorb/apiv3/route/punishments/POSTPunishments.java @@ -63,8 +63,9 @@ public final class POSTPunishments implements Handler { Instant expiresAt = null; - if (requestBody.containsKey("expiresAt") && requestBody.getLong("expiresAt") != -1) { - expiresAt = Instant.ofEpochMilli(requestBody.getLong("expiresAt")); + if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) { + long expiresInMillis = requestBody.getLong("expiresIn") * 1000; + expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis); } if (expiresAt != null && expiresAt.isBefore(Instant.now())) {