mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-14 20:12:39 +08:00
fix(ccswitch): preserve Codex provider root endpoint
This commit is contained in:
@@ -27,28 +27,12 @@ describe('ccswitchImport utils', () => {
|
||||
usageScript: 'return true'
|
||||
}
|
||||
|
||||
it('adds the Codex model parameter for OpenAI imports', () => {
|
||||
const params = paramsFromDeeplink(
|
||||
buildCcSwitchImportDeeplink({
|
||||
...baseInput,
|
||||
platform: 'openai',
|
||||
clientType: 'claude'
|
||||
})
|
||||
)
|
||||
|
||||
expect(params.get('resource')).toBe('provider')
|
||||
expect(params.get('app')).toBe('codex')
|
||||
expect(params.get('endpoint')).toBe(`${baseInput.baseUrl}/v1`)
|
||||
expect(params.get('model')).toBe(OPENAI_CC_SWITCH_CODEX_MODEL)
|
||||
expect(atob(params.get('usageScript') || '')).toBe(baseInput.usageScript)
|
||||
})
|
||||
|
||||
it.each([
|
||||
'https://api.example.com',
|
||||
'https://api.example.com/',
|
||||
'https://api.example.com/v1',
|
||||
'https://api.example.com/v1/'
|
||||
])('imports Codex with exactly one /v1 suffix for base URL %s', (baseUrl) => {
|
||||
['https://api.example.com', 'https://api.example.com'],
|
||||
['https://api.example.com/', 'https://api.example.com'],
|
||||
['https://api.example.com/v1', 'https://api.example.com/v1'],
|
||||
['https://api.example.com/v1/', 'https://api.example.com/v1']
|
||||
])('keeps Codex imports on the configured endpoint for base URL %s', (baseUrl, endpoint) => {
|
||||
const params = paramsFromDeeplink(
|
||||
buildCcSwitchImportDeeplink({
|
||||
...baseInput,
|
||||
@@ -58,7 +42,11 @@ describe('ccswitchImport utils', () => {
|
||||
})
|
||||
)
|
||||
|
||||
expect(params.get('endpoint')).toBe('https://api.example.com/v1')
|
||||
expect(params.get('resource')).toBe('provider')
|
||||
expect(params.get('app')).toBe('codex')
|
||||
expect(params.get('endpoint')).toBe(endpoint)
|
||||
expect(params.get('model')).toBe(OPENAI_CC_SWITCH_CODEX_MODEL)
|
||||
expect(atob(params.get('usageScript') || '')).toBe(baseInput.usageScript)
|
||||
})
|
||||
|
||||
it.each([
|
||||
|
||||
@@ -25,6 +25,10 @@ function withV1Endpoint(baseUrl: string): string {
|
||||
return normalizedBaseUrl.endsWith('/v1') ? normalizedBaseUrl : `${normalizedBaseUrl}/v1`
|
||||
}
|
||||
|
||||
function withoutTrailingSlashes(baseUrl: string): string {
|
||||
return baseUrl.replace(/\/+$/, '')
|
||||
}
|
||||
|
||||
export function resolveCcSwitchImportConfig(
|
||||
platform: GroupPlatform | undefined | null,
|
||||
clientType: CcSwitchClientType,
|
||||
@@ -39,7 +43,9 @@ export function resolveCcSwitchImportConfig(
|
||||
case 'openai':
|
||||
return {
|
||||
app: 'codex',
|
||||
endpoint: withV1Endpoint(baseUrl),
|
||||
// CC Switch's Codex provider appends the OpenAI-compatible path itself.
|
||||
// Passing /v1 here can make the client request /v1/v1/....
|
||||
endpoint: withoutTrailingSlashes(baseUrl),
|
||||
model: OPENAI_CC_SWITCH_CODEX_MODEL
|
||||
}
|
||||
case 'gemini':
|
||||
|
||||
Reference in New Issue
Block a user