Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/shared/src/filePreview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ describe("workspace file previews", () => {
["db", "sqlite", "application/vnd.sqlite3"],
])("recognizes binary preview %s", (extension, kind, mimeType) => {
const name = `files#draft/sample.${extension.toUpperCase()}`;
expect(filePreviewKind({ name, mimeType: "application/octet-stream" })).toBe(kind);
for (const genericMime of [
"",
"application/octet-stream",
"binary/octet-stream",
"application/unknown",
" APPLICATION/UNKNOWN ; charset=utf-8",
"text/plain",
]) {
expect(filePreviewKind({ name, mimeType: genericMime })).toBe(kind);
}
expect(filePreviewKind({ name: "download", mimeType })).toBe(kind);
expect(isWorkspacePreviewEntryPath(name)).toBe(true);
expect(isWorkspacePreviewEntryPath(`${name}?download=1`)).toBe(false);
Expand Down Expand Up @@ -79,7 +88,16 @@ describe("workspace file previews", () => {
["analysis.ipynb", "ipynb", "application/x-ipynb+json"],
])("recognizes Office assets at literal path %s", (name, kind, mimeType) => {
expect(officePreviewKind({ name })).toBe(kind);
expect(filePreviewKind({ name, mimeType: "application/octet-stream" })).toBe(kind);
for (const genericMime of [
"",
"application/octet-stream",
"binary/octet-stream",
"application/unknown",
" APPLICATION/UNKNOWN ; charset=utf-8",
"text/plain",
]) {
expect(filePreviewKind({ name, mimeType: genericMime })).toBe(kind);
}
expect(isWorkspacePreviewEntryPath(name)).toBe(true);
expect(hostPreviewMimeTypeFromExtension(`.${kind}`)).toBe(mimeType);
expect(filePreviewKind({ name: "download", mimeType })).toBe(kind);
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/filePreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function binaryPreviewKind(file: {
].includes(mime)
)
return "archive";
if (mime && mime !== "application/octet-stream" && mime !== "text/plain") return null;
if (mime && !GENERIC_MIME_TYPES.has(mime) && mime !== "text/plain") return null;
const extension = file.name.slice(file.name.lastIndexOf(".")).toLowerCase();
const inferred = BINARY_MIME_TYPES.get(extension);
return inferred === "application/vnd.sqlite3" ? "sqlite" : inferred ? "archive" : null;
Expand Down Expand Up @@ -158,7 +158,7 @@ export function officePreviewKind(file: {
if (mime === OFFICE_MIME_TYPES[kind]) return kind;
if (
(!mime ||
mime === "application/octet-stream" ||
GENERIC_MIME_TYPES.has(mime) ||
mime === "text/plain" ||
(kind === "ipynb" && mime === "application/json")) &&
file.name.toLowerCase().endsWith(`.${kind}`)
Expand Down
Loading