Add coexistence checks to all enqueue methods to prevent loading both React and Grid.js assets simultaneously. Changes: - ReactAdmin.php: Only enqueue React assets when ?react=1 - Init.php: Skip Grid.js when React active on admin pages - Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0 - Customer.php, Product.php, License.php: Add coexistence checks Now the toggle between Classic and React versions works correctly. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
83 lines
2.4 KiB
JavaScript
83 lines
2.4 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
var _i18n = require("@wordpress/i18n");
|
|
var _response = require("../utils/response");
|
|
/**
|
|
* WordPress dependencies
|
|
*/
|
|
|
|
/**
|
|
* Internal dependencies
|
|
*/
|
|
|
|
/**
|
|
* @param {import('../types').APIFetchOptions} options
|
|
* @return {boolean} True if the request is for media upload.
|
|
*/
|
|
function isMediaUploadRequest(options) {
|
|
const isCreateMethod = !!options.method && options.method === 'POST';
|
|
const isMediaEndpoint = !!options.path && options.path.indexOf('/wp/v2/media') !== -1 || !!options.url && options.url.indexOf('/wp/v2/media') !== -1;
|
|
return isMediaEndpoint && isCreateMethod;
|
|
}
|
|
|
|
/**
|
|
* Middleware handling media upload failures and retries.
|
|
*
|
|
* @type {import('../types').APIFetchMiddleware}
|
|
*/
|
|
const mediaUploadMiddleware = (options, next) => {
|
|
if (!isMediaUploadRequest(options)) {
|
|
return next(options);
|
|
}
|
|
let retries = 0;
|
|
const maxRetries = 5;
|
|
|
|
/**
|
|
* @param {string} attachmentId
|
|
* @return {Promise<any>} Processed post response.
|
|
*/
|
|
const postProcess = attachmentId => {
|
|
retries++;
|
|
return next({
|
|
path: `/wp/v2/media/${attachmentId}/post-process`,
|
|
method: 'POST',
|
|
data: {
|
|
action: 'create-image-subsizes'
|
|
},
|
|
parse: false
|
|
}).catch(() => {
|
|
if (retries < maxRetries) {
|
|
return postProcess(attachmentId);
|
|
}
|
|
next({
|
|
path: `/wp/v2/media/${attachmentId}?force=true`,
|
|
method: 'DELETE'
|
|
});
|
|
return Promise.reject();
|
|
});
|
|
};
|
|
return next({
|
|
...options,
|
|
parse: false
|
|
}).catch(response => {
|
|
const attachmentId = response.headers.get('x-wp-upload-attachment-id');
|
|
if (response.status >= 500 && response.status < 600 && attachmentId) {
|
|
return postProcess(attachmentId).catch(() => {
|
|
if (options.parse !== false) {
|
|
return Promise.reject({
|
|
code: 'post_process',
|
|
message: (0, _i18n.__)('Media upload failed. If this is a photo or a large image, please scale it down and try again.')
|
|
});
|
|
}
|
|
return Promise.reject(response);
|
|
});
|
|
}
|
|
return (0, _response.parseAndThrowError)(response, options.parse);
|
|
}).then(response => (0, _response.parseResponseAndNormalizeError)(response, options.parse));
|
|
};
|
|
var _default = exports.default = mediaUploadMiddleware;
|
|
//# sourceMappingURL=media-upload.js.map
|