@wordpress/upload-media
Version:
Core media upload logic.
127 lines (125 loc) • 5 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/upload-media/src/error-messages.ts
var error_messages_exports = {};
__export(error_messages_exports, {
getErrorMessage: () => getErrorMessage
});
module.exports = __toCommonJS(error_messages_exports);
var import_i18n = require("@wordpress/i18n");
var import_upload_error = require("./upload-error.cjs");
function getErrorMessage(code, fileName) {
const messages = {
[import_upload_error.ErrorCode.EMPTY_FILE]: {
title: (0, import_i18n.__)("Empty file"),
description: (0, import_i18n.sprintf)(
/* translators: %s: file name */
(0, import_i18n.__)('"%s" is empty.'),
fileName
),
action: (0, import_i18n.__)("Please choose a different file.")
},
[import_upload_error.ErrorCode.SIZE_ABOVE_LIMIT]: {
title: (0, import_i18n.__)("File too large"),
description: (0, import_i18n.sprintf)(
/* translators: %s: file name */
(0, import_i18n.__)('"%s" exceeds the maximum upload size.'),
fileName
),
action: (0, import_i18n.__)("Please reduce the file size and try again.")
},
[import_upload_error.ErrorCode.MIME_TYPE_NOT_SUPPORTED]: {
title: (0, import_i18n.__)("Unsupported file type"),
description: (0, import_i18n.sprintf)(
/* translators: %s: file name */
(0, import_i18n.__)('"%s" is not a supported file type.'),
fileName
),
action: (0, import_i18n.__)("Please upload a different file format.")
},
[import_upload_error.ErrorCode.MIME_TYPE_NOT_ALLOWED_FOR_USER]: {
title: (0, import_i18n.__)("File type not allowed"),
description: (0, import_i18n.sprintf)(
/* translators: %s: file name */
(0, import_i18n.__)('You are not allowed to upload "%s".'),
fileName
),
action: (0, import_i18n.__)("Please contact your site administrator.")
},
[import_upload_error.ErrorCode.HEIC_DECODE_ERROR]: {
title: (0, import_i18n.__)("HEIC decode failed"),
description: (0, import_i18n.sprintf)(
/* translators: %s: file name */
(0, import_i18n.__)('Failed to decode HEIC file "%s".'),
fileName
),
action: (0, import_i18n.__)("Try converting the image to JPEG or PNG first.")
},
[import_upload_error.ErrorCode.IMAGE_TRANSCODING_ERROR]: {
title: (0, import_i18n.__)("Image processing failed"),
description: (0, import_i18n.sprintf)(
/* translators: %s: file name */
(0, import_i18n.__)('Failed to process "%s".'),
fileName
),
action: (0, import_i18n.__)("The image may be corrupted. Try a different file.")
},
[import_upload_error.ErrorCode.IMAGE_ROTATION_ERROR]: {
title: (0, import_i18n.__)("Image rotation failed"),
description: (0, import_i18n.sprintf)(
/* translators: %s: file name */
(0, import_i18n.__)('Failed to rotate "%s".'),
fileName
),
action: (0, import_i18n.__)("The image may be corrupted. Try a different file.")
},
[import_upload_error.ErrorCode.MEDIA_TRANSCODING_ERROR]: {
title: (0, import_i18n.__)("Media processing failed"),
description: (0, import_i18n.sprintf)(
/* translators: %s: file name */
(0, import_i18n.__)('Failed to convert "%s" to the target format.'),
fileName
),
action: (0, import_i18n.__)("The file may be corrupted. Try a different file.")
},
[import_upload_error.ErrorCode.GENERAL]: {
title: (0, import_i18n.__)("Upload failed"),
description: (0, import_i18n.sprintf)(
/* translators: %s: file name */
(0, import_i18n.__)('Failed to upload "%s".'),
fileName
),
action: (0, import_i18n.__)("Please try again.")
}
};
return messages[code] || {
title: (0, import_i18n.__)("Upload failed"),
description: (0, import_i18n.sprintf)(
/* translators: %s: file name */
(0, import_i18n.__)('Failed to upload "%s".'),
fileName
),
action: (0, import_i18n.__)("Please try again.")
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getErrorMessage
});
//# sourceMappingURL=error-messages.cjs.map