Skip to content

Commit 45e8671

Browse files
committed
chore(resources): delete the code this branch left with no callers
Three zero-reference exports, found by walking every export in the modules the merge touched and counting non-test references. - `resolveMediaMimeType` + `MEDIA_FALLBACK_MIME` (`lib/uploads/utils/file-utils`). Staging added them in #6341 for `MediaPreview`'s blob path; this branch rewrote that preview to stream from the serve route, so the merge orphaned them. Their tests go too, and the `DUAL_CONTAINER_MIME` doc stops pointing at a function that no longer exists. Worth recording, since deleting the helper deletes the fix: it retagged a dual-container `.webm` to the element the viewer had already chosen. The serve route now declares the type instead, and derives it from the filename, where `webm` maps to `video/webm` — so an audio-only `.webm` reaches an `<audio>` element labelled `video/webm`. Browsers sniff `src=` responses rather than trusting the header, so this is inert in practice, but it is a real narrowing and the public-share route (which uses the stored `file.contentType`) does not share it. - `tableWorkspaceId` (`resources/table-source.ts`, the whole file). Added by this branch's own first commit and never called — `cell-render` takes the workspace id as a plain argument. Its TSDoc claimed to be "the value that decides whether a cell may render a sim-resource chip", which nothing enforced. The table migration will want this helper; it can arrive with a caller and an accurate docstring. - `isMediaFileType` (`lib/uploads/utils/file-utils`). Not ours — dead since #2068, zero references including tests. Removed while the file was open.
1 parent 285e035 commit 45e8671

3 files changed

Lines changed: 1 addition & 84 deletions

File tree

apps/sim/lib/uploads/utils/file-utils.test.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
processSingleFileToUserFile,
1515
resolveEffectiveMimeType,
1616
resolveFileType,
17-
resolveMediaMimeType,
1817
resolveTrustedFileContext,
1918
} from '@/lib/uploads/utils/file-utils'
2019

@@ -255,28 +254,3 @@ describe('resolveEffectiveMimeType', () => {
255254
})
256255
})
257256

258-
describe('resolveMediaMimeType', () => {
259-
it('resolves a generic stored type from the extension', () => {
260-
expect(resolveMediaMimeType('application/octet-stream', 'clip.mp4', 'video')).toBe('video/mp4')
261-
expect(resolveMediaMimeType('application/octet-stream', 'song.flac', 'audio')).toBe(
262-
'audio/flac'
263-
)
264-
})
265-
266-
it('retags a dual audio/video container to the kind being rendered', () => {
267-
expect(resolveMediaMimeType(null, 'clip.webm', 'video')).toBe('video/webm')
268-
expect(resolveMediaMimeType('audio/webm', 'clip.webm', 'video')).toBe('video/webm')
269-
expect(resolveMediaMimeType(null, 'recording.webm', 'audio')).toBe('audio/webm')
270-
expect(resolveMediaMimeType('video/webm', 'recording.webm', 'audio')).toBe('audio/webm')
271-
})
272-
273-
it('keeps a specific type that already names the right kind', () => {
274-
expect(resolveMediaMimeType('video/quicktime', 'clip.mov', 'video')).toBe('video/quicktime')
275-
expect(resolveMediaMimeType('audio/opus', 'voice.opus', 'audio')).toBe('audio/opus')
276-
})
277-
278-
it('falls back to the kind default when nothing names a media format', () => {
279-
expect(resolveMediaMimeType('application/zip', 'weird.bin', 'audio')).toBe('audio/mpeg')
280-
expect(resolveMediaMimeType(null, 'weird.bin', 'video')).toBe('video/mp4')
281-
})
282-
})

apps/sim/lib/uploads/utils/file-utils.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,6 @@ export function isVideoFileType(mimeType: string): boolean {
133133
return getContentType(mimeType) === 'video'
134134
}
135135

136-
/**
137-
* Check if a MIME type is an audio or video type
138-
*/
139-
export function isMediaFileType(mimeType: string): boolean {
140-
const contentType = getContentType(mimeType)
141-
return contentType === 'audio' || contentType === 'video'
142-
}
143-
144136
/**
145137
* Convert a file buffer to base64
146138
*/
@@ -390,8 +382,7 @@ const GENERIC_MIME_TYPE = 'application/octet-stream'
390382
*
391383
* Deliberately not folded into {@link EXTENSION_TO_MIME}: the speech-to-text and ElevenLabs
392384
* routes read that table directly to label an upload, and a `video/*` label there sends a
393-
* `.webm` down an ffmpeg extraction path it does not need. Callers that know which element
394-
* they are rendering retag from here — see {@link resolveMediaMimeType}.
385+
* `.webm` down an ffmpeg extraction path it does not need.
395386
*/
396387
const DUAL_CONTAINER_MIME: Record<string, string> = { webm: 'video/webm' }
397388

@@ -432,32 +423,6 @@ export function resolveEffectiveMimeType(
432423
return DUAL_CONTAINER_MIME[extension] ?? getMimeTypeFromExtension(extension)
433424
}
434425

435-
const MEDIA_FALLBACK_MIME = { audio: 'audio/mpeg', video: 'video/mp4' } as const
436-
437-
/**
438-
* The MIME type to hand an `<audio>`/`<video>` element, given which of the two the caller
439-
* is rendering.
440-
*
441-
* Beyond {@link resolveEffectiveMimeType} this settles an ambiguity a filename alone cannot:
442-
* `.webm` and `.ogg` are both audio and video containers, so a resolved `audio/webm` would
443-
* make a `<video>` element drop the picture. The caller has already chosen the element, so
444-
* the container subtype is kept and retagged to that kind — the choice belongs here, where
445-
* the kind is known, and not in the extension table, which several non-viewer callers share.
446-
*
447-
* A type naming no media format falls back to the kind's default: passed through, it would
448-
* leave the element unable to determine the format, rendering nothing.
449-
*/
450-
export function resolveMediaMimeType(
451-
declaredType: string | null | undefined,
452-
filename: string,
453-
kind: 'audio' | 'video'
454-
): string {
455-
const resolved = resolveEffectiveMimeType(declaredType, filename)
456-
const [type, subtype] = resolved.split('/')
457-
if (type === kind) return resolved
458-
if (type === 'audio' || type === 'video') return `${kind}/${subtype}`
459-
return MEDIA_FALLBACK_MIME[kind]
460-
}
461426

462427
/**
463428
* Resolve a reliable MIME type from a file, falling back to the extension map

apps/sim/resources/table-source.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)