migrate apiConfiguration protobus (#4072)
* migrate apiConfiguration * fix type issue --------- Co-authored-by: Elephant Lumps <celestial_vault@Elephants-MacBook-Pro.local>
This commit is contained in:
1 parent
f16c70e200
commit
9733ef791e
9 files changed
+684
-33
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import type { Controller } from "../index"
|
||||
import { Empty } from "@shared/proto/common"
|
||||
import { UpdateApiConfigurationRequest } from "@shared/proto/models"
|
||||
import { updateApiConfiguration } from "../../storage/state"
|
||||
import { buildApiHandler } from "@api/index"
|
||||
import { convertProtoToApiConfiguration } from "@shared/proto-conversions/models/api-configuration-conversion"
|
||||
|
||||
/**
|
||||
* Updates API configuration
|
||||
* @param controller The controller instance
|
||||
* @param request The update API configuration request
|
||||
* @returns Empty response
|
||||
*/
|
||||
export async function updateApiConfigurationProto(
|
||||
controller: Controller,
|
||||
request: UpdateApiConfigurationRequest,
|
||||
): Promise<Empty> {
|
||||
try {
|
||||
if (!request.apiConfiguration) {
|
||||
console.log("[APICONFIG: updateApiConfigurationProto] API configuration is required")
|
||||
throw new Error("API configuration is required")
|
||||
}
|
||||
|
||||
// Convert proto ApiConfiguration to application ApiConfiguration
|
||||
const appApiConfiguration = convertProtoToApiConfiguration(request.apiConfiguration)
|
||||
|
||||
// Update the API configuration in storage
|
||||
await updateApiConfiguration(controller.context, appApiConfiguration)
|
||||
|
||||
// Update the task's API handler if there's an active task
|
||||
if (controller.task) {
|
||||
controller.task.api = buildApiHandler(appApiConfiguration)
|
||||
}
|
||||
|
||||
// Post updated state to webview
|
||||
await controller.postStateToWebview()
|
||||
|
||||
return Empty.create()
|
||||
} catch (error) {
|
||||
console.error(`Failed to update API configuration: ${error}`)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user