diff --git a/backend/src/utils/discovery-cache.ts b/backend/src/utils/discovery-cache.ts index ecf47bfd..6391cbd9 100644 --- a/backend/src/utils/discovery-cache.ts +++ b/backend/src/utils/discovery-cache.ts @@ -15,6 +15,7 @@ export function normalizeToBaseUrl(endpoint: string): string { .replace(/\/v1\/audio\/transcriptions$/, '') .replace(/\/audio\/transcriptions$/, '') .replace(/\/$/, '') + .replace(/\/v1$/, '') } async function ensureDiscoveryCacheDir(): Promise { diff --git a/backend/test/utils/discovery-cache.test.ts b/backend/test/utils/discovery-cache.test.ts new file mode 100644 index 00000000..c0fd8b7b --- /dev/null +++ b/backend/test/utils/discovery-cache.test.ts @@ -0,0 +1,16 @@ +import { describe, expect, it } from 'vitest' +import { normalizeToBaseUrl } from '../../src/utils/discovery-cache' + +describe('normalizeToBaseUrl', () => { + it.each([ + ['http://host:9000', 'http://host:9000'], + ['http://host:9000/', 'http://host:9000'], + ['http://host:9000/v1', 'http://host:9000'], + ['http://host:9000/v1/', 'http://host:9000'], + ['http://host:9000/v1/audio/transcriptions', 'http://host:9000'], + ['http://host:8880/v1/audio/speech', 'http://host:8880'], + ['http://host:8880/audio/speech', 'http://host:8880'], + ])('reduces %s to the server base %s', (endpoint, expected) => { + expect(normalizeToBaseUrl(endpoint)).toBe(expected) + }) +})