mirror of
https://github.com/WordPress/create-block-theme.git
synced 2025-10-03 16:11:13 +08:00
Quality: Fix warning error when exporting theme (#671)
This commit is contained in:
parent
ddf7459282
commit
58fed318c7
2 changed files with 7 additions and 21 deletions
|
@ -308,6 +308,7 @@ class CBT_Theme_API {
|
|||
header( 'Content-Length: ' . filesize( $filename ) );
|
||||
flush();
|
||||
echo readfile( $filename );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
import { downloadBlob } from '@wordpress/blob';
|
||||
|
||||
/*
|
||||
* Download a file from in a browser.
|
||||
*
|
||||
|
@ -9,25 +14,5 @@ export default async function downloadFile( response ) {
|
|||
const filename = response.headers
|
||||
.get( 'Content-Disposition' )
|
||||
.split( 'filename=' )[ 1 ];
|
||||
|
||||
// Check if the browser supports navigator.msSaveBlob or navigator.saveBlob
|
||||
if ( window.navigator.msSaveBlob || window.navigator.saveBlob ) {
|
||||
const saveBlob =
|
||||
window.navigator.msSaveBlob || window.navigator.saveBlob;
|
||||
saveBlob.call( window.navigator, blob, filename );
|
||||
} else {
|
||||
// Fall back to creating an object URL and triggering a download using an anchor element
|
||||
const url = URL.createObjectURL( blob );
|
||||
|
||||
const a = document.createElement( 'a' );
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild( a );
|
||||
a.click();
|
||||
document.body.removeChild( a );
|
||||
|
||||
setTimeout( () => {
|
||||
URL.revokeObjectURL( url );
|
||||
}, 100 );
|
||||
}
|
||||
downloadBlob( filename, blob, 'application/zip' );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue