Skip to content

Commit 4b65d93

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-27622
2 parents b44557c + 616c426 commit 4b65d93

5 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎packages/shared/src/filePreview.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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");

‎packages/shared/src/filePreview.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export {
99
mediaKindFromPath,
1010
mediaMimeTypeFromExtension,
1111
} from "./mediaPreview.ts";
12+
import { GENERIC_MIME_TYPES } from "./image.ts";
1213
import { videoMimeType } from "./video.ts";
1314

1415
export 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";

‎packages/shared/src/image.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

1821
export function isSvgAttachment(attachment: {

‎packages/shared/src/video.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

‎packages/shared/src/video.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)