diff --git a/CHANGELOG.md b/CHANGELOG.md index c990f831..dd57b295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ See also the [v0.107.70 GitHub milestone][ms-v0.107.70]. NOTE: Add new changes BELOW THIS COMMENT. --> +### Added + +- New field `"start_time"` in the `GET /control/status` response. + diff --git a/client/src/actions/index.tsx b/client/src/actions/index.tsx index d122e215..76c38e72 100644 --- a/client/src/actions/index.tsx +++ b/client/src/actions/index.tsx @@ -222,7 +222,7 @@ const checkStatus = async (handleRequestSuccess: any, handleRequestError: any, a }; export const getUpdate = () => async (dispatch: any, getState: any) => { - const { dnsVersion } = getState().dashboard; + const { dnsVersion, dnsStartTime } = getState().dashboard; dispatch(getUpdateRequest()); const handleRequestError = () => { @@ -238,8 +238,9 @@ export const getUpdate = () => async (dispatch: any, getState: any) => { const handleRequestSuccess = (response: any) => { const responseVersion = response.data?.version; + const responseStartTime = response.data?.start_time; - if (dnsVersion !== responseVersion) { + if (dnsVersion !== responseVersion || dnsStartTime !== responseStartTime) { dispatch(getUpdateSuccess()); window.location.reload(); diff --git a/client/src/initialState.ts b/client/src/initialState.ts index 57993666..cd506156 100644 --- a/client/src/initialState.ts +++ b/client/src/initialState.ts @@ -128,6 +128,7 @@ export type DashboardData = { dnsPort: number; dnsAddresses: string[]; dnsVersion: string; + dnsStartTime: number | null; clients: Client[]; autoClients: AutoClient[]; supportedTags: string[]; @@ -445,6 +446,7 @@ export const initialState: RootState = { dnsPort: STANDARD_DNS_PORT, dnsAddresses: [], dnsVersion: '', + dnsStartTime: null, clients: [], autoClients: [], supportedTags: [], diff --git a/client/src/reducers/dashboard.ts b/client/src/reducers/dashboard.ts index 91f2b262..b745f5f4 100644 --- a/client/src/reducers/dashboard.ts +++ b/client/src/reducers/dashboard.ts @@ -21,6 +21,7 @@ const dashboard = handleActions( [actions.dnsStatusSuccess.toString()]: (state: any, { payload }: any) => { const { version, + start_time: dnsStartTime, dns_port: dnsPort, dns_addresses: dnsAddresses, protection_enabled: protectionEnabled, @@ -33,6 +34,7 @@ const dashboard = handleActions( isCoreRunning: true, processing: false, dnsVersion: version, + dnsStartTime, dnsPort, dnsAddresses, protectionEnabled, @@ -183,6 +185,7 @@ const dashboard = handleActions( dnsPort: STANDARD_DNS_PORT, dnsAddresses: [], dnsVersion: '', + dnsStartTime: null, clients: [], autoClients: [], supportedTags: [], diff --git a/internal/home/control.go b/internal/home/control.go index ecdb8ba3..b60a7cf4 100644 --- a/internal/home/control.go +++ b/internal/home/control.go @@ -107,6 +107,9 @@ type statusResponse struct { // milliseconds. ProtectionDisabledDuration int64 `json:"protection_disabled_duration"` + // StartTime is the start time of the web API server in Unix milliseconds. + StartTime aghhttp.JSONTime `json:"start_time"` + ProtectionEnabled bool `json:"protection_enabled"` // TODO(e.burkov): Inspect if front-end doesn't requires this field as // openapi.yaml declares. @@ -158,6 +161,7 @@ func (web *webAPI) handleStatus(w http.ResponseWriter, r *http.Request) { DNSPort: config.DNS.Port, HTTPPort: config.HTTPConfig.Address.Port(), ProtectionDisabledDuration: protectionDisabledDuration, + StartTime: aghhttp.JSONTime(web.startTime), ProtectionEnabled: protEnabled, IsRunning: isRunning(), } diff --git a/internal/home/web.go b/internal/home/web.go index 70e816bf..13761901 100644 --- a/internal/home/web.go +++ b/internal/home/web.go @@ -158,6 +158,9 @@ type webAPI struct { // httpsServer is the server that handles HTTPS traffic. If it is not nil, // [Web.http3Server] must also not be nil. httpsServer httpsServer + + // startTime is the start time of the web API server in Unix milliseconds. + startTime time.Time } // newWebAPI creates a new instance of the web UI and API server. conf must be @@ -176,6 +179,7 @@ func newWebAPI(ctx context.Context, conf *webConfig) (w *webAPI) { baseLogger: conf.baseLogger, tlsManager: conf.tlsManager, auth: conf.auth, + startTime: time.Now(), } clientFS := http.FileServer(http.FS(conf.clientFS)) diff --git a/openapi/CHANGELOG.md b/openapi/CHANGELOG.md index 16563a50..75cefc9d 100644 --- a/openapi/CHANGELOG.md +++ b/openapi/CHANGELOG.md @@ -2,6 +2,12 @@ +## v0.107.70: API changes + +### New `"start_time"` field in 'GET /control/status' + +- New field `"start_time"` indicates the start time of the web API server (Unix time in milliseconds). + ## v0.107.68: API changes ### New HTTP APIs 'GET /control/rewrite/settings' and 'PUT /control/rewrite/settings/update' diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index a5df03c2..bef4c97b 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -1500,6 +1500,11 @@ 'language': 'type': 'string' 'example': 'en' + 'start_time': + 'type': 'number' + 'format': 'double' + 'example': 1700000000000 + 'description': 'Start time of the web API server (Unix time in milliseconds).' 'DNSConfig': 'type': 'object' 'description': 'DNS server configuration'