fix(traffic): подтверждать свежесть статусов привязанных интерфейсов
This commit is contained in:
1 parent
2b3d583e3b
commit
b4d0733cfa
27 files changed
+1463
-36
No files matched your search
@@ -0,0 +1,6 @@
|
||||
export function projectTrafficBindingStatus(status: unknown, observedAt: unknown, expiresAt: unknown, now = Date.now()): "online" | "offline" | "unknown" {
|
||||
if ((status !== "online" && status !== "offline") || typeof observedAt !== "string" || typeof expiresAt !== "string") return "unknown"
|
||||
const observed = Date.parse(observedAt), expires = Date.parse(expiresAt)
|
||||
if (!Number.isFinite(observed) || !Number.isFinite(expires) || observed >= expires || now > expires || observed > now + (expires-observed)/3) return "unknown"
|
||||
return status
|
||||
}
|
||||
Reference in new issue
Block a user