@wordpress/media-utils 5.32.0 → 5.32.1-next.47f435fc9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/index.js +36 -11
- package/build/components/index.js.map +7 -1
- package/build/components/media-upload/index.js +156 -221
- package/build/components/media-upload/index.js.map +7 -1
- package/build/index.js +44 -65
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/private-apis.js +31 -17
- package/build/private-apis.js.map +7 -1
- package/build/utils/flatten-form-data.js +28 -20
- package/build/utils/flatten-form-data.js.map +7 -1
- package/build/utils/get-mime-types-array.js +38 -20
- package/build/utils/get-mime-types-array.js.map +7 -1
- package/build/utils/sideload-media.js +50 -38
- package/build/utils/sideload-media.js.map +7 -1
- package/build/utils/sideload-to-server.js +53 -36
- package/build/utils/sideload-to-server.js.map +7 -1
- package/build/utils/transform-attachment.js +29 -23
- package/build/utils/transform-attachment.js.map +7 -1
- package/build/utils/types.js +16 -5
- package/build/utils/types.js.map +7 -1
- package/build/utils/upload-error.js +30 -21
- package/build/utils/upload-error.js.map +7 -1
- package/build/utils/upload-media.js +62 -71
- package/build/utils/upload-media.js.map +7 -1
- package/build/utils/upload-to-server.js +54 -27
- package/build/utils/upload-to-server.js.map +7 -1
- package/build/utils/validate-file-size.js +44 -32
- package/build/utils/validate-file-size.js.map +7 -1
- package/build/utils/validate-mime-type-for-user.js +42 -30
- package/build/utils/validate-mime-type-for-user.js.map +7 -1
- package/build/utils/validate-mime-type.js +37 -32
- package/build/utils/validate-mime-type.js.map +7 -1
- package/build-module/components/index.js +5 -2
- package/build-module/components/index.js.map +7 -1
- package/build-module/components/media-upload/index.js +137 -215
- package/build-module/components/media-upload/index.js.map +7 -1
- package/build-module/index.js +16 -8
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/private-apis.js +7 -11
- package/build-module/private-apis.js.map +7 -1
- package/build-module/utils/flatten-form-data.js +7 -17
- package/build-module/utils/flatten-form-data.js.map +7 -1
- package/build-module/utils/get-mime-types-array.js +17 -17
- package/build-module/utils/get-mime-types-array.js.map +7 -1
- package/build-module/utils/sideload-media.js +28 -34
- package/build-module/utils/sideload-media.js.map +7 -1
- package/build-module/utils/sideload-to-server.js +22 -33
- package/build-module/utils/sideload-to-server.js.map +7 -1
- package/build-module/utils/transform-attachment.js +8 -20
- package/build-module/utils/transform-attachment.js.map +7 -1
- package/build-module/utils/types.js +1 -2
- package/build-module/utils/types.js.map +7 -1
- package/build-module/utils/upload-error.js +9 -17
- package/build-module/utils/upload-error.js.map +7 -1
- package/build-module/utils/upload-media.js +36 -63
- package/build-module/utils/upload-media.js.map +7 -1
- package/build-module/utils/upload-to-server.js +23 -22
- package/build-module/utils/upload-to-server.js.map +7 -1
- package/build-module/utils/validate-file-size.js +19 -25
- package/build-module/utils/validate-file-size.js.map +7 -1
- package/build-module/utils/validate-mime-type-for-user.js +18 -24
- package/build-module/utils/validate-mime-type-for-user.js.map +7 -1
- package/build-module/utils/validate-mime-type.js +14 -27
- package/build-module/utils/validate-mime-type.js.map +7 -1
- package/package.json +15 -8
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/upload-media.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { createBlobURL, revokeBlobURL } from '@wordpress/blob';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tAdditionalData,\n\tAttachment,\n\tOnChangeHandler,\n\tOnErrorHandler,\n} from './types';\nimport { uploadToServer } from './upload-to-server';\nimport { validateMimeType } from './validate-mime-type';\nimport { validateMimeTypeForUser } from './validate-mime-type-for-user';\nimport { validateFileSize } from './validate-file-size';\nimport { UploadError } from './upload-error';\n\ndeclare global {\n\tinterface Window {\n\t\t__experimentalMediaProcessing?: boolean;\n\t}\n}\n\ninterface UploadMediaArgs {\n\t// Additional data to include in the request.\n\tadditionalData?: AdditionalData;\n\t// Array with the types of media that can be uploaded, if unset all types are allowed.\n\tallowedTypes?: string[];\n\t// List of files.\n\tfilesList: File[];\n\t// Maximum upload size in bytes allowed for the site.\n\tmaxUploadFileSize?: number;\n\t// Function called when an error happens.\n\tonError?: OnErrorHandler;\n\t// Function called each time a file or a temporary representation of the file is available.\n\tonFileChange?: OnChangeHandler;\n\t// List of allowed mime types and file extensions.\n\twpAllowedMimeTypes?: Record< string, string > | null;\n\t// Abort signal.\n\tsignal?: AbortSignal;\n\t// Whether to allow multiple files to be uploaded.\n\tmultiple?: boolean;\n}\n\n/**\n * Upload a media file when the file upload button is activated\n * or when adding a file to the editor via drag & drop.\n *\n * @param $0 Parameters object passed to the function.\n * @param $0.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.\n * @param $0.additionalData Additional data to include in the request.\n * @param $0.filesList List of files.\n * @param $0.maxUploadFileSize Maximum upload size in bytes allowed for the site.\n * @param $0.onError Function called when an error happens.\n * @param $0.onFileChange Function called each time a file or a temporary representation of the file is available.\n * @param $0.wpAllowedMimeTypes List of allowed mime types and file extensions.\n * @param $0.signal Abort signal.\n * @param $0.multiple Whether to allow multiple files to be uploaded.\n */\nexport function uploadMedia( {\n\twpAllowedMimeTypes,\n\tallowedTypes,\n\tadditionalData = {},\n\tfilesList,\n\tmaxUploadFileSize,\n\tonError,\n\tonFileChange,\n\tsignal,\n\tmultiple = true,\n}: UploadMediaArgs ) {\n\tif ( ! multiple && filesList.length > 1 ) {\n\t\tonError?.( new Error( __( 'Only one file can be used here.' ) ) );\n\t\treturn;\n\t}\n\n\tconst validFiles = [];\n\n\tconst filesSet: Array< Partial< Attachment > | null > = [];\n\tconst setAndUpdateFiles = ( index: number, value: Attachment | null ) => {\n\t\t// For client-side media processing, this is handled by the upload-media package.\n\t\tif ( ! window.__experimentalMediaProcessing ) {\n\t\t\tif ( filesSet[ index ]?.url ) {\n\t\t\t\trevokeBlobURL( filesSet[ index ].url );\n\t\t\t}\n\t\t}\n\t\tfilesSet[ index ] = value;\n\t\tonFileChange?.(\n\t\t\tfilesSet.filter( ( attachment ) => attachment !== null )\n\t\t);\n\t};\n\n\tfor ( const mediaFile of filesList ) {\n\t\t// Verify if user is allowed to upload this mime type.\n\t\t// Defer to the server when type not detected.\n\t\ttry {\n\t\t\tvalidateMimeTypeForUser( mediaFile, wpAllowedMimeTypes );\n\t\t} catch ( error: unknown ) {\n\t\t\tonError?.( error as Error );\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Check if the caller (e.g. a block) supports this mime type.\n\t\t// Defer to the server when type not detected.\n\t\ttry {\n\t\t\tvalidateMimeType( mediaFile, allowedTypes );\n\t\t} catch ( error: unknown ) {\n\t\t\tonError?.( error as Error );\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Verify if file is greater than the maximum file upload size allowed for the site.\n\t\ttry {\n\t\t\tvalidateFileSize( mediaFile, maxUploadFileSize );\n\t\t} catch ( error: unknown ) {\n\t\t\tonError?.( error as Error );\n\t\t\tcontinue;\n\t\t}\n\n\t\tvalidFiles.push( mediaFile );\n\n\t\t// For client-side media processing, this is handled by the upload-media package.\n\t\tif ( ! window.__experimentalMediaProcessing ) {\n\t\t\t// Set temporary URL to create placeholder media file, this is replaced\n\t\t\t// with final file from media gallery when upload is `done` below.\n\t\t\tfilesSet.push( { url: createBlobURL( mediaFile ) } );\n\t\t\tonFileChange?.( filesSet as Array< Partial< Attachment > > );\n\t\t}\n\t}\n\n\tvalidFiles.map( async ( file, index ) => {\n\t\ttry {\n\t\t\tconst attachment = await uploadToServer(\n\t\t\t\tfile,\n\t\t\t\tadditionalData,\n\t\t\t\tsignal\n\t\t\t);\n\t\t\tsetAndUpdateFiles( index, attachment );\n\t\t} catch ( error ) {\n\t\t\t// Reset to empty on failure.\n\t\t\tsetAndUpdateFiles( index, null );\n\n\t\t\t// @wordpress/api-fetch throws any response that isn't in the 200 range as-is.\n\t\t\tlet message: string;\n\t\t\tif (\n\t\t\t\ttypeof error === 'object' &&\n\t\t\t\terror !== null &&\n\t\t\t\t'message' in error\n\t\t\t) {\n\t\t\t\tmessage =\n\t\t\t\t\ttypeof error.message === 'string'\n\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t: String( error.message );\n\t\t\t} else {\n\t\t\t\tmessage = sprintf(\n\t\t\t\t\t// translators: %s: file name\n\t\t\t\t\t__( 'Error while uploading file %s to the media library.' ),\n\t\t\t\t\tfile.name\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tonError?.(\n\t\t\t\tnew UploadError( {\n\t\t\t\t\tcode: 'GENERAL',\n\t\t\t\t\tmessage,\n\t\t\t\t\tfile,\n\t\t\t\t\tcause: error instanceof Error ? error : undefined,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\t} );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAC5B,kBAA6C;AAW7C,8BAA+B;AAC/B,gCAAiC;AACjC,yCAAwC;AACxC,gCAAiC;AACjC,0BAA4B;AA4CrB,SAAS,YAAa;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,iBAAiB,CAAC;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AACZ,GAAqB;AACpB,MAAK,CAAE,YAAY,UAAU,SAAS,GAAI;AACzC,cAAW,IAAI,UAAO,gBAAI,iCAAkC,CAAE,CAAE;AAChE;AAAA,EACD;AAEA,QAAM,aAAa,CAAC;AAEpB,QAAM,WAAkD,CAAC;AACzD,QAAM,oBAAoB,CAAE,OAAe,UAA8B;AAExE,QAAK,CAAE,OAAO,+BAAgC;AAC7C,UAAK,SAAU,KAAM,GAAG,KAAM;AAC7B,uCAAe,SAAU,KAAM,EAAE,GAAI;AAAA,MACtC;AAAA,IACD;AACA,aAAU,KAAM,IAAI;AACpB;AAAA,MACC,SAAS,OAAQ,CAAE,eAAgB,eAAe,IAAK;AAAA,IACxD;AAAA,EACD;AAEA,aAAY,aAAa,WAAY;AAGpC,QAAI;AACH,sEAAyB,WAAW,kBAAmB;AAAA,IACxD,SAAU,OAAiB;AAC1B,gBAAW,KAAe;AAC1B;AAAA,IACD;AAIA,QAAI;AACH,sDAAkB,WAAW,YAAa;AAAA,IAC3C,SAAU,OAAiB;AAC1B,gBAAW,KAAe;AAC1B;AAAA,IACD;AAGA,QAAI;AACH,sDAAkB,WAAW,iBAAkB;AAAA,IAChD,SAAU,OAAiB;AAC1B,gBAAW,KAAe;AAC1B;AAAA,IACD;AAEA,eAAW,KAAM,SAAU;AAG3B,QAAK,CAAE,OAAO,+BAAgC;AAG7C,eAAS,KAAM,EAAE,SAAK,2BAAe,SAAU,EAAE,CAAE;AACnD,qBAAgB,QAA2C;AAAA,IAC5D;AAAA,EACD;AAEA,aAAW,IAAK,OAAQ,MAAM,UAAW;AACxC,QAAI;AACH,YAAM,aAAa,UAAM;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,wBAAmB,OAAO,UAAW;AAAA,IACtC,SAAU,OAAQ;AAEjB,wBAAmB,OAAO,IAAK;AAG/B,UAAI;AACJ,UACC,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,OACZ;AACD,kBACC,OAAO,MAAM,YAAY,WACtB,MAAM,UACN,OAAQ,MAAM,OAAQ;AAAA,MAC3B,OAAO;AACN,sBAAU;AAAA;AAAA,cAET,gBAAI,qDAAsD;AAAA,UAC1D,KAAK;AAAA,QACN;AAAA,MACD;AAEA;AAAA,QACC,IAAI,gCAAa;AAAA,UAChB,MAAM;AAAA,UACN;AAAA,UACA;AAAA,UACA,OAAO,iBAAiB,QAAQ,QAAQ;AAAA,QACzC,CAAE;AAAA,MACH;AAAA,IACD;AAAA,EACD,CAAE;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,34 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var upload_to_server_exports = {};
|
|
30
|
+
__export(upload_to_server_exports, {
|
|
31
|
+
uploadToServer: () => uploadToServer
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
/**
|
|
12
|
-
* WordPress dependencies
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Internal dependencies
|
|
17
|
-
*/
|
|
18
|
-
|
|
33
|
+
module.exports = __toCommonJS(upload_to_server_exports);
|
|
34
|
+
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
35
|
+
var import_flatten_form_data = require("./flatten-form-data");
|
|
36
|
+
var import_transform_attachment = require("./transform-attachment");
|
|
19
37
|
async function uploadToServer(file, additionalData = {}, signal) {
|
|
20
|
-
// Create upload payload.
|
|
21
38
|
const data = new FormData();
|
|
22
|
-
data.append(
|
|
39
|
+
data.append("file", file, file.name || file.type.replace("/", "."));
|
|
23
40
|
for (const [key, value] of Object.entries(additionalData)) {
|
|
24
|
-
(0,
|
|
41
|
+
(0, import_flatten_form_data.flattenFormData)(
|
|
42
|
+
data,
|
|
43
|
+
key,
|
|
44
|
+
value
|
|
45
|
+
);
|
|
25
46
|
}
|
|
26
|
-
return (0,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
47
|
+
return (0, import_transform_attachment.transformAttachment)(
|
|
48
|
+
await (0, import_api_fetch.default)({
|
|
49
|
+
// This allows the video block to directly get a video's poster image.
|
|
50
|
+
path: "/wp/v2/media?_embed=wp:featuredmedia",
|
|
51
|
+
body: data,
|
|
52
|
+
method: "POST",
|
|
53
|
+
signal
|
|
54
|
+
})
|
|
55
|
+
);
|
|
33
56
|
}
|
|
34
|
-
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
uploadToServer
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=upload-to-server.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/upload-to-server.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { flattenFormData } from './flatten-form-data';\nimport { transformAttachment } from './transform-attachment';\nimport type { CreateRestAttachment, RestAttachment } from './types';\n\nexport async function uploadToServer(\n\tfile: File,\n\tadditionalData: CreateRestAttachment = {},\n\tsignal?: AbortSignal\n) {\n\t// Create upload payload.\n\tconst data = new FormData();\n\tdata.append( 'file', file, file.name || file.type.replace( '/', '.' ) );\n\tfor ( const [ key, value ] of Object.entries( additionalData ) ) {\n\t\tflattenFormData(\n\t\t\tdata,\n\t\t\tkey,\n\t\t\tvalue as string | Record< string, string > | undefined\n\t\t);\n\t}\n\n\treturn transformAttachment(\n\t\tawait apiFetch< RestAttachment >( {\n\t\t\t// This allows the video block to directly get a video's poster image.\n\t\t\tpath: '/wp/v2/media?_embed=wp:featuredmedia',\n\t\t\tbody: data,\n\t\t\tmethod: 'POST',\n\t\t\tsignal,\n\t\t} )\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AAKrB,+BAAgC;AAChC,kCAAoC;AAGpC,eAAsB,eACrB,MACA,iBAAuC,CAAC,GACxC,QACC;AAED,QAAM,OAAO,IAAI,SAAS;AAC1B,OAAK,OAAQ,QAAQ,MAAM,KAAK,QAAQ,KAAK,KAAK,QAAS,KAAK,GAAI,CAAE;AACtE,aAAY,CAAE,KAAK,KAAM,KAAK,OAAO,QAAS,cAAe,GAAI;AAChE;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAEA,aAAO;AAAA,IACN,UAAM,iBAAAA,SAA4B;AAAA;AAAA,MAEjC,MAAM;AAAA,MACN,MAAM;AAAA,MACN,QAAQ;AAAA,MACR;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
|
|
6
|
+
"names": ["apiFetch"]
|
|
7
|
+
}
|
|
@@ -1,44 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var validate_file_size_exports = {};
|
|
20
|
+
__export(validate_file_size_exports, {
|
|
21
|
+
validateFileSize: () => validateFileSize
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
/**
|
|
10
|
-
* WordPress dependencies
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Verifies whether the file is within the file upload size limits for the site.
|
|
19
|
-
*
|
|
20
|
-
* @param file File object.
|
|
21
|
-
* @param maxUploadFileSize Maximum upload size in bytes allowed for the site.
|
|
22
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(validate_file_size_exports);
|
|
24
|
+
var import_i18n = require("@wordpress/i18n");
|
|
25
|
+
var import_upload_error = require("./upload-error");
|
|
23
26
|
function validateFileSize(file, maxUploadFileSize) {
|
|
24
|
-
// Don't allow empty files to be uploaded.
|
|
25
27
|
if (file.size <= 0) {
|
|
26
|
-
throw new
|
|
27
|
-
code:
|
|
28
|
-
message: (0,
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
throw new import_upload_error.UploadError({
|
|
29
|
+
code: "EMPTY_FILE",
|
|
30
|
+
message: (0, import_i18n.sprintf)(
|
|
31
|
+
// translators: %s: file name.
|
|
32
|
+
(0, import_i18n.__)("%s: This file is empty."),
|
|
33
|
+
file.name
|
|
34
|
+
),
|
|
31
35
|
file
|
|
32
36
|
});
|
|
33
37
|
}
|
|
34
38
|
if (maxUploadFileSize && file.size > maxUploadFileSize) {
|
|
35
|
-
throw new
|
|
36
|
-
code:
|
|
37
|
-
message: (0,
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
throw new import_upload_error.UploadError({
|
|
40
|
+
code: "SIZE_ABOVE_LIMIT",
|
|
41
|
+
message: (0, import_i18n.sprintf)(
|
|
42
|
+
// translators: %s: file name.
|
|
43
|
+
(0, import_i18n.__)(
|
|
44
|
+
"%s: This file exceeds the maximum upload size for this site."
|
|
45
|
+
),
|
|
46
|
+
file.name
|
|
47
|
+
),
|
|
40
48
|
file
|
|
41
49
|
});
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
|
-
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
validateFileSize
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=validate-file-size.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/validate-file-size.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { UploadError } from './upload-error';\n\n/**\n * Verifies whether the file is within the file upload size limits for the site.\n *\n * @param file File object.\n * @param maxUploadFileSize Maximum upload size in bytes allowed for the site.\n */\nexport function validateFileSize( file: File, maxUploadFileSize?: number ) {\n\t// Don't allow empty files to be uploaded.\n\tif ( file.size <= 0 ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'EMPTY_FILE',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__( '%s: This file is empty.' ),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n\n\tif ( maxUploadFileSize && file.size > maxUploadFileSize ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'SIZE_ABOVE_LIMIT',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__(\n\t\t\t\t\t'%s: This file exceeds the maximum upload size for this site.'\n\t\t\t\t),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAK5B,0BAA4B;AAQrB,SAAS,iBAAkB,MAAY,mBAA6B;AAE1E,MAAK,KAAK,QAAQ,GAAI;AACrB,UAAM,IAAI,gCAAa;AAAA,MACtB,MAAM;AAAA,MACN,aAAS;AAAA;AAAA,YAER,gBAAI,yBAA0B;AAAA,QAC9B,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AAEA,MAAK,qBAAqB,KAAK,OAAO,mBAAoB;AACzD,UAAM,IAAI,gCAAa;AAAA,MACtB,MAAM;AAAA,MACN,aAAS;AAAA;AAAA,YAER;AAAA,UACC;AAAA,QACD;AAAA,QACA,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,41 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var validate_mime_type_for_user_exports = {};
|
|
20
|
+
__export(validate_mime_type_for_user_exports, {
|
|
21
|
+
validateMimeTypeForUser: () => validateMimeTypeForUser
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
/**
|
|
11
|
-
* WordPress dependencies
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Verifies if the user is allowed to upload this mime type.
|
|
20
|
-
*
|
|
21
|
-
* @param file File object.
|
|
22
|
-
* @param wpAllowedMimeTypes List of allowed mime types and file extensions.
|
|
23
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(validate_mime_type_for_user_exports);
|
|
24
|
+
var import_i18n = require("@wordpress/i18n");
|
|
25
|
+
var import_upload_error = require("./upload-error");
|
|
26
|
+
var import_get_mime_types_array = require("./get-mime-types-array");
|
|
24
27
|
function validateMimeTypeForUser(file, wpAllowedMimeTypes) {
|
|
25
|
-
|
|
26
|
-
const allowedMimeTypesForUser = (0, _getMimeTypesArray.getMimeTypesArray)(wpAllowedMimeTypes);
|
|
28
|
+
const allowedMimeTypesForUser = (0, import_get_mime_types_array.getMimeTypesArray)(wpAllowedMimeTypes);
|
|
27
29
|
if (!allowedMimeTypesForUser) {
|
|
28
30
|
return;
|
|
29
31
|
}
|
|
30
|
-
const isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(
|
|
32
|
+
const isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(
|
|
33
|
+
file.type
|
|
34
|
+
);
|
|
31
35
|
if (file.type && !isAllowedMimeTypeForUser) {
|
|
32
|
-
throw new
|
|
33
|
-
code:
|
|
34
|
-
message: (0,
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
throw new import_upload_error.UploadError({
|
|
37
|
+
code: "MIME_TYPE_NOT_ALLOWED_FOR_USER",
|
|
38
|
+
message: (0, import_i18n.sprintf)(
|
|
39
|
+
// translators: %s: file name.
|
|
40
|
+
(0, import_i18n.__)(
|
|
41
|
+
"%s: Sorry, you are not allowed to upload this file type."
|
|
42
|
+
),
|
|
43
|
+
file.name
|
|
44
|
+
),
|
|
37
45
|
file
|
|
38
46
|
});
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
|
-
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
validateMimeTypeForUser
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=validate-mime-type-for-user.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/validate-mime-type-for-user.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { UploadError } from './upload-error';\nimport { getMimeTypesArray } from './get-mime-types-array';\n\n/**\n * Verifies if the user is allowed to upload this mime type.\n *\n * @param file File object.\n * @param wpAllowedMimeTypes List of allowed mime types and file extensions.\n */\nexport function validateMimeTypeForUser(\n\tfile: File,\n\twpAllowedMimeTypes?: Record< string, string > | null\n) {\n\t// Allowed types for the current WP_User.\n\tconst allowedMimeTypesForUser = getMimeTypesArray( wpAllowedMimeTypes );\n\n\tif ( ! allowedMimeTypesForUser ) {\n\t\treturn;\n\t}\n\n\tconst isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(\n\t\tfile.type\n\t);\n\n\tif ( file.type && ! isAllowedMimeTypeForUser ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'MIME_TYPE_NOT_ALLOWED_FOR_USER',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__(\n\t\t\t\t\t'%s: Sorry, you are not allowed to upload this file type.'\n\t\t\t\t),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAK5B,0BAA4B;AAC5B,kCAAkC;AAQ3B,SAAS,wBACf,MACA,oBACC;AAED,QAAM,8BAA0B,+CAAmB,kBAAmB;AAEtE,MAAK,CAAE,yBAA0B;AAChC;AAAA,EACD;AAEA,QAAM,2BAA2B,wBAAwB;AAAA,IACxD,KAAK;AAAA,EACN;AAEA,MAAK,KAAK,QAAQ,CAAE,0BAA2B;AAC9C,UAAM,IAAI,gCAAa;AAAA,MACtB,MAAM;AAAA,MACN,aAAS;AAAA;AAAA,YAER;AAAA,UACC;AAAA,QACD;AAAA,QACA,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,47 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var validate_mime_type_exports = {};
|
|
20
|
+
__export(validate_mime_type_exports, {
|
|
21
|
+
validateMimeType: () => validateMimeType
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
/**
|
|
10
|
-
* WordPress dependencies
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Verifies if the caller (e.g. a block) supports this mime type.
|
|
19
|
-
*
|
|
20
|
-
* @param file File object.
|
|
21
|
-
* @param allowedTypes List of allowed mime types.
|
|
22
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(validate_mime_type_exports);
|
|
24
|
+
var import_i18n = require("@wordpress/i18n");
|
|
25
|
+
var import_upload_error = require("./upload-error");
|
|
23
26
|
function validateMimeType(file, allowedTypes) {
|
|
24
27
|
if (!allowedTypes) {
|
|
25
28
|
return;
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const isAllowedType = allowedTypes.some(allowedType => {
|
|
30
|
-
// If a complete mimetype is specified verify if it matches exactly the mime type of the file.
|
|
31
|
-
if (allowedType.includes('/')) {
|
|
30
|
+
const isAllowedType = allowedTypes.some((allowedType) => {
|
|
31
|
+
if (allowedType.includes("/")) {
|
|
32
32
|
return allowedType === file.type;
|
|
33
33
|
}
|
|
34
|
-
// Otherwise a general mime type is used, and we should verify if the file mimetype starts with it.
|
|
35
34
|
return file.type.startsWith(`${allowedType}/`);
|
|
36
35
|
});
|
|
37
36
|
if (file.type && !isAllowedType) {
|
|
38
|
-
throw new
|
|
39
|
-
code:
|
|
40
|
-
message: (0,
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
throw new import_upload_error.UploadError({
|
|
38
|
+
code: "MIME_TYPE_NOT_SUPPORTED",
|
|
39
|
+
message: (0, import_i18n.sprintf)(
|
|
40
|
+
// translators: %s: file name.
|
|
41
|
+
(0, import_i18n.__)("%s: Sorry, this file type is not supported here."),
|
|
42
|
+
file.name
|
|
43
|
+
),
|
|
43
44
|
file
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
validateMimeType
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=validate-mime-type.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/validate-mime-type.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { UploadError } from './upload-error';\n\n/**\n * Verifies if the caller (e.g. a block) supports this mime type.\n *\n * @param file File object.\n * @param allowedTypes List of allowed mime types.\n */\nexport function validateMimeType( file: File, allowedTypes?: string[] ) {\n\tif ( ! allowedTypes ) {\n\t\treturn;\n\t}\n\n\t// Allowed type specified by consumer.\n\tconst isAllowedType = allowedTypes.some( ( allowedType ) => {\n\t\t// If a complete mimetype is specified verify if it matches exactly the mime type of the file.\n\t\tif ( allowedType.includes( '/' ) ) {\n\t\t\treturn allowedType === file.type;\n\t\t}\n\t\t// Otherwise a general mime type is used, and we should verify if the file mimetype starts with it.\n\t\treturn file.type.startsWith( `${ allowedType }/` );\n\t} );\n\n\tif ( file.type && ! isAllowedType ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'MIME_TYPE_NOT_SUPPORTED',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__( '%s: Sorry, this file type is not supported here.' ),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAK5B,0BAA4B;AAQrB,SAAS,iBAAkB,MAAY,cAA0B;AACvE,MAAK,CAAE,cAAe;AACrB;AAAA,EACD;AAGA,QAAM,gBAAgB,aAAa,KAAM,CAAE,gBAAiB;AAE3D,QAAK,YAAY,SAAU,GAAI,GAAI;AAClC,aAAO,gBAAgB,KAAK;AAAA,IAC7B;AAEA,WAAO,KAAK,KAAK,WAAY,GAAI,WAAY,GAAI;AAAA,EAClD,CAAE;AAEF,MAAK,KAAK,QAAQ,CAAE,eAAgB;AACnC,UAAM,IAAI,gCAAa;AAAA,MACtB,MAAM;AAAA,MACN,aAAS;AAAA;AAAA,YAER,gBAAI,kDAAmD;AAAA,QACvD,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/index.js"],
|
|
4
|
+
"sourcesContent": ["export { default as MediaUpload } from './media-upload';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAA8B;",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|