* 保存图片服务商
()
| 407 | * 保存图片服务商 |
| 408 | */ |
| 409 | async function saveImageProvider() { |
| 410 | const name = editingImageProvider.value || imageForm.value.name |
| 411 | |
| 412 | if (!name) { |
| 413 | setError('请填写服务商名称', '配置不完整') |
| 414 | return |
| 415 | } |
| 416 | |
| 417 | if (!imageForm.value.type) { |
| 418 | setError('请填写服务商类型', '配置不完整') |
| 419 | return |
| 420 | } |
| 421 | |
| 422 | // 新增时必须填写 API Key |
| 423 | if (!editingImageProvider.value && !imageForm.value.api_key) { |
| 424 | setError('请填写 API Key', '配置不完整') |
| 425 | return |
| 426 | } |
| 427 | |
| 428 | const existingProvider = imageConfig.value.providers[name] || {} |
| 429 | |
| 430 | const providerData: any = { |
| 431 | ...existingProvider, |
| 432 | type: imageForm.value.type, |
| 433 | model: imageForm.value.model, |
| 434 | high_concurrency: imageForm.value.high_concurrency, |
| 435 | short_prompt: imageForm.value.short_prompt |
| 436 | } |
| 437 | |
| 438 | // 如果是 OpenAI 兼容接口,保存 endpoint_type |
| 439 | if (imageForm.value.type === 'image_api') { |
| 440 | providerData.endpoint_type = imageForm.value.endpoint_type |
| 441 | } |
| 442 | |
| 443 | // 如果填写了新的 API Key,使用新的;否则保留原有的 |
| 444 | if (imageForm.value.api_key) { |
| 445 | providerData.api_key = imageForm.value.api_key |
| 446 | } else if (existingProvider.api_key) { |
| 447 | providerData.api_key = existingProvider.api_key |
| 448 | } |
| 449 | |
| 450 | if (imageForm.value.base_url) { |
| 451 | providerData.base_url = imageForm.value.base_url |
| 452 | } |
| 453 | |
| 454 | imageConfig.value.providers[name] = providerData |
| 455 | |
| 456 | closeImageModal() |
| 457 | await autoSaveConfig() |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * 删除图片服务商 |
nothing calls this directly
no test coverage detected