From 0da3f0a7a4960fe832b97c17754032ead2dbd620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 16 Apr 2024 11:43:02 +0200 Subject: [PATCH] WXR Import: Allow media files from wpthemetestdata.files.wordpress.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enables fully importing the Theme Unit Testing WXR file by tunneling all the media files through plugin-proxy.php. This PR, unfortunately, cannot be merged – there is so many media files that the import takes more than 15 minutes to complete (I actually gave up at the 15 minute mark). We'll need to resolve https://github.com/WordPress/blueprints-library/issues/100 first --- packages/playground/blueprints/src/lib/steps/import-wxr.ts | 4 ++++ .../remote/src/lib/setup-fetch-network-transport.ts | 6 +++++- packages/playground/website/public/plugin-proxy.php | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/playground/blueprints/src/lib/steps/import-wxr.ts b/packages/playground/blueprints/src/lib/steps/import-wxr.ts index dc1de5ee5d..c796fb8d8c 100644 --- a/packages/playground/blueprints/src/lib/steps/import-wxr.ts +++ b/packages/playground/blueprints/src/lib/steps/import-wxr.ts @@ -42,6 +42,10 @@ export const importWxr: StepHandler> = async ( await playground.run({ code: ` 'Administrator') )[0]; $importer = new WXR_Importer( array( diff --git a/packages/playground/remote/src/lib/setup-fetch-network-transport.ts b/packages/playground/remote/src/lib/setup-fetch-network-transport.ts index 03acdd9e7a..52bc47f980 100644 --- a/packages/playground/remote/src/lib/setup-fetch-network-transport.ts +++ b/packages/playground/remote/src/lib/setup-fetch-network-transport.ts @@ -64,7 +64,11 @@ export async function setupFetchNetworkTransport(playground: UniversalPHP) { export async function handleRequest(data: RequestData, fetchFn = fetch) { const hostname = new URL(data.url).hostname; - const fetchUrl = ['w.org', 's.w.org'].includes(hostname) + const fetchUrl = [ + 'w.org', + 's.w.org', + 'wpthemetestdata.files.wordpress.com', + ].includes(hostname) ? `/plugin-proxy.php?url=${encodeURIComponent(data.url)}` : data.url; diff --git a/packages/playground/website/public/plugin-proxy.php b/packages/playground/website/public/plugin-proxy.php index f6da2c3e9e..ab8cf0159f 100644 --- a/packages/playground/website/public/plugin-proxy.php +++ b/packages/playground/website/public/plugin-proxy.php @@ -338,7 +338,7 @@ function ($curl, $body) use (&$extra_headers_sent, $default_response_headers) { // Proxy the current request to $_GET['url'] and return the response, // but only if the URL is allowlisted. $url = $_GET['url']; - $allowed_domains = ['api.wordpress.org', 'w.org', 'wordpress.org', 's.w.org']; + $allowed_domains = ['api.wordpress.org', 'w.org', 'wordpress.org', 's.w.org', 'wpthemetestdata.files.wordpress.com']; $parsed_url = parse_url($url); if (!in_array($parsed_url['host'], $allowed_domains)) { http_response_code(403);