@wordpress/media-utils
Version:
WordPress Media Upload Utils.
34 lines (33 loc) • 846 B
JavaScript
// packages/media-utils/src/utils/validate-file-size.ts
import { __, sprintf } from "@wordpress/i18n";
import { UploadError } from "./upload-error.mjs";
function validateFileSize(file, maxUploadFileSize) {
if (file.size <= 0) {
throw new UploadError({
code: "EMPTY_FILE",
message: sprintf(
// translators: %s: file name.
__("%s: This file is empty."),
file.name
),
file
});
}
if (maxUploadFileSize && file.size > maxUploadFileSize) {
throw new UploadError({
code: "SIZE_ABOVE_LIMIT",
message: sprintf(
// translators: %s: file name.
__(
"%s: This file exceeds the maximum upload size for this site."
),
file.name
),
file
});
}
}
export {
validateFileSize
};
//# sourceMappingURL=validate-file-size.mjs.map