mirror of
https://github.com/outline/outline.git
synced 2026-12-04 02:20:17 +03:00
fix: Keep extensions in toDropzoneAccept when there are no mime types (#14502)
This commit is contained in:
1 parent
2c3bff81e1
commit
3cdf0c0979
2 files changed
+22
-1
No files matched your search
@@ -20,4 +20,17 @@ describe("#toDropzoneAccept", () => {
|
||||
"image/heif": [],
|
||||
});
|
||||
});
|
||||
|
||||
it("should keep extensions when there are no mime types", () => {
|
||||
const accept = toDropzoneAccept([".png", ".jpg"]);
|
||||
const entries = Object.entries(accept);
|
||||
|
||||
expect(entries).toHaveLength(1);
|
||||
expect(entries[0][0]).toMatch(/^application\/x-/);
|
||||
expect(entries[0][1]).toEqual([".png", ".jpg"]);
|
||||
});
|
||||
|
||||
it("should return an empty map when there are no types", () => {
|
||||
expect(toDropzoneAccept([])).toEqual({});
|
||||
});
|
||||
});
|
||||
+9
-1
@@ -146,7 +146,8 @@ export { dataUrlToBlob };
|
||||
/**
|
||||
* Converts a list of mime types and file extensions to the accept map used by
|
||||
* react-dropzone. The map is flattened into a single accept attribute, so the
|
||||
* extensions are grouped under the first mime type.
|
||||
* extensions are grouped under the first mime type, or a placeholder if there
|
||||
* is none.
|
||||
*
|
||||
* @param types the mime types and file extensions, such as "image/png" or ".png".
|
||||
* @returns the accept map.
|
||||
@@ -155,6 +156,10 @@ export const toDropzoneAccept = (types: readonly string[]): Accept => {
|
||||
const mimeTypes = types.filter((type) => !type.startsWith("."));
|
||||
const extensions = types.filter((type) => type.startsWith("."));
|
||||
|
||||
if (mimeTypes.length === 0 && extensions.length > 0) {
|
||||
return { [extensionOnlyMimeType]: extensions };
|
||||
}
|
||||
|
||||
return Object.fromEntries(
|
||||
mimeTypes.map((mimeType, index) => [
|
||||
mimeType,
|
||||
@@ -163,6 +168,9 @@ export const toDropzoneAccept = (types: readonly string[]): Accept => {
|
||||
);
|
||||
};
|
||||
|
||||
/** A key for extensions with no mime type, no file reports this type. */
|
||||
const extensionOnlyMimeType = "application/x-outline-extension-only";
|
||||
|
||||
/**
|
||||
* Header names the browser controls itself - it silently ignores an attempt to
|
||||
* set one and logs an error to the console.
|
||||
|
||||
Reference in new issue
Block a user