@wordpress/upload-media
Version:
Core media upload logic.
34 lines (33 loc) • 868 B
JavaScript
// packages/upload-media/src/validate-file-size.ts
import { __, sprintf } from "@wordpress/i18n";
import { ErrorCode, UploadError } from "./upload-error.mjs";
function validateFileSize(file, maxUploadFileSize) {
if (file.size <= 0) {
throw new UploadError({
code: ErrorCode.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: ErrorCode.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