@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
61 lines (60 loc) • 1.59 kB
JavaScript
import { z as e } from "zod";
import { buildCommonSchema as m } from "../validation.js";
const p = {
B: Math.pow(1024, 0),
KB: Math.pow(1024, 1),
MB: Math.pow(1024, 2),
GB: Math.pow(1024, 3)
}, r = (o) => {
const t = /^(\d+)\s*(B|KB|MB|GB)?$/i.exec(o);
if (t === null)
return null;
const i = parseInt(t[1], 10), s = (t[2] || "B").toUpperCase();
return i * p[s];
}, l = e.number().int().positive(), u = e.object({
image: e.object({
resize: e.object({
apply: e.boolean().optional(),
width: l.optional(),
height: l.optional()
}).optional()
}).optional()
}), f = (o, t) => {
const {
serverUploadLimit: i
} = t, s = r(i) ?? Number.MAX_SAFE_INTEGER;
return e.string().transform((n, c) => {
const a = r(n);
return a === null ? (c.addIssue({
code: e.ZodIssueCode.custom,
message: o.formatMessage({
id: "QW32Dd",
defaultMessage: [{
type: 0,
value: "Specify a positive, non-zero file size without decimals, e.g. 10MB."
}]
})
}), e.NEVER) : a;
}).refine((n) => n <= s, {
message: o.formatMessage({
id: "5/jkH9",
defaultMessage: [{
type: 0,
value: "Specify a file size less than or equal to the server upload limit."
}]
})
});
}, d = (o, t) => e.object({
of: u.optional(),
maxNumberOfFiles: e.union([e.null(), e.number().int().positive().optional()]),
fileMaxSize: f(o, t).optional()
}), S = ({
intl: o,
builderContext: t
}) => {
const i = m(o), s = d(o, t);
return i.and(s);
};
export {
S as default
};