Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidMount() {
const { attributes, setAttributes } = this.props;
// This will warn when we have `id` defined, while `url` is undefined.
// This may help track this issue: https://github.com/wordpress-mobile/WordPress-Android/issues/9768
// where a cancelled image upload was resulting in a subsequent crash.
if ( attributes.id && ! attributes.url ) {
// eslint-disable-next-line no-console
console.warn( 'Attributes has id with no url.' );
}
if ( attributes.id && attributes.url && ! isURL( attributes.url ) ) {
if ( attributes.url.indexOf( 'file:' ) === 0 ) {
requestMediaImport( attributes.url, ( mediaId, mediaUri ) => {
if ( mediaUri ) {
setAttributes( { url: mediaUri, id: mediaId } );
}
} );
}
mediaUploadSync();
}
}
if ( onReplace && isEmpty( value ) ) {
onReplace( content );
} else {
splitValue( value, content );
}
return;
}
let mode = onReplace && onSplit ? 'AUTO' : 'INLINE';
if (
__unstableEmbedURLOnPaste &&
isEmpty( value ) &&
isURL( plainText.trim() )
) {
mode = 'BLOCKS';
}
const content = pasteHandler( {
HTML: html,
plainText,
mode,
tagName,
canUserUseUnfilteredHTML,
} );
if ( typeof content === 'string' ) {
let valueToInsert = create( { html: content } );
// If there are active formats, merge them with the pasted formats.
jQuery( wizardError[0] ).text( '' );
// Verify Title and Site URL fields are non-empty.
const validateTitle = validateField( jQuery( titleField ), event );
const validateURL = validateField( jQuery( externalSiteUrlField ), event );
if (
! validateTitle ||
! validateURL
) {
event.preventDefault();
return false;
}
let siteURL = prependHTTP( externalSiteUrlField.value );
if ( ! isURL( siteURL ) ) {
jQuery( wizardError[0] ).text( dt.invalid_url );
return false;
}
// Show the spinner and loading message.
wizardStatus.style.display = 'block';
// Remove wp-json from URL, if that was added
siteURL = siteURL.replace( /wp-json(\/)*/, '' );
// Ensure URL ends with trailing slash
siteURL = siteURL.replace( /\/?$/, '/' );
jQuery.ajax( {
url: ajaxurl,
method: 'post',
onMediaPressed() {
const { mediaId, mediaUrl } = this.props;
if ( this.state.isUploadInProgress ) {
requestImageUploadCancelDialog( mediaId );
} else if ( mediaId && ! isURL( mediaUrl ) ) {
requestImageFailedRetryDialog( mediaId );
}
}
addLink() {
const { value, onChange } = this.props;
const text = getTextContent( slice( value ) );
if ( text && isURL( text ) ) {
onChange( applyFormat( value, { type: name, attributes: { url: text } } ) );
} else {
this.setState( { addingLink: true } );
}
}
event => {
event.preventDefault();
removeAllNotices();
if ( ! editedUrl ) {
return;
}
/*
* Ensure URL has `http` appended to it (if it doesn't already) before we
* accept it as the entered URL.
*/
const prependedURL = prependHTTP( editedUrl );
if ( ! isURL( prependedURL ) ) {
createErrorNotice(
__( "Your podcast couldn't be embedded. Please double check your URL.", 'jetpack' )
);
return;
}
/*
* Short-circuit feed fetching if we tried before, use useEffect otherwise.
* @see {@link https://github.com/Automattic/jetpack/pull/15213}
*/
if ( prependedURL === url ) {
fetchFeed( url );
} else {
setAttributes( { url: prependedURL } );
}
renderVideo( params, openMediaOptions ) {
const { mediaUrl, isSelected } = this.props;
const { isUploadInProgress } = this.state;
const { isUploadFailed, retryMessage } = params;
const showVideo = isURL( mediaUrl ) && ! isUploadInProgress && ! isUploadFailed;
return (
onChangeSearchInput( value ) {
this.setState( {
isUrlInput: isURL( value ),
currentSearchInput: value,
} );
}
onMediaPressed() {
const { id, url } = this.props;
this.onSelectImage();
if ( this.state.isUploadInProgress ) {
requestImageUploadCancelDialog( id );
} else if ( ( this.state.didUploadFail ) || ( id && ! isURL( url ) ) ) {
requestImageFailedRetryDialog( id );
}
}