File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ describe("workspace file previews", () => {
3030 expect ( isWorkspacePreviewEntryPath ( `${ name } ?download=1` ) ) . toBe ( false ) ;
3131 expect ( hostPreviewMimeTypeFromExtension ( `.${ extension } ` ) ) . toBe ( mimeType ) ;
3232 } ) ;
33+ it ( "previews a TypeScript file the OS labels as MPEG transport stream as text" , ( ) => {
34+ expect ( filePreviewKind ( { name : "clamp.ts" , mimeType : "video/mp2t" } ) ) . toBe ( "text" ) ;
35+ } ) ;
3336 it ( "recognizes compound archives and MIME aliases" , ( ) => {
3437 expect ( filePreviewKind ( { name : "archive.tar.gz" } ) ) . toBe ( "archive" ) ;
3538 expect ( filePreviewKind ( { name : "download" , mimeType : "application/x-gzip" } ) ) . toBe ( "archive" ) ;
Original file line number Diff line number Diff line change 99 mediaKindFromPath ,
1010 mediaMimeTypeFromExtension ,
1111} from "./mediaPreview.ts" ;
12+ import { GENERIC_MIME_TYPES } from "./image.ts" ;
1213import { videoMimeType } from "./video.ts" ;
1314
1415export type FilePreviewKind =
@@ -41,7 +42,7 @@ export function filePreviewKind(
4142 const mime = file . mimeType ?. split ( ";" , 1 ) [ 0 ] ?. trim ( ) . toLowerCase ( ) ?? "" ;
4243 const name = file . name . toLowerCase ( ) ;
4344 const extension = name . slice ( name . lastIndexOf ( "." ) ) ;
44- const generic = ! mime || mime === "application/octet-stream" || mime === "text/plain" ;
45+ const generic = ! mime || GENERIC_MIME_TYPES . has ( mime ) || mime === "text/plain" ;
4546 const richDocuments = options ?. richDocuments !== false ;
4647 const office = richDocuments ? officePreviewKind ( file ) : null ;
4748 if ( office ) return office ;
@@ -61,7 +62,7 @@ export function filePreviewKind(
6162 )
6263 return "font" ;
6364 if ( mime . startsWith ( "image/" ) ) return "image" ;
64- if ( mime . startsWith ( "video/" ) ) return "video" ;
65+ if ( mime . startsWith ( "video/" ) && ! generic ) return "video" ;
6566 if ( mime . startsWith ( "audio/" ) ) return "audio" ;
6667 if ( generic ) {
6768 if ( extension === ".pdf" ) return "pdf" ;
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ export const GENERIC_MIME_TYPES = new Set([
1313 "application/octet-stream" ,
1414 "binary/octet-stream" ,
1515 "application/unknown" ,
16+ // macOS and Windows label TypeScript `.ts` files as MPEG transport streams, which browsers can't play.
17+ "video/mp2t" ,
18+ "video/vnd.dlna.mpeg-tts" ,
1619] ) ;
1720
1821export function isSvgAttachment ( attachment : {
Original file line number Diff line number Diff line change @@ -14,4 +14,9 @@ describe("videoMimeType", () => {
1414 "video/webm" ,
1515 ) ;
1616 } ) ;
17+
18+ it ( "does not treat a TypeScript file the OS labels as MPEG transport stream as video" , ( ) => {
19+ expect ( videoMimeType ( { name : "clamp.ts" , mimeType : "video/mp2t" } ) ) . toBeNull ( ) ;
20+ expect ( videoMimeType ( { name : "clamp.ts" , mimeType : "video/vnd.dlna.mpeg-tts" } ) ) . toBeNull ( ) ;
21+ } ) ;
1722} ) ;
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ export function videoMimeType(attachment: {
1717 readonly mimeType : string ;
1818} ) : string | null {
1919 const mimeType = attachment . mimeType . split ( ";" , 1 ) [ 0 ] ?. trim ( ) . toLowerCase ( ) ?? "" ;
20- if ( mimeType . startsWith ( "video/" ) ) return mimeType ;
20+ if ( mimeType . startsWith ( "video/" ) && ! GENERIC_MIME_TYPES . has ( mimeType ) ) return mimeType ;
2121 if ( mimeType !== "" && ! GENERIC_MIME_TYPES . has ( mimeType ) ) return null ;
2222 const dotIndex = attachment . name . lastIndexOf ( "." ) ;
2323 return dotIndex < 0
You can’t perform that action at this time.
0 commit comments