@wordpress/media-utils 5.6.0 → 5.8.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/CHANGELOG.md +8 -0
- package/README.md +70 -1
- package/build/index.js +43 -11
- package/build/index.js.map +1 -1
- package/build/utils/flatten-form-data.js +32 -0
- package/build/utils/flatten-form-data.js.map +1 -0
- package/build/utils/get-mime-types-array.js +27 -0
- package/build/utils/get-mime-types-array.js.map +1 -0
- package/build/utils/transform-attachment.js +33 -0
- package/build/utils/transform-attachment.js.map +1 -0
- package/build/utils/types.js +6 -0
- package/build/utils/types.js.map +1 -0
- package/build/utils/upload-error.js +29 -0
- package/build/utils/upload-error.js.map +1 -0
- package/build/utils/upload-media.js +53 -152
- package/build/utils/upload-media.js.map +1 -1
- package/build/utils/upload-to-server.js +34 -0
- package/build/utils/upload-to-server.js.map +1 -0
- package/build/utils/validate-file-size.js +44 -0
- package/build/utils/validate-file-size.js.map +1 -0
- package/build/utils/validate-mime-type-for-user.js +41 -0
- package/build/utils/validate-mime-type-for-user.js.map +1 -0
- package/build/utils/validate-mime-type.js +47 -0
- package/build/utils/validate-mime-type.js.map +1 -0
- package/build-module/index.js +5 -1
- package/build-module/index.js.map +1 -1
- package/build-module/utils/flatten-form-data.js +26 -0
- package/build-module/utils/flatten-form-data.js.map +1 -0
- package/build-module/utils/get-mime-types-array.js +21 -0
- package/build-module/utils/get-mime-types-array.js.map +1 -0
- package/build-module/utils/transform-attachment.js +27 -0
- package/build-module/utils/transform-attachment.js.map +1 -0
- package/build-module/utils/types.js +2 -0
- package/build-module/utils/types.js.map +1 -0
- package/build-module/utils/upload-error.js +22 -0
- package/build-module/utils/upload-error.js.map +1 -0
- package/build-module/utils/upload-media.js +53 -149
- package/build-module/utils/upload-media.js.map +1 -1
- package/build-module/utils/upload-to-server.js +26 -0
- package/build-module/utils/upload-to-server.js.map +1 -0
- package/build-module/utils/validate-file-size.js +38 -0
- package/build-module/utils/validate-file-size.js.map +1 -0
- package/build-module/utils/validate-mime-type-for-user.js +35 -0
- package/build-module/utils/validate-mime-type-for-user.js.map +1 -0
- package/build-module/utils/validate-mime-type.js +41 -0
- package/build-module/utils/validate-mime-type.js.map +1 -0
- package/build-types/components/index.d.ts +2 -0
- package/build-types/components/index.d.ts.map +1 -0
- package/build-types/components/media-upload/index.d.ts +30 -0
- package/build-types/components/media-upload/index.d.ts.map +1 -0
- package/build-types/index.d.ts +8 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/utils/flatten-form-data.d.ts +9 -0
- package/build-types/utils/flatten-form-data.d.ts.map +1 -0
- package/build-types/utils/get-mime-types-array.d.ts +12 -0
- package/build-types/utils/get-mime-types-array.d.ts.map +1 -0
- package/build-types/utils/transform-attachment.d.ts +11 -0
- package/build-types/utils/transform-attachment.d.ts.map +1 -0
- package/build-types/utils/types.d.ts +199 -0
- package/build-types/utils/types.d.ts.map +1 -0
- package/build-types/utils/upload-error.d.ts +19 -0
- package/build-types/utils/upload-error.d.ts.map +1 -0
- package/build-types/utils/upload-media.d.ts +32 -0
- package/build-types/utils/upload-media.d.ts.map +1 -0
- package/build-types/utils/upload-to-server.d.ts +3 -0
- package/build-types/utils/upload-to-server.d.ts.map +1 -0
- package/build-types/utils/validate-file-size.d.ts +8 -0
- package/build-types/utils/validate-file-size.d.ts.map +1 -0
- package/build-types/utils/validate-mime-type-for-user.d.ts +8 -0
- package/build-types/utils/validate-mime-type-for-user.d.ts.map +1 -0
- package/build-types/utils/validate-mime-type.d.ts +8 -0
- package/build-types/utils/validate-mime-type.d.ts.map +1 -0
- package/package.json +8 -7
- package/src/index.ts +9 -0
- package/src/utils/flatten-form-data.ts +33 -0
- package/src/utils/get-mime-types-array.ts +29 -0
- package/src/utils/test/flatten-form-data.ts +49 -0
- package/src/utils/test/get-mime-types-array.ts +47 -0
- package/src/utils/test/upload-error.ts +24 -0
- package/src/utils/test/{upload-media.test.js → upload-media.ts} +47 -76
- package/src/utils/test/validate-file-size.ts +70 -0
- package/src/utils/test/validate-mime-type-for-user.ts +37 -0
- package/src/utils/test/validate-mime-type.ts +57 -0
- package/src/utils/transform-attachment.ts +24 -0
- package/src/utils/types.ts +207 -0
- package/src/utils/upload-error.ts +26 -0
- package/src/utils/upload-media.ts +149 -0
- package/src/utils/upload-to-server.ts +38 -0
- package/src/utils/validate-file-size.ts +44 -0
- package/src/utils/validate-mime-type-for-user.ts +46 -0
- package/src/utils/validate-mime-type.ts +43 -0
- package/tsconfig.json +17 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/build/utils/index.js +0 -13
- package/build/utils/index.js.map +0 -1
- package/build-module/utils/index.js +0 -2
- package/build-module/utils/index.js.map +0 -1
- package/src/index.js +0 -2
- package/src/utils/index.js +0 -1
- package/src/utils/upload-media.js +0 -232
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
5
|
+
import { createBlobURL, revokeBlobURL } from '@wordpress/blob';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import type {
|
|
11
|
+
AdditionalData,
|
|
12
|
+
Attachment,
|
|
13
|
+
OnChangeHandler,
|
|
14
|
+
OnErrorHandler,
|
|
15
|
+
OnSuccessHandler,
|
|
16
|
+
} from './types';
|
|
17
|
+
import { uploadToServer } from './upload-to-server';
|
|
18
|
+
import { validateMimeType } from './validate-mime-type';
|
|
19
|
+
import { validateMimeTypeForUser } from './validate-mime-type-for-user';
|
|
20
|
+
import { validateFileSize } from './validate-file-size';
|
|
21
|
+
import { UploadError } from './upload-error';
|
|
22
|
+
|
|
23
|
+
interface UploadMediaArgs {
|
|
24
|
+
// Additional data to include in the request.
|
|
25
|
+
additionalData?: AdditionalData;
|
|
26
|
+
// Array with the types of media that can be uploaded, if unset all types are allowed.
|
|
27
|
+
allowedTypes?: string[];
|
|
28
|
+
// List of files.
|
|
29
|
+
filesList: File[];
|
|
30
|
+
// Maximum upload size in bytes allowed for the site.
|
|
31
|
+
maxUploadFileSize?: number;
|
|
32
|
+
// Function called when an error happens.
|
|
33
|
+
onError?: OnErrorHandler;
|
|
34
|
+
// Function called each time a file or a temporary representation of the file is available.
|
|
35
|
+
onFileChange?: OnChangeHandler;
|
|
36
|
+
// Function called once a file has completely finished uploading, including thumbnails.
|
|
37
|
+
onSuccess?: OnSuccessHandler;
|
|
38
|
+
// List of allowed mime types and file extensions.
|
|
39
|
+
wpAllowedMimeTypes?: Record< string, string > | null;
|
|
40
|
+
// Abort signal.
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Upload a media file when the file upload button is activated
|
|
46
|
+
* or when adding a file to the editor via drag & drop.
|
|
47
|
+
*
|
|
48
|
+
* @param $0 Parameters object passed to the function.
|
|
49
|
+
* @param $0.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.
|
|
50
|
+
* @param $0.additionalData Additional data to include in the request.
|
|
51
|
+
* @param $0.filesList List of files.
|
|
52
|
+
* @param $0.maxUploadFileSize Maximum upload size in bytes allowed for the site.
|
|
53
|
+
* @param $0.onError Function called when an error happens.
|
|
54
|
+
* @param $0.onFileChange Function called each time a file or a temporary representation of the file is available.
|
|
55
|
+
* @param $0.wpAllowedMimeTypes List of allowed mime types and file extensions.
|
|
56
|
+
* @param $0.signal Abort signal.
|
|
57
|
+
*/
|
|
58
|
+
export function uploadMedia( {
|
|
59
|
+
wpAllowedMimeTypes,
|
|
60
|
+
allowedTypes,
|
|
61
|
+
additionalData = {},
|
|
62
|
+
filesList,
|
|
63
|
+
maxUploadFileSize,
|
|
64
|
+
onError,
|
|
65
|
+
onFileChange,
|
|
66
|
+
signal,
|
|
67
|
+
}: UploadMediaArgs ) {
|
|
68
|
+
const validFiles = [];
|
|
69
|
+
|
|
70
|
+
const filesSet: Array< Partial< Attachment > | null > = [];
|
|
71
|
+
const setAndUpdateFiles = ( index: number, value: Attachment | null ) => {
|
|
72
|
+
if ( filesSet[ index ]?.url ) {
|
|
73
|
+
revokeBlobURL( filesSet[ index ].url );
|
|
74
|
+
}
|
|
75
|
+
filesSet[ index ] = value;
|
|
76
|
+
onFileChange?.(
|
|
77
|
+
filesSet.filter( ( attachment ) => attachment !== null )
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
for ( const mediaFile of filesList ) {
|
|
82
|
+
// Verify if user is allowed to upload this mime type.
|
|
83
|
+
// Defer to the server when type not detected.
|
|
84
|
+
try {
|
|
85
|
+
validateMimeTypeForUser( mediaFile, wpAllowedMimeTypes );
|
|
86
|
+
} catch ( error: unknown ) {
|
|
87
|
+
onError?.( error as Error );
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Check if the caller (e.g. a block) supports this mime type.
|
|
92
|
+
// Defer to the server when type not detected.
|
|
93
|
+
try {
|
|
94
|
+
validateMimeType( mediaFile, allowedTypes );
|
|
95
|
+
} catch ( error: unknown ) {
|
|
96
|
+
onError?.( error as Error );
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Verify if file is greater than the maximum file upload size allowed for the site.
|
|
101
|
+
try {
|
|
102
|
+
validateFileSize( mediaFile, maxUploadFileSize );
|
|
103
|
+
} catch ( error: unknown ) {
|
|
104
|
+
onError?.( error as Error );
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
validFiles.push( mediaFile );
|
|
109
|
+
|
|
110
|
+
// Set temporary URL to create placeholder media file, this is replaced
|
|
111
|
+
// with final file from media gallery when upload is `done` below.
|
|
112
|
+
filesSet.push( { url: createBlobURL( mediaFile ) } );
|
|
113
|
+
onFileChange?.( filesSet as Array< Partial< Attachment > > );
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
validFiles.map( async ( file, index ) => {
|
|
117
|
+
try {
|
|
118
|
+
const attachment = await uploadToServer(
|
|
119
|
+
file,
|
|
120
|
+
additionalData,
|
|
121
|
+
signal
|
|
122
|
+
);
|
|
123
|
+
setAndUpdateFiles( index, attachment );
|
|
124
|
+
} catch ( error ) {
|
|
125
|
+
// Reset to empty on failure.
|
|
126
|
+
setAndUpdateFiles( index, null );
|
|
127
|
+
|
|
128
|
+
let message;
|
|
129
|
+
if ( error instanceof Error ) {
|
|
130
|
+
message = error.message;
|
|
131
|
+
} else {
|
|
132
|
+
message = sprintf(
|
|
133
|
+
// translators: %s: file name
|
|
134
|
+
__( 'Error while uploading file %s to the media library.' ),
|
|
135
|
+
file.name
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
onError?.(
|
|
140
|
+
new UploadError( {
|
|
141
|
+
code: 'GENERAL',
|
|
142
|
+
message,
|
|
143
|
+
file,
|
|
144
|
+
cause: error instanceof Error ? error : undefined,
|
|
145
|
+
} )
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
} );
|
|
149
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { flattenFormData } from './flatten-form-data';
|
|
10
|
+
import { transformAttachment } from './transform-attachment';
|
|
11
|
+
import type { CreateRestAttachment, RestAttachment } from './types';
|
|
12
|
+
|
|
13
|
+
export async function uploadToServer(
|
|
14
|
+
file: File,
|
|
15
|
+
additionalData: CreateRestAttachment = {},
|
|
16
|
+
signal?: AbortSignal
|
|
17
|
+
) {
|
|
18
|
+
// Create upload payload.
|
|
19
|
+
const data = new FormData();
|
|
20
|
+
data.append( 'file', file, file.name || file.type.replace( '/', '.' ) );
|
|
21
|
+
for ( const [ key, value ] of Object.entries( additionalData ) ) {
|
|
22
|
+
flattenFormData(
|
|
23
|
+
data,
|
|
24
|
+
key,
|
|
25
|
+
value as string | Record< string, string > | undefined
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return transformAttachment(
|
|
30
|
+
await apiFetch< RestAttachment >( {
|
|
31
|
+
// This allows the video block to directly get a video's poster image.
|
|
32
|
+
path: '/wp/v2/media?_embed=wp:featuredmedia',
|
|
33
|
+
body: data,
|
|
34
|
+
method: 'POST',
|
|
35
|
+
signal,
|
|
36
|
+
} )
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { UploadError } from './upload-error';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Verifies whether the file is within the file upload size limits for the site.
|
|
13
|
+
*
|
|
14
|
+
* @param file File object.
|
|
15
|
+
* @param maxUploadFileSize Maximum upload size in bytes allowed for the site.
|
|
16
|
+
*/
|
|
17
|
+
export function validateFileSize( file: File, maxUploadFileSize?: number ) {
|
|
18
|
+
// Don't allow empty files to be uploaded.
|
|
19
|
+
if ( file.size <= 0 ) {
|
|
20
|
+
throw new UploadError( {
|
|
21
|
+
code: 'EMPTY_FILE',
|
|
22
|
+
message: sprintf(
|
|
23
|
+
// translators: %s: file name.
|
|
24
|
+
__( '%s: This file is empty.' ),
|
|
25
|
+
file.name
|
|
26
|
+
),
|
|
27
|
+
file,
|
|
28
|
+
} );
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if ( maxUploadFileSize && file.size > maxUploadFileSize ) {
|
|
32
|
+
throw new UploadError( {
|
|
33
|
+
code: 'SIZE_ABOVE_LIMIT',
|
|
34
|
+
message: sprintf(
|
|
35
|
+
// translators: %s: file name.
|
|
36
|
+
__(
|
|
37
|
+
'%s: This file exceeds the maximum upload size for this site.'
|
|
38
|
+
),
|
|
39
|
+
file.name
|
|
40
|
+
),
|
|
41
|
+
file,
|
|
42
|
+
} );
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { UploadError } from './upload-error';
|
|
10
|
+
import { getMimeTypesArray } from './get-mime-types-array';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Verifies if the user is allowed to upload this mime type.
|
|
14
|
+
*
|
|
15
|
+
* @param file File object.
|
|
16
|
+
* @param wpAllowedMimeTypes List of allowed mime types and file extensions.
|
|
17
|
+
*/
|
|
18
|
+
export function validateMimeTypeForUser(
|
|
19
|
+
file: File,
|
|
20
|
+
wpAllowedMimeTypes?: Record< string, string > | null
|
|
21
|
+
) {
|
|
22
|
+
// Allowed types for the current WP_User.
|
|
23
|
+
const allowedMimeTypesForUser = getMimeTypesArray( wpAllowedMimeTypes );
|
|
24
|
+
|
|
25
|
+
if ( ! allowedMimeTypesForUser ) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(
|
|
30
|
+
file.type
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if ( file.type && ! isAllowedMimeTypeForUser ) {
|
|
34
|
+
throw new UploadError( {
|
|
35
|
+
code: 'MIME_TYPE_NOT_ALLOWED_FOR_USER',
|
|
36
|
+
message: sprintf(
|
|
37
|
+
// translators: %s: file name.
|
|
38
|
+
__(
|
|
39
|
+
'%s: Sorry, you are not allowed to upload this file type.'
|
|
40
|
+
),
|
|
41
|
+
file.name
|
|
42
|
+
),
|
|
43
|
+
file,
|
|
44
|
+
} );
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { UploadError } from './upload-error';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Verifies if the caller (e.g. a block) supports this mime type.
|
|
13
|
+
*
|
|
14
|
+
* @param file File object.
|
|
15
|
+
* @param allowedTypes List of allowed mime types.
|
|
16
|
+
*/
|
|
17
|
+
export function validateMimeType( file: File, allowedTypes?: string[] ) {
|
|
18
|
+
if ( ! allowedTypes ) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Allowed type specified by consumer.
|
|
23
|
+
const isAllowedType = allowedTypes.some( ( allowedType ) => {
|
|
24
|
+
// If a complete mimetype is specified verify if it matches exactly the mime type of the file.
|
|
25
|
+
if ( allowedType.includes( '/' ) ) {
|
|
26
|
+
return allowedType === file.type;
|
|
27
|
+
}
|
|
28
|
+
// Otherwise a general mime type is used, and we should verify if the file mimetype starts with it.
|
|
29
|
+
return file.type.startsWith( `${ allowedType }/` );
|
|
30
|
+
} );
|
|
31
|
+
|
|
32
|
+
if ( file.type && ! isAllowedType ) {
|
|
33
|
+
throw new UploadError( {
|
|
34
|
+
code: 'MIME_TYPE_NOT_SUPPORTED',
|
|
35
|
+
message: sprintf(
|
|
36
|
+
// translators: %s: file name.
|
|
37
|
+
__( '%s: Sorry, this file type is not supported here.' ),
|
|
38
|
+
file.name
|
|
39
|
+
),
|
|
40
|
+
file,
|
|
41
|
+
} );
|
|
42
|
+
}
|
|
43
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig.json",
|
|
3
|
+
"extends": "../../tsconfig.base.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"rootDir": "src",
|
|
6
|
+
"declarationDir": "build-types",
|
|
7
|
+
"types": [ "gutenberg-env" ],
|
|
8
|
+
"checkJs": false
|
|
9
|
+
},
|
|
10
|
+
"include": [ "src/**/*" ],
|
|
11
|
+
"references": [
|
|
12
|
+
{ "path": "../api-fetch" },
|
|
13
|
+
{ "path": "../blob" },
|
|
14
|
+
{ "path": "../element" },
|
|
15
|
+
{ "path": "../i18n" }
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.es2021.d.ts","../../node_modules/typescript/lib/lib.es2022.d.ts","../../node_modules/typescript/lib/lib.es2023.d.ts","../../node_modules/typescript/lib/lib.esnext.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.dom.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2016.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.date.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../node_modules/typescript/lib/lib.es2023.array.d.ts","../../node_modules/typescript/lib/lib.es2023.collection.d.ts","../../node_modules/typescript/lib/lib.es2023.intl.d.ts","../../node_modules/typescript/lib/lib.esnext.array.d.ts","../../node_modules/typescript/lib/lib.esnext.collection.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../node_modules/typescript/lib/lib.esnext.disposable.d.ts","../../node_modules/typescript/lib/lib.esnext.string.d.ts","../../node_modules/typescript/lib/lib.esnext.promise.d.ts","../../node_modules/typescript/lib/lib.esnext.decorators.d.ts","../../node_modules/typescript/lib/lib.esnext.object.d.ts","../../node_modules/typescript/lib/lib.esnext.regexp.d.ts","../../node_modules/typescript/lib/lib.decorators.d.ts","../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../node_modules/@types/react/global.d.ts","../../node_modules/csstype/index.d.ts","../../node_modules/@types/prop-types/index.d.ts","../../node_modules/@types/react/index.d.ts","../element/build-types/create-interpolate-element.d.ts","../element/build-types/react.d.ts","../../node_modules/@types/react-dom/index.d.ts","../../node_modules/@types/react-dom/client.d.ts","../element/build-types/react-platform.d.ts","../element/build-types/utils.d.ts","../element/build-types/platform.d.ts","../element/build-types/serialize.d.ts","../element/build-types/raw-html.d.ts","../element/build-types/index.d.ts","../i18n/build-types/sprintf.d.ts","../hooks/build-types/createAddHook.d.ts","../hooks/build-types/createRemoveHook.d.ts","../hooks/build-types/createHasHook.d.ts","../hooks/build-types/createDoingHook.d.ts","../hooks/build-types/createDidHook.d.ts","../hooks/build-types/index.d.ts","../hooks/build-types/createHooks.d.ts","../i18n/build-types/create-i18n.d.ts","../i18n/build-types/default-i18n.d.ts","../i18n/build-types/index.d.ts","./src/components/media-upload/index.js","./src/components/index.js","../blob/build-types/index.d.ts","./src/utils/types.ts","../api-fetch/build-types/types.d.ts","../api-fetch/build-types/middlewares/nonce.d.ts","../api-fetch/build-types/middlewares/preloading.d.ts","../api-fetch/build-types/middlewares/root-url.d.ts","../api-fetch/build-types/middlewares/fetch-all-middleware.d.ts","../api-fetch/build-types/middlewares/media-upload.d.ts","../api-fetch/build-types/middlewares/theme-preview.d.ts","../api-fetch/build-types/index.d.ts","./src/utils/flatten-form-data.ts","./src/utils/transform-attachment.ts","./src/utils/upload-to-server.ts","./src/utils/upload-error.ts","./src/utils/validate-mime-type.ts","./src/utils/get-mime-types-array.ts","./src/utils/validate-mime-type-for-user.ts","./src/utils/validate-file-size.ts","./src/utils/upload-media.ts","./src/index.ts","../../typings/gutenberg-env/index.d.ts"],"fileInfos":[{"version":"44e584d4f6444f58791784f1d530875970993129442a847597db702a073ca68c","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","27bdc30a0e32783366a5abeda841bc22757c1797de8681bbe81fbc735eeb1c10","17edc026abf73c5c2dd508652d63f68ec4efd9d4856e3469890d27598209feb5",{"version":"4af6b0c727b7a2896463d512fafd23634229adf69ac7c00e2ae15a09cb084fad","affectsGlobalScope":true},{"version":"9c00a480825408b6a24c63c1b71362232927247595d7c97659bc24dc68ae0757","affectsGlobalScope":true},{"version":"6920e1448680767498a0b77c6a00a8e77d14d62c3da8967b171f1ddffa3c18e4","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"ea011c76963fb15ef1cdd7ce6a6808b46322c527de2077b6cfdf23ae6f5f9ec7","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true},{"version":"ae37d6ccd1560b0203ab88d46987393adaaa78c919e51acf32fb82c86502e98c","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"5e07ed3809d48205d5b985642a59f2eba47c402374a7cf8006b686f79efadcbd","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"479553e3779be7d4f68e9f40cdb82d038e5ef7592010100410723ceced22a0f7","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"d3d7b04b45033f57351c8434f60b6be1ea71a2dfec2d0a0c3c83badbb0e3e693","affectsGlobalScope":true},{"version":"956d27abdea9652e8368ce029bb1e0b9174e9678a273529f426df4b3d90abd60","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"d8670852241d4c6e03f2b89d67497a4bbefe29ecaa5a444e2c11a9b05e6fccc6","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"b4b67b1a91182421f5df999988c690f14d813b9850b40acd06ed44691f6727ad","affectsGlobalScope":true},{"version":"08a58483392df5fcc1db57d782e87734f77ae9eab42516028acbfe46f29a3ef7","affectsGlobalScope":true},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true},{"version":"8e3c06ea092138bf9fa5e874a1fdbc9d54805d074bee1de31b99a11e2fec239d","affectsGlobalScope":true},{"version":"0b11f3ca66aa33124202c80b70cd203219c3d4460cfc165e0707aa9ec710fc53","affectsGlobalScope":true},{"version":"6a3f5a0129cc80cf439ab71164334d649b47059a4f5afca90282362407d0c87f","affectsGlobalScope":true},{"version":"811c71eee4aa0ac5f7adf713323a5c41b0cf6c4e17367a34fbce379e12bbf0a4","affectsGlobalScope":true},{"version":"15b98a533864d324e5f57cd3cfc0579b231df58c1c0f6063ea0fcb13c3c74ff9","affectsGlobalScope":true},{"version":"0a6282c8827e4b9a95f4bf4f5c205673ada31b982f50572d27103df8ceb8013c","affectsGlobalScope":true},{"version":"ac77cb3e8c6d3565793eb90a8373ee8033146315a3dbead3bde8db5eaf5e5ec6","affectsGlobalScope":true},{"version":"d4b1d2c51d058fc21ec2629fff7a76249dec2e36e12960ea056e3ef89174080f","affectsGlobalScope":true},{"version":"2fef54945a13095fdb9b84f705f2b5994597640c46afeb2ce78352fab4cb3279","affectsGlobalScope":true},{"version":"56e4ed5aab5f5920980066a9409bfaf53e6d21d3f8d020c17e4de584d29600ad","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},{"version":"55461596dc873b866911ef4e640fae4c39da7ac1fbc7ef5e649cb2f2fb42c349","affectsGlobalScope":true},"4c68749a564a6facdf675416d75789ee5a557afda8960e0803cf6711fa569288","f7b46d22a307739c145e5fddf537818038fdfffd580d79ed717f4d4d37249380",{"version":"8ca4709dbd22a34bcc1ebf93e1877645bdb02ebd3f3d9a211a299a8db2ee4ba1","affectsGlobalScope":true},"4c506b14512049dfe6f4ceb172b13c6af03663f85ba61fc57efbe6c2e7be9f44","4405cd67ec5f7f748fd793be0ce5842fa0808955b8e37518c011abfa5ab63ba5","adb17fea4d847e1267ae1241fa1ac3917c7e332999ebdab388a24d82d4f58240","05321b823dd3781d0b6aac8700bfdc0c9181d56479fe52ba6a40c9196fd661a8","472c14cdec534a465e866b6e1feee2d4e0d89c15fdc33ba80ff034fa0e80f3c1","4d807d55c784b72f71c092c34c84d09b95c29500c30252538fd5cf9a0a788c0e","df43a3968118d4b16618d7a0ac8ba89337fcce3c39e39984087ac34bf0cf250c","4714d89e7ea47b8f79a4d448a11674b2a724f93ab03cfa6879dafbab0f0c5a15","cb9a03b327570c1eae5c82a48604ef697ad1a6264ed0490743a3449de61a4fff","af88a0b0f808a6721401550621bfe67c46c6fd55000305058e7c73600d119a9b","2f1fe46a7a4e25a4a414d5491c7b39b695a6f37e97a1bdfeb71d430f98c3ed10","20f2b0befb27c07049565340fac3ab264c94afebacb3234dfb945e1c4a8ab5fb","406a8b30598c33638390e65c1b18d65804784069a176ec900aa033b2b0038673","0b48405ec967a9982c1001d4222b1c64091aba1441fc4318b08bc1cd4036794a","12324a25a603147ab9cf9724d762a767dd8b22c3b4f3ea44357bb937565509c3","7966497f2357f63036d7c12917ee20d91b7a74c4d9d682e75c44f7b7f6ea4e5b","0213daac422dfdc25a92d4a95859fb7d9d451fdd67fa675d3705884289019fd9","154d6cd3d408e0ac27d063a1c05eba3fbe6218643059f07abf83a8db7b78e5cc","08c2de6aff6a0af37e67460ae45ca87f440ef378f5a586afcafea49a02db3990","061e88a6b235d5dd90a3cb8af8d27f397fd069e1bed76a5c7617b1c00a395ba7","2a49b24214a9709c04c7d21d99f1473058bd3b4d1310655288347a4c8862da30",{"version":"6b2c22803b37b9d6efddc754c15e0261c373378668ac75cbf795b5b64b45cf3a","signature":"4dd88e34f7eb9132e6064b2dc601ee46506537753bf5c5e2b80538fa248a718c"},{"version":"1046d3ac059363b0160758674a343e23a5262c6fe4ecf75aaa622f1681c11e55","signature":"370f606498ffd6b82bc16091c77b55c219f42093b2d0dbe6f85631eceb70069e"},"26dbb5d43d71f83d67778a513a7b130555d5d844bce071e340373e69d7ca3c8f",{"version":"3e476c72f40a03bbe496f29eb5bc977c90c74d68bc40687c522eaa70d08914d3","signature":"11adb12ee8d9809d7aa458f717a3c863ff6668a64af352efcf76c1463089513b"},"3482d13bc405611566ba123aad79452857745448142396834295f9180c256698","e365ba12b07112503bbbd9288f0c9ca4bf489be7fdfad34a1283057151715809","3ca242600b64f805e6b2c5184538aa74d75842f9fad69bad0afa859aca385c38","8be7afaa20cb8fe823c7efc4757166924731e6c0cb224a25052d2ce698c5e3be","42886bbaee379c1c9c75850ff45d71f25f9c077dd80059795b319cebeac941f0","5718e06ca02fd4da961d57375d8fd21f0ec4deffd243b9daa46a3f71e1c44c1d","b73ca7483e8207e6c359cab77d1b02352993c833ebc025cbf0044d056cf03010","16bee3e299a6c1ddf12e8175ca75de044b097211eac8a1e6cd0c972a4b279419",{"version":"da3bb674c1182d84093929be7871ad700e21e0b7daea1da441a3eead717874c6","signature":"8a03de0a8ccd986f069e47e746e880ff5752474c68cfbe8475bee2b798050cbf"},{"version":"fe5754aa45b8acd6511d03bff4daf9d61b87d715af248044424f4c1c624a172d","signature":"040bbe5b8fae690cef078d6f0a2c83876d1204577369421cedc1e264ca21393d"},{"version":"96cce577a689f2741284cb548ca9e1090154c4b939a93789d509066392c172ce","signature":"5102357e4b7452b8afd38b2f4c509e1079fdddef1c8c5dedc934b7ff0e3e9235"},{"version":"916cdcd1b368ffd1783a4a04162b508d6c8408c3f21b9ed6c880e596e66c4414","signature":"f29b397bbb375815f7ae0a30e5abe4d6921893eecabd15f2a2a26ac1b767978b"},{"version":"6469831c12f693df087d37a6e97e9fffab133f7798f90b486dfc9552c389cef0","signature":"cb87a039169f10e3e3cc92416c20ccd04d8841a4b7ba12ddaf68ebec2e9feea5"},{"version":"3dfd2b6e204c409e473e9141999af424c4c49fb04add6c0679f43c0bd9684e3d","signature":"1c39a61f95b134bb96a287a458ae5d67d659e1cbddcb99ae19617a3962558a14"},{"version":"c3c7068bfefc188ec3b622e0e160f5d572d140daf8cc9f5a6f7283d5749f0765","signature":"da598aa05f7892c3f3371e0d62d5b9d574786215e3d0b82b1d0cf247688a540a"},{"version":"5cf9279015909d07c027fdc725de54ffb602487685bbb9c98e63d70c7a1f620f","signature":"9e11037f69d3b5d4f0d623aa90f00d5936af06a1d90cd6ede7d0ec5f9939ee87"},{"version":"93f13518a1f6a5d7c8e81e5c1dc1294c069ac5dc82212dde6cc645395b9e6f49","signature":"4a54c691ec0a9e647f3e85f3355e51b06fd0ff638e94667b89db554521d698a6"},{"version":"bc54ef0a4dea92e774f57a1c68071b9a9d428d05d43d8edba0418c63874683c2","signature":"8ec628fed81d4f8d8f4183adb94142f7f74e900643472d96342b9bcbdbb5ca22"},{"version":"cd62baba8e325afe998a6537894fcc0420146c242e1b6fdfdaaadfd21dc0d969","affectsGlobalScope":true}],"root":[99,100,102,[111,120]],"options":{"allowJs":true,"allowSyntheticDefaultImports":true,"checkJs":false,"composite":true,"declaration":true,"declarationDir":"./build-types","declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":false,"jsx":1,"module":99,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"rootDir":"./src","skipDefaultLibCheck":true,"strict":true,"target":99},"fileIdsList":[[77],[74,75,76],[103,104,105,106,107,108,109],[103],[78,79,82,83,84,85,86],[80,81],[94],[89,90,91,92,93,94],[89,90,91,92,93,95],[94,95],[96],[88,96,97],[99],[87,98],[100,102,112,115,117,118,119],[102],[98,101,102,113,114,115,117,118],[102,110,111,112],[98,114],[98,114,116]],"referencedMap":[[81,1],[80,1],[77,2],[110,3],[107,4],[108,4],[104,4],[105,4],[106,4],[109,4],[78,1],[87,5],[86,1],[82,6],[79,1],[85,1],[89,7],[93,7],[92,7],[91,7],[95,8],[90,7],[94,9],[96,10],[97,11],[98,12],[100,13],[99,14],[120,15],[112,16],[119,17],[113,18],[118,19],[117,20],[115,19]],"latestChangedDtsFile":"./build-types/index.d.ts"},"version":"5.5.3"}
|
package/build/utils/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "uploadMedia", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _uploadMedia.uploadMedia;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _uploadMedia = require("./upload-media");
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
package/build/utils/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_uploadMedia","require"],"sources":["@wordpress/media-utils/src/utils/index.js"],"sourcesContent":["export { uploadMedia } from './upload-media';\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["uploadMedia"],"sources":["@wordpress/media-utils/src/utils/index.js"],"sourcesContent":["export { uploadMedia } from './upload-media';\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,gBAAgB","ignoreList":[]}
|
package/src/index.js
DELETED
package/src/utils/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { uploadMedia } from './upload-media';
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import apiFetch from '@wordpress/api-fetch';
|
|
5
|
-
import { createBlobURL, revokeBlobURL } from '@wordpress/blob';
|
|
6
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
7
|
-
|
|
8
|
-
const noop = () => {};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Browsers may use unexpected mime types, and they differ from browser to browser.
|
|
12
|
-
* This function computes a flexible array of mime types from the mime type structured provided by the server.
|
|
13
|
-
* Converts { jpg|jpeg|jpe: "image/jpeg" } into [ "image/jpeg", "image/jpg", "image/jpeg", "image/jpe" ]
|
|
14
|
-
* The computation of this array instead of directly using the object,
|
|
15
|
-
* solves the problem in chrome where mp3 files have audio/mp3 as mime type instead of audio/mpeg.
|
|
16
|
-
* https://bugs.chromium.org/p/chromium/issues/detail?id=227004
|
|
17
|
-
*
|
|
18
|
-
* @param {?Object} wpMimeTypesObject Mime type object received from the server.
|
|
19
|
-
* Extensions are keys separated by '|' and values are mime types associated with an extension.
|
|
20
|
-
*
|
|
21
|
-
* @return {?Array} An array of mime types or the parameter passed if it was "falsy".
|
|
22
|
-
*/
|
|
23
|
-
export function getMimeTypesArray( wpMimeTypesObject ) {
|
|
24
|
-
if ( ! wpMimeTypesObject ) {
|
|
25
|
-
return wpMimeTypesObject;
|
|
26
|
-
}
|
|
27
|
-
return Object.entries( wpMimeTypesObject )
|
|
28
|
-
.map( ( [ extensionsString, mime ] ) => {
|
|
29
|
-
const [ type ] = mime.split( '/' );
|
|
30
|
-
const extensions = extensionsString.split( '|' );
|
|
31
|
-
return [
|
|
32
|
-
mime,
|
|
33
|
-
...extensions.map(
|
|
34
|
-
( extension ) => `${ type }/${ extension }`
|
|
35
|
-
),
|
|
36
|
-
];
|
|
37
|
-
} )
|
|
38
|
-
.flat();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Media Upload is used by audio, image, gallery, video, and file blocks to
|
|
43
|
-
* handle uploading a media file when a file upload button is activated.
|
|
44
|
-
*
|
|
45
|
-
* TODO: future enhancement to add an upload indicator.
|
|
46
|
-
*
|
|
47
|
-
* @param {Object} $0 Parameters object passed to the function.
|
|
48
|
-
* @param {?Array} $0.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.
|
|
49
|
-
* @param {?Object} $0.additionalData Additional data to include in the request.
|
|
50
|
-
* @param {Array} $0.filesList List of files.
|
|
51
|
-
* @param {?number} $0.maxUploadFileSize Maximum upload size in bytes allowed for the site.
|
|
52
|
-
* @param {Function} $0.onError Function called when an error happens.
|
|
53
|
-
* @param {Function} $0.onFileChange Function called each time a file or a temporary representation of the file is available.
|
|
54
|
-
* @param {?Object} $0.wpAllowedMimeTypes List of allowed mime types and file extensions.
|
|
55
|
-
*/
|
|
56
|
-
export async function uploadMedia( {
|
|
57
|
-
allowedTypes,
|
|
58
|
-
additionalData = {},
|
|
59
|
-
filesList,
|
|
60
|
-
maxUploadFileSize,
|
|
61
|
-
onError = noop,
|
|
62
|
-
onFileChange,
|
|
63
|
-
wpAllowedMimeTypes = null,
|
|
64
|
-
} ) {
|
|
65
|
-
// Cast filesList to array.
|
|
66
|
-
const files = [ ...filesList ];
|
|
67
|
-
|
|
68
|
-
const filesSet = [];
|
|
69
|
-
const setAndUpdateFiles = ( idx, value ) => {
|
|
70
|
-
revokeBlobURL( filesSet[ idx ]?.url );
|
|
71
|
-
filesSet[ idx ] = value;
|
|
72
|
-
onFileChange( filesSet.filter( Boolean ) );
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// Allowed type specified by consumer.
|
|
76
|
-
const isAllowedType = ( fileType ) => {
|
|
77
|
-
if ( ! allowedTypes ) {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
return allowedTypes.some( ( allowedType ) => {
|
|
81
|
-
// If a complete mimetype is specified verify if it matches exactly the mime type of the file.
|
|
82
|
-
if ( allowedType.includes( '/' ) ) {
|
|
83
|
-
return allowedType === fileType;
|
|
84
|
-
}
|
|
85
|
-
// Otherwise a general mime type is used and we should verify if the file mimetype starts with it.
|
|
86
|
-
return fileType.startsWith( `${ allowedType }/` );
|
|
87
|
-
} );
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// Allowed types for the current WP_User.
|
|
91
|
-
const allowedMimeTypesForUser = getMimeTypesArray( wpAllowedMimeTypes );
|
|
92
|
-
const isAllowedMimeTypeForUser = ( fileType ) => {
|
|
93
|
-
return allowedMimeTypesForUser.includes( fileType );
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const validFiles = [];
|
|
97
|
-
|
|
98
|
-
for ( const mediaFile of files ) {
|
|
99
|
-
// Verify if user is allowed to upload this mime type.
|
|
100
|
-
// Defer to the server when type not detected.
|
|
101
|
-
if (
|
|
102
|
-
allowedMimeTypesForUser &&
|
|
103
|
-
mediaFile.type &&
|
|
104
|
-
! isAllowedMimeTypeForUser( mediaFile.type )
|
|
105
|
-
) {
|
|
106
|
-
onError( {
|
|
107
|
-
code: 'MIME_TYPE_NOT_ALLOWED_FOR_USER',
|
|
108
|
-
message: sprintf(
|
|
109
|
-
// translators: %s: file name.
|
|
110
|
-
__(
|
|
111
|
-
'%s: Sorry, you are not allowed to upload this file type.'
|
|
112
|
-
),
|
|
113
|
-
mediaFile.name
|
|
114
|
-
),
|
|
115
|
-
file: mediaFile,
|
|
116
|
-
} );
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Check if the block supports this mime type.
|
|
121
|
-
// Defer to the server when type not detected.
|
|
122
|
-
if ( mediaFile.type && ! isAllowedType( mediaFile.type ) ) {
|
|
123
|
-
onError( {
|
|
124
|
-
code: 'MIME_TYPE_NOT_SUPPORTED',
|
|
125
|
-
message: sprintf(
|
|
126
|
-
// translators: %s: file name.
|
|
127
|
-
__( '%s: Sorry, this file type is not supported here.' ),
|
|
128
|
-
mediaFile.name
|
|
129
|
-
),
|
|
130
|
-
file: mediaFile,
|
|
131
|
-
} );
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Verify if file is greater than the maximum file upload size allowed for the site.
|
|
136
|
-
if ( maxUploadFileSize && mediaFile.size > maxUploadFileSize ) {
|
|
137
|
-
onError( {
|
|
138
|
-
code: 'SIZE_ABOVE_LIMIT',
|
|
139
|
-
message: sprintf(
|
|
140
|
-
// translators: %s: file name.
|
|
141
|
-
__(
|
|
142
|
-
'%s: This file exceeds the maximum upload size for this site.'
|
|
143
|
-
),
|
|
144
|
-
mediaFile.name
|
|
145
|
-
),
|
|
146
|
-
file: mediaFile,
|
|
147
|
-
} );
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Don't allow empty files to be uploaded.
|
|
152
|
-
if ( mediaFile.size <= 0 ) {
|
|
153
|
-
onError( {
|
|
154
|
-
code: 'EMPTY_FILE',
|
|
155
|
-
message: sprintf(
|
|
156
|
-
// translators: %s: file name.
|
|
157
|
-
__( '%s: This file is empty.' ),
|
|
158
|
-
mediaFile.name
|
|
159
|
-
),
|
|
160
|
-
file: mediaFile,
|
|
161
|
-
} );
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
validFiles.push( mediaFile );
|
|
166
|
-
|
|
167
|
-
// Set temporary URL to create placeholder media file, this is replaced
|
|
168
|
-
// with final file from media gallery when upload is `done` below.
|
|
169
|
-
filesSet.push( { url: createBlobURL( mediaFile ) } );
|
|
170
|
-
onFileChange( filesSet );
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
for ( let idx = 0; idx < validFiles.length; ++idx ) {
|
|
174
|
-
const mediaFile = validFiles[ idx ];
|
|
175
|
-
try {
|
|
176
|
-
const savedMedia = await createMediaFromFile(
|
|
177
|
-
mediaFile,
|
|
178
|
-
additionalData
|
|
179
|
-
);
|
|
180
|
-
// eslint-disable-next-line camelcase
|
|
181
|
-
const { alt_text, source_url, ...savedMediaProps } = savedMedia;
|
|
182
|
-
const mediaObject = {
|
|
183
|
-
...savedMediaProps,
|
|
184
|
-
alt: savedMedia.alt_text,
|
|
185
|
-
caption: savedMedia.caption?.raw ?? '',
|
|
186
|
-
title: savedMedia.title.raw,
|
|
187
|
-
url: savedMedia.source_url,
|
|
188
|
-
};
|
|
189
|
-
setAndUpdateFiles( idx, mediaObject );
|
|
190
|
-
} catch ( error ) {
|
|
191
|
-
// Reset to empty on failure.
|
|
192
|
-
setAndUpdateFiles( idx, null );
|
|
193
|
-
let message;
|
|
194
|
-
if ( error.message ) {
|
|
195
|
-
message = error.message;
|
|
196
|
-
} else {
|
|
197
|
-
message = sprintf(
|
|
198
|
-
// translators: %s: file name
|
|
199
|
-
__( 'Error while uploading file %s to the media library.' ),
|
|
200
|
-
mediaFile.name
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
onError( {
|
|
204
|
-
code: 'GENERAL',
|
|
205
|
-
message,
|
|
206
|
-
file: mediaFile,
|
|
207
|
-
} );
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* @param {File} file Media File to Save.
|
|
214
|
-
* @param {?Object} additionalData Additional data to include in the request.
|
|
215
|
-
*
|
|
216
|
-
* @return {Promise} Media Object Promise.
|
|
217
|
-
*/
|
|
218
|
-
function createMediaFromFile( file, additionalData ) {
|
|
219
|
-
// Create upload payload.
|
|
220
|
-
const data = new window.FormData();
|
|
221
|
-
data.append( 'file', file, file.name || file.type.replace( '/', '.' ) );
|
|
222
|
-
if ( additionalData ) {
|
|
223
|
-
Object.entries( additionalData ).forEach( ( [ key, value ] ) =>
|
|
224
|
-
data.append( key, value )
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
return apiFetch( {
|
|
228
|
-
path: '/wp/v2/media',
|
|
229
|
-
body: data,
|
|
230
|
-
method: 'POST',
|
|
231
|
-
} );
|
|
232
|
-
}
|