mirror of
https://github.com/tale/headplane.git
synced 2026-08-21 10:16:37 +00:00
refactor: extract isNoExpiry utility for zero-time handling
Go's time.Time{} serialises to '0001-01-01T00:00:00Z' which headscale
may return instead of null for tagged nodes (juanfont/headscale#3170).
Commit extracts the the existing inline check into a shared function for reuse.
No behavior change — mapNodes() already handled both variants.
This commit is contained in:
@@ -12,6 +12,11 @@ export interface PopulatedNode extends Machine {
|
||||
};
|
||||
}
|
||||
|
||||
const GO_ZERO_TIMES = new Set(["0001-01-01 00:00:00", "0001-01-01T00:00:00Z"]);
|
||||
export function isNoExpiry(expiry: string | null | undefined): boolean {
|
||||
return expiry == null || GO_ZERO_TIMES.has(expiry);
|
||||
}
|
||||
|
||||
export function mapNodes(
|
||||
nodes: Machine[],
|
||||
stats?: Record<string, HostInfo> | undefined,
|
||||
@@ -35,12 +40,7 @@ export function mapNodes(
|
||||
routes: Array.from(new Set(node.availableRoutes)),
|
||||
hostInfo: stats?.[node.nodeKey],
|
||||
customRouting,
|
||||
expired:
|
||||
node.expiry === "0001-01-01 00:00:00" ||
|
||||
node.expiry === "0001-01-01T00:00:00Z" ||
|
||||
node.expiry === null
|
||||
? false
|
||||
: new Date(node.expiry).getTime() < Date.now(),
|
||||
expired: isNoExpiry(node.expiry) ? false : new Date(node.expiry!).getTime() < Date.now(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user