(nextDraft: AppSettings)
| 540 | } |
| 541 | |
| 542 | const commitSettings = (nextDraft: AppSettings) => { |
| 543 | const normalizedProfiles = nextDraft.profiles.map((profile) => { |
| 544 | const nextApiProxy = isProfileApiProxyEligible(nextDraft, profile) && apiProxyAvailable ? (apiProxyLocked || profile.apiProxy) : false |
| 545 | const shouldKeepEmptyBaseUrl = profile.provider !== 'fal' && nextApiProxy && !profile.baseUrl.trim() |
| 546 | const normalizedBaseUrl = profile.provider === 'fal' |
| 547 | ? profile.baseUrl.trim().replace(/\/+$/, '') || DEFAULT_FAL_BASE_URL |
| 548 | : shouldKeepEmptyBaseUrl ? '' : normalizeBaseUrl(profile.baseUrl.trim() || DEFAULT_SETTINGS.baseUrl) |
| 549 | const defaultModel = profile.provider === 'fal' ? DEFAULT_FAL_MODEL : getDefaultModelForMode(profile.apiMode) |
| 550 | return { |
| 551 | ...profile, |
| 552 | name: profile.name.trim() || (profile.id === DEFAULT_OPENAI_PROFILE_ID ? '默认' : '新配置'), |
| 553 | baseUrl: normalizedBaseUrl, |
| 554 | model: profile.model.trim() || defaultModel, |
| 555 | timeout: Number(profile.timeout) || DEFAULT_SETTINGS.timeout, |
| 556 | apiProxy: nextApiProxy, |
| 557 | codexCli: profile.provider === 'openai' ? profile.codexCli : false, |
| 558 | streamImages: profile.provider === 'openai' ? profile.streamImages : false, |
| 559 | streamPartialImages: profile.provider === 'openai' ? normalizeStreamPartialImages(profile.streamPartialImages) : DEFAULT_STREAM_PARTIAL_IMAGES, |
| 560 | } |
| 561 | }) |
| 562 | const fallbackProfile = createDefaultOpenAIProfile({ id: newId('openai') }) |
| 563 | const normalizedDraft = normalizeSettings({ |
| 564 | ...nextDraft, |
| 565 | profiles: normalizedProfiles.length ? normalizedProfiles : [fallbackProfile], |
| 566 | activeProfileId: normalizedProfiles.some((profile) => profile.id === nextDraft.activeProfileId) |
| 567 | ? nextDraft.activeProfileId |
| 568 | : (normalizedProfiles[0]?.id ?? fallbackProfile.id), |
| 569 | }) |
| 570 | setDraft(normalizedDraft) |
| 571 | setSettings(normalizedDraft) |
| 572 | } |
| 573 | |
| 574 | const setZipDownloadRouteEnabled = (route: ZipDownloadRoute, enabled: boolean) => { |
| 575 | const nextRoutes = enabled |
no test coverage detected