-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
Copy pathfn.js
35 lines (28 loc) · 907 Bytes
/
fn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* @prettier
*/
import { Map } from "immutable"
import isPlainObject from "lodash/isPlainObject"
export const makeIsFileUploadIntended = (getSystem) => {
const isFileUploadIntended = (schema, mediaType = null) => {
const { getConfigs, fn } = getSystem()
const { fileUploadMediaTypes } = getConfigs()
const isFileUploadMediaType =
typeof mediaType === "string" &&
fileUploadMediaTypes.some((fileUploadMediaType) =>
mediaType.startsWith(fileUploadMediaType)
)
if (isFileUploadMediaType) {
return true
}
const isSchemaImmutable = Map.isMap(schema)
if (!isSchemaImmutable && !isPlainObject(schema)) {
return false
}
const format = isSchemaImmutable ? schema.get("format") : schema.format
return (
fn.hasSchemaType(schema, "string") && ["binary", "byte"].includes(format)
)
}
return isFileUploadIntended
}