Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export type Node = {
total_tx: number
month_rx: number
month_tx: number
/** This period's usage as the plan meters it (`traffic_mode`). Absent on older hubs. */
month_used?: number
month_start: string
day_rx: number
day_tx: number
Expand Down
1 change: 1 addition & 0 deletions src/lib/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ eq(duration(76 * 86400 + 5), "76 天", "超过一天只写天数")
eq(monthUsage({ ...node, traffic_mode: "up" }), 5, "仅上行")
eq(monthUsage({ ...node, traffic_mode: "down" }), 3, "仅下行")
eq(monthUsage({ ...node, traffic_mode: "max" }), 5, "取较大值")
eq(monthUsage({ ...node, traffic_mode: "up", month_used: 7 }), 7, "hub 算好的值优先")
}

eq(osName("Debian GNU/Linux 12 (bookworm)"), "Debian 12", "发行版名去掉代号")
Expand Down
8 changes: 6 additions & 2 deletions src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ export function duration(seconds: number): string {
return `${Math.floor(s / 3600)}:${pad(Math.floor((s % 3600) / 60))}:${pad(s % 60)}`
}

/** The month's usage counted the way the node's plan meters it. */
export function monthUsage(node: { month_rx: number; month_tx: number; traffic_mode: string }): number {
/**
* The month's usage counted the way the node's plan meters it. The hub computes
* it; the switch below serves only a hub from before `month_used`.
*/
export function monthUsage(node: { month_rx: number; month_tx: number; month_used?: number; traffic_mode: string }): number {
if (typeof node.month_used === "number") return node.month_used
const { month_rx: rx, month_tx: tx } = node
switch (node.traffic_mode) {
case "up":
Expand Down
Loading