MCPcopy Create free account
hub / github.com/TanStack/ai / deriveAudioContentType

Function deriveAudioContentType

packages/ai-fal/src/utils/client.ts:73–102  ·  view source on GitHub ↗
(
  explicitContentType: string | undefined,
  url: string,
)

Source from the content-addressed store, hash-verified

71 * otherwise falls back to audio/mpeg — fal URLs virtually always serve mp3.
72 */
73export function deriveAudioContentType(
74 explicitContentType: string | undefined,
75 url: string,
76): string {
77 const stripped = explicitContentType?.split(';')[0]?.trim()
78 if (stripped) return stripped
79
80 const ext = extractUrlExtension(url)?.toLowerCase()
81 switch (ext) {
82 case 'mp3':
83 return 'audio/mpeg'
84 case 'wav':
85 return 'audio/wav'
86 case 'ogg':
87 case 'oga':
88 return 'audio/ogg'
89 case 'flac':
90 return 'audio/flac'
91 case 'aac':
92 return 'audio/aac'
93 case 'm4a':
94 case 'mp4':
95 return 'audio/mp4'
96 case 'webm':
97 return 'audio/webm'
98 case undefined:
99 default:
100 return 'audio/mpeg'
101 }
102}
103
104/**
105 * Decode a `data:` URL into a Blob so fal-client can auto-upload it via

Callers 2

transformResponseMethod · 0.90
utils.test.tsFile · 0.90

Calls 1

extractUrlExtensionFunction · 0.85

Tested by

no test coverage detected