From 0f65b1f0ffcf2d50e535c9f1f29bb479e554c967 Mon Sep 17 00:00:00 2001 From: Gerard Braad Date: Thu, 22 Jun 2023 15:35:11 +0800 Subject: [PATCH] More type info --- src/app.tsx | 9 ++++----- src/types.ts | 46 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index 4d9ed78..3396e2e 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -1,17 +1,16 @@ import React from 'react'; -import { TailscaleBackendState, TailscaleStatusResponse, TailscaleUpResponse } from './types'; +import { TailscaleBackendState, TailscaleStatus, TailscaleUp } from './types'; import { Card, CardTitle, CardBody } from '@patternfly/react-core'; type ApplicationProps = { } type ApplicationState = { - Status: TailscaleStatusResponse + Status: TailscaleStatus } - export class Application extends React.Component { state: ApplicationState = { Status: null @@ -21,7 +20,7 @@ export class Application extends React.Component { - const status: TailscaleStatusResponse = JSON.parse(content) + const status: TailscaleStatus = JSON.parse(content) this.setState(state => ({Status: status})); }); } @@ -34,7 +33,7 @@ export class Application extends React.Component { this.state.Status != null - ? this.state.Status.Self.TailscaleIPs[0] + ? this.state.Status.Self.HostName + " " + this.state.Status.Self.TailscaleIPs[0] :

Loading...

} diff --git a/src/types.ts b/src/types.ts index d99f262..9d0a83b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,25 +9,47 @@ export type TailscaleBackendState = | 'Starting' | 'Running'; -export type TailscaleStatusResponse = { - BackendState: TailscaleBackendState; - AuthURL: string; - Self: { +export enum OS { + Android = "android", + IOS = "iOS", + Linux = "linux", + MACOS = "macOS", + Windows = "windows", +} + +export type TailscalePeer = { ID: string; - UserID: number; + PublicKey: string; HostName: string; DNSName: string; - OS: string; + OS: OS; + UserID: string; + TailscaleIPs: string[] + Tags?: string[]; + Online: boolean; + Capabilities?: string[]; +} + +export interface TailscaleExitNodeStatus { + ID: string; + Online: boolean; TailscaleIPs: string[]; - Capabilities: string[]; - Online: boolean - }; +} + +export type TailscaleStatus = { + BackendState: TailscaleBackendState; + AuthURL: string; + Self: TailscalePeer, User: Record | null; CurrentTailnet: { Name: string; MagicDNSSuffix: string; MagicDNSEnabled: boolean; } | null; + ExitNodeStatus: TailscaleExitNodeStatus | null; + Peer: { + [key: string]: TailscalePeer + }; }; export type TailscaleUser = { @@ -38,8 +60,8 @@ export type TailscaleUser = { Roles: string[]; }; -export type TailscaleUpResponse = { +export type TailscaleUp = { BackendState: TailscaleBackendState; - AuthURL?: string; // e.g. https://login.tailscale.com/a/0123456789abcdef - QR?: string; // a DataURL-encoded QR code PNG of the AuthURL + AuthURL?: string; + QR?: string; }; \ No newline at end of file