@@ -89,9 +89,13 @@ export function getDomain(index: number): ServerConfig {
8989 ) ;
9090}
9191
92- export function updateDomain ( index : number , server : ServerConfig ) : void {
93- reloadDatabase ( ) ;
94- serverConfigSchema . parse ( server ) ;
92+ export function getDomainById ( id : string ) : ServerConfig | undefined {
93+ return getDomains ( ) . find ( ( server ) => server . id === id ) ;
94+ }
95+
96+ export function updateDomainById ( id : string , server : ServerConfig ) : void {
97+ const index = getDomains ( ) . findIndex ( ( domain ) => domain . id === id ) ;
98+ assert . ok ( index !== - 1 , `Domain with id ${ id } not found` ) ;
9599 database . push ( `/domains[${ index } ]` , server , true ) ;
96100}
97101
@@ -164,10 +168,10 @@ export async function saveServerIcon(iconURL: string): Promise<string> {
164168
165169export async function updateSavedServer (
166170 url : string ,
167- index : number ,
171+ id : string ,
168172) : Promise < ServerConfig > {
169173 // Does not promise successful update
170- const serverConfig = getDomain ( index ) ;
174+ const serverConfig = getDomainById ( id ) ! ;
171175 const oldIcon = serverConfig . icon ;
172176 try {
173177 const newServerSetting = await checkDomain ( url , true ) ;
@@ -178,7 +182,7 @@ export async function updateSavedServer(
178182 const localIconUrl = await saveServerIcon ( newServerConfig . icon ) ;
179183 if ( ! oldIcon || localIconUrl !== defaultIconSentinel ) {
180184 newServerConfig . icon = localIconUrl ;
181- updateDomain ( index , newServerConfig ) ;
185+ updateDomainById ( id , newServerConfig ) ;
182186 reloadDatabase ( ) ;
183187 }
184188
0 commit comments