refactor: rename to RedirectTo

This commit is contained in:
Adam Shiervani 2025-10-23 15:26:48 +00:00
parent 632125e38f
commit e2fd6961e2
4 changed files with 9 additions and 9 deletions

View File

@ -29,7 +29,7 @@ func (s *RpcNetworkSettings) ToNetworkConfig() *types.NetworkConfig {
type PostRebootAction struct { type PostRebootAction struct {
HealthCheck string `json:"healthCheck"` HealthCheck string `json:"healthCheck"`
RedirectUrl string `json:"redirectUrl"` RedirectTo string `json:"redirectTo"`
} }
func toRpcNetworkSettings(config *types.NetworkConfig) *RpcNetworkSettings { func toRpcNetworkSettings(config *types.NetworkConfig) *RpcNetworkSettings {
@ -202,7 +202,7 @@ func shouldRebootForNetworkChange(oldConfig, newConfig *types.NetworkConfig) (re
if newIPv4Mode == "static" && oldIPv4Mode != "static" { if newIPv4Mode == "static" && oldIPv4Mode != "static" {
postRebootAction = &PostRebootAction{ postRebootAction = &PostRebootAction{
HealthCheck: fmt.Sprintf("//%s/device/status", newConfig.IPv4Static.Address.String), HealthCheck: fmt.Sprintf("//%s/device/status", newConfig.IPv4Static.Address.String),
RedirectUrl: fmt.Sprintf("//%s", newConfig.IPv4Static.Address.String), RedirectTo: fmt.Sprintf("//%s", newConfig.IPv4Static.Address.String),
} }
l.Info().Interface("postRebootAction", postRebootAction).Msg("IPv4 mode changed to static, reboot required") l.Info().Interface("postRebootAction", postRebootAction).Msg("IPv4 mode changed to static, reboot required")
} }
@ -219,7 +219,7 @@ func shouldRebootForNetworkChange(oldConfig, newConfig *types.NetworkConfig) (re
newConfig.IPv4Static.Address.String != oldConfig.IPv4Static.Address.String { newConfig.IPv4Static.Address.String != oldConfig.IPv4Static.Address.String {
postRebootAction = &PostRebootAction{ postRebootAction = &PostRebootAction{
HealthCheck: fmt.Sprintf("//%s/device/status", newConfig.IPv4Static.Address.String), HealthCheck: fmt.Sprintf("//%s/device/status", newConfig.IPv4Static.Address.String),
RedirectUrl: fmt.Sprintf("//%s", newConfig.IPv4Static.Address.String), RedirectTo: fmt.Sprintf("//%s", newConfig.IPv4Static.Address.String),
} }
l.Info().Interface("postRebootAction", postRebootAction).Msg("IPv4 static config changed, reboot required") l.Info().Interface("postRebootAction", postRebootAction).Msg("IPv4 static config changed, reboot required")

6
ota.go
View File

@ -490,7 +490,7 @@ func TryUpdate(ctx context.Context, deviceId string, includePreRelease bool) err
scopedLogger.Info().Msg("System Rebooting due to OTA update") scopedLogger.Info().Msg("System Rebooting due to OTA update")
// Build redirect URL with conditional query parameters // Build redirect URL with conditional query parameters
redirectUrl := "/settings/general/update" redirectTo := "/settings/general/update"
queryParams := url.Values{} queryParams := url.Values{}
if systemUpdateAvailable { if systemUpdateAvailable {
queryParams.Set("systemVersion", remote.SystemVersion) queryParams.Set("systemVersion", remote.SystemVersion)
@ -499,12 +499,12 @@ func TryUpdate(ctx context.Context, deviceId string, includePreRelease bool) err
queryParams.Set("appVersion", remote.AppVersion) queryParams.Set("appVersion", remote.AppVersion)
} }
if len(queryParams) > 0 { if len(queryParams) > 0 {
redirectUrl += "?" + queryParams.Encode() redirectTo += "?" + queryParams.Encode()
} }
postRebootAction := &PostRebootAction{ postRebootAction := &PostRebootAction{
HealthCheck: "/device/status", HealthCheck: "/device/status",
RedirectUrl: redirectUrl, RedirectTo: redirectTo,
} }
if err := hwReboot(true, postRebootAction, 10*time.Second); err != nil { if err := hwReboot(true, postRebootAction, 10*time.Second); err != nil {

View File

@ -474,13 +474,13 @@ export function RebootingOverlay({ show, postRebootAction }: RebootingOverlayPro
if (response.ok) { if (response.ok) {
// Device is available, redirect to the specified URL // Device is available, redirect to the specified URL
console.log('Device is available, redirecting to:', postRebootAction.redirectUrl); console.log('Device is available, redirecting to:', postRebootAction.redirectTo);
// URL constructor handles all cases elegantly: // URL constructor handles all cases elegantly:
// - Absolute paths: resolved against current origin // - Absolute paths: resolved against current origin
// - Protocol-relative URLs: resolved with current protocol // - Protocol-relative URLs: resolved with current protocol
// - Fully qualified URLs: used as-is // - Fully qualified URLs: used as-is
const targetUrl = new URL(postRebootAction.redirectUrl, window.location.origin); const targetUrl = new URL(postRebootAction.redirectTo, window.location.origin);
window.location.href = targetUrl.href; window.location.href = targetUrl.href;
} }

View File

@ -21,7 +21,7 @@ interface JsonRpcResponse {
export type PostRebootAction = { export type PostRebootAction = {
healthCheck: string; healthCheck: string;
redirectUrl: string; redirectTo: string;
} | null; } | null;
// Utility function to append stats to a Map // Utility function to append stats to a Map