From 005505a2daa14925c8254fbc7d1435c4c9e96424 Mon Sep 17 00:00:00 2001 From: Siyuan Date: Mon, 10 Nov 2025 17:00:31 +0000 Subject: [PATCH] chore(ota): use []string instead of comma-separated string --- ota.go | 15 +++++---------- ui/src/routes/devices.$id.settings.advanced.tsx | 2 +- .../devices.$id.settings.general.update.tsx | 9 ++++----- ui/src/utils/jsonrpc.ts | 2 +- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/ota.go b/ota.go index 56a67bcc..ebea1800 100644 --- a/ota.go +++ b/ota.go @@ -135,9 +135,9 @@ func rpcGetLocalVersion() (*ota.LocalMetadata, error) { } type updateParams struct { - AppTargetVersion string `json:"appTargetVersion"` - SystemTargetVersion string `json:"systemTargetVersion"` - Components string `json:"components,omitempty"` // components is a comma-separated list of components to update + AppTargetVersion string `json:"appTargetVersion"` + SystemTargetVersion string `json:"systemTargetVersion"` + Components []string `json:"components,omitempty"` } func rpcTryUpdate() error { @@ -154,9 +154,7 @@ func rpcCheckUpdateComponents(params updateParams, includePreRelease bool) (*ota IncludePreRelease: includePreRelease, AppTargetVersion: params.AppTargetVersion, SystemTargetVersion: params.SystemTargetVersion, - } - if params.Components != "" { - updateParams.Components = strings.Split(params.Components, ",") + Components: params.Components, } info, err := otaState.GetUpdateStatus(context.Background(), updateParams) if err != nil { @@ -170,6 +168,7 @@ func rpcTryUpdateComponents(params updateParams, includePreRelease bool, resetCo DeviceID: GetDeviceID(), IncludePreRelease: includePreRelease, ResetConfig: resetConfig, + Components: params.Components, } updateParams.AppTargetVersion = params.AppTargetVersion @@ -182,10 +181,6 @@ func rpcTryUpdateComponents(params updateParams, includePreRelease bool, resetCo return fmt.Errorf("failed to set system target version: %w", err) } - if params.Components != "" { - updateParams.Components = strings.Split(params.Components, ",") - } - go func() { err := otaState.TryUpdate(context.Background(), updateParams) if err != nil { diff --git a/ui/src/routes/devices.$id.settings.advanced.tsx b/ui/src/routes/devices.$id.settings.advanced.tsx index 260db3ca..5eccce31 100644 --- a/ui/src/routes/devices.$id.settings.advanced.tsx +++ b/ui/src/routes/devices.$id.settings.advanced.tsx @@ -203,7 +203,7 @@ export default function SettingsAdvancedRoute() { // because it will be redirected to the update page later setVersionUpdateLoading(true); versionInfo = await checkUpdateComponents({ - components: components.join(","), + components, appTargetVersion: appVersion, systemTargetVersion: systemVersion, }, devChannel); diff --git a/ui/src/routes/devices.$id.settings.general.update.tsx b/ui/src/routes/devices.$id.settings.general.update.tsx index fb5be055..17f576ca 100644 --- a/ui/src/routes/devices.$id.settings.general.update.tsx +++ b/ui/src/routes/devices.$id.settings.general.update.tsx @@ -49,7 +49,7 @@ export default function SettingsGeneralUpdateRoute() { send("tryUpdateComponents", { params: { - components: components.join(","), + components, appTargetVersion, systemTargetVersion, }, @@ -196,13 +196,12 @@ function LoadingState({ return await getVersionInfo(); } const params : updateParams = { - components: "", + components: [], appTargetVersion: customAppVersion, systemTargetVersion: customSystemVersion, }; - if (customAppVersion) params.components += ",app"; - if (customSystemVersion) params.components += ",system"; - params.components = params.components?.replace(/^,+/, ""); + if (customAppVersion) params.components?.push("app"); + if (customSystemVersion) params.components?.push("system"); return await checkUpdateComponents(params, false); }, [customAppVersion, customSystemVersion, getVersionInfo]); diff --git a/ui/src/utils/jsonrpc.ts b/ui/src/utils/jsonrpc.ts index 51d12127..f4cbc91f 100644 --- a/ui/src/utils/jsonrpc.ts +++ b/ui/src/utils/jsonrpc.ts @@ -246,7 +246,7 @@ export async function getLocalVersion() { export interface updateParams { appTargetVersion?: string; systemTargetVersion?: string; - components?: string; + components?: string[]; } export async function checkUpdateComponents(params: updateParams, includePreRelease: boolean) {