diff --git a/.github/workflows/deploy-website-next.yml b/.github/workflows/deploy-website-next.yml index 504bbcdee4..a93f5bdbef 100644 --- a/.github/workflows/deploy-website-next.yml +++ b/.github/workflows/deploy-website-next.yml @@ -27,6 +27,7 @@ jobs: - uses: actions/checkout@v4 with: sparse-checkout: | + packages/php-wasm/universal/src/lib/mime-types.json packages/playground/website-deployment - name: Wait for latest build artifact shell: bash @@ -79,6 +80,11 @@ jobs: packages/playground/website-deployment/ \ ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }}:'~/website-deployment' + # Copy MIME types for use with PHP-served files + scp -i ~/.ssh/id_ed25519 \ + packages/php-wasm/universal/src/lib/mime-types.json \ + ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }}:'~/website-deployment/' + # Apply update ssh -i ~/.ssh/id_ed25519 \ ${{ secrets.DEPLOY_WEBSITE_TARGET_USER }}@${{ secrets.DEPLOY_WEBSITE_TARGET_HOST }} \ diff --git a/packages/php-wasm/universal/src/lib/mime-types.json b/packages/php-wasm/universal/src/lib/mime-types.json index c06cec272d..49116390f2 100644 --- a/packages/php-wasm/universal/src/lib/mime-types.json +++ b/packages/php-wasm/universal/src/lib/mime-types.json @@ -1,5 +1,5 @@ { - "_default": "application-octet-stream", + "_default": "application/octet-stream", "3gpp": "video/3gpp", "7z": "application/x-7z-compressed", "asx": "video/x-ms-asf", diff --git a/packages/playground/website-deployment/apply-update.sh b/packages/playground/website-deployment/apply-update.sh index 1062afa317..2ed0909c78 100755 --- a/packages/playground/website-deployment/apply-update.sh +++ b/packages/playground/website-deployment/apply-update.sh @@ -19,6 +19,45 @@ echo Copy supporting files for WP Cloud cp -r ~/website-deployment/__wp__ ~/website-update/ cp ~/website-deployment/custom-redirects-lib.php ~/website-update/ cp ~/website-deployment/custom-redirects.php ~/website-update/ + +# Generate mime-types.php from mime-types.json in case the PHP can be opcached +echo Generating mime-types.php +cat ~/website-deployment/mime-types.json | "$SITE_PHP" -r ' + $raw_json = file_get_contents( "php://stdin" ); + if ( false === $raw_json ) { + fprintf( STDERR, "Unable to read MIME type JSON\n" ); + die( -1 ); + } + $types = json_decode( $raw_json, JSON_OBJECT_AS_ARRAY ); + if ( null === $types ) { + fprintf( STDERR, "Unable to decode MIME type JSON\n" ); + die( -1 ); + } + + echo " $mime_type ) { + echo " \"$extension\" => \"$mime_type\",\n"; + } + echo ");\n"; +' > ~/website-deployment/mime-types.php + +echo Checking mime-types.php +( + cd ~/website-deployment + "$SITE_PHP" -r ' + require( "mime-types.php" ); + if ( + $mime_types["_default"] !== "application/octet-stream" || + $mime_types["html"] !== "text/html" || + $mime_types["jpeg"] !== "image/jpeg" + ) { + fprintf( STDERR, "mime-types.php looks broken\n" ); + die( -1 ); + } + ' +) +echo Adding mime-types.php to updated website files cp ~/website-deployment/mime-types.php ~/website-update/ function match_files_to_serve_via_php() ( diff --git a/packages/playground/website-deployment/custom-redirects-lib.php b/packages/playground/website-deployment/custom-redirects-lib.php index 60f257b1b7..b997520fa3 100644 --- a/packages/playground/website-deployment/custom-redirects-lib.php +++ b/packages/playground/website-deployment/custom-redirects-lib.php @@ -124,11 +124,9 @@ function playground_handle_request() { : false; require_once __DIR__ . '/mime-types.php'; - if ( isset( $mime_types[ $extension ] ) ) { - $content_type = $mime_types[ $extension ]; - $log( "Setting Content-Type to '$content_type'" ); - header( "Content-Type: $content_type" ); - } + $content_type = $mime_types[ $extension ] ?? $mime_types['_default']; + $log( "Setting Content-Type to '$content_type'" ); + header( "Content-Type: $content_type" ); $custom_response_headers = playground_get_custom_response_headers( $filename ); if ( ! empty( $custom_response_headers ) ) { diff --git a/packages/playground/website-deployment/mime-types.php b/packages/playground/website-deployment/mime-types.php deleted file mode 100644 index 1c99438aa4..0000000000 --- a/packages/playground/website-deployment/mime-types.php +++ /dev/null @@ -1,93 +0,0 @@ - 'video/3gpp', - '7z' => 'application/x-7z-compressed', - 'asx' => 'video/x-ms-asf', - 'atom' => 'application/atom+xml', - 'avi' => 'video/x-msvideo', - 'avif' => 'image/avif', - 'bin' => 'application/octet-stream', - 'bmp' => 'image/x-ms-bmp', - 'cco' => 'application/x-cocoa', - 'css' => 'text/css', - 'data' => 'application/octet-stream', - 'deb' => 'application/octet-stream', - 'der' => 'application/x-x509-ca-cert', - 'dmg' => 'application/octet-stream', - 'doc' => 'application/msword', - 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'eot' => 'application/vnd.ms-fontobject', - 'flv' => 'video/x-flv', - 'gif' => 'image/gif', - 'hqx' => 'application/mac-binhex40', - 'htc' => 'text/x-component', - 'html' => 'text/html', - 'ico' => 'image/x-icon', - 'iso' => 'application/octet-stream', - 'jad' => 'text/vnd.sun.j2me.app-descriptor', - 'jar' => 'application/java-archive', - 'jardiff' => 'application/x-java-archive-diff', - 'jng' => 'image/x-jng', - 'jnlp' => 'application/x-java-jnlp-file', - 'jpeg' => 'image/jpeg', - 'js' => 'application/javascript', - 'json' => 'application/json', - 'kml' => 'application/vnd.google-earth.kml+xml', - 'kmz' => 'application/vnd.google-earth.kmz', - 'm3u8' => 'application/vnd.apple.mpegurl', - 'm4a' => 'audio/x-m4a', - 'm4v' => 'video/x-m4v', - 'mid' => 'audio/midi', - 'mml' => 'text/mathml', - 'mng' => 'video/x-mng', - 'mov' => 'video/quicktime', - 'mp3' => 'audio/mpeg', - 'mp4' => 'video/mp4', - 'mpeg' => 'video/mpeg', - 'msi' => 'application/octet-stream', - 'odg' => 'application/vnd.oasis.opendocument.graphics', - 'odp' => 'application/vnd.oasis.opendocument.presentation', - 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', - 'odt' => 'application/vnd.oasis.opendocument.text', - 'ogg' => 'audio/ogg', - 'pdf' => 'application/pdf', - 'pl' => 'application/x-perl', - 'png' => 'image/png', - 'ppt' => 'application/vnd.ms-powerpoint', - 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'prc' => 'application/x-pilot', - 'ps' => 'application/postscript', - 'ra' => 'audio/x-realaudio', - 'rar' => 'application/x-rar-compressed', - 'rpm' => 'application/x-redhat-package-manager', - 'rss' => 'application/rss+xml', - 'rtf' => 'application/rtf', - 'run' => 'application/x-makeself', - 'sea' => 'application/x-sea', - 'sit' => 'application/x-stuffit', - 'svg' => 'image/svg+xml', - 'swf' => 'application/x-shockwave-flash', - 'tcl' => 'application/x-tcl', - 'tif' => 'image/tiff', - 'ts' => 'video/mp2t', - 'txt' => 'text/plain', - 'wasm' => 'application/wasm', - 'wbmp' => 'image/vnd.wap.wbmp', - 'webm' => 'video/webm', - 'webp' => 'image/webp', - 'wml' => 'text/vnd.wap.wml', - 'wmlc' => 'application/vnd.wap.wmlc', - 'wmv' => 'video/x-ms-wmv', - 'woff' => 'font/woff', - 'woff2' => 'font/woff2', - 'xhtml' => 'application/xhtml+xml', - 'xls' => 'application/vnd.ms-excel', - 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'xml' => 'text/xml', - 'xpi' => 'application/x-xpinstall', - 'xspf' => 'application/xspf+xml', - 'zip' => 'application/zip', -); -