diff --git a/package-lock.json b/package-lock.json index 9fdb075601..0123a08078 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,6 @@ "date-fns": "^3.3.1", "electron-squirrel-startup": "^1.0.0", "express": "4.19.2", - "express-fileupload": "1.4.0", "file-stream-rotator": "^1.0.0", "follow-redirects": "1.15.6", "fs-extra": "11.1.1", @@ -55,7 +54,6 @@ "@timfish/forge-externals-plugin": "^0.2.1", "@types/archiver": "^6.0.2", "@types/ejs": "^3.1.5", - "@types/express-fileupload": "1.5.0", "@types/jest": "^29.5.11", "@types/react": "^18.2.42", "@types/react-dom": "^18.2.17", @@ -5249,15 +5247,6 @@ "@types/node": "*" } }, - "node_modules/@types/busboy": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/@types/busboy/-/busboy-1.5.3.tgz", - "integrity": "sha512-YMBLFN/xBD8bnqywIlGyYqsNFXu6bsiY7h3Ae0kO17qEuTjsqeyYMRPSUDacIKIquws2Y6KjmxAyNx8xB3xQbw==", - "dev": true, - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/cacheable-request": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.3.tgz", @@ -5330,16 +5319,6 @@ "@types/serve-static": "*" } }, - "node_modules/@types/express-fileupload": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@types/express-fileupload/-/express-fileupload-1.5.0.tgz", - "integrity": "sha512-Y9v88IC5ItAxkKwfnyIi1y0jSZwTMY4jqXUQLZ3jFhYJlLdRnN919bKBNM8jbVVD2cxywA/uEC1kNNpZQGwx7Q==", - "dev": true, - "dependencies": { - "@types/busboy": "*", - "@types/express": "*" - } - }, "node_modules/@types/express-serve-static-core": { "version": "4.17.42", "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.42.tgz", @@ -7681,17 +7660,6 @@ "resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-2.0.0.tgz", "integrity": "sha512-8KPx+JfZWi0K8L5sycIOA6/ZFZbaFKXDeUIXaqwUnhed1Ge1cB0wyq+bNDjKnL9AR2Uj3m/khkF6CDolsyMitA==" }, - "node_modules/busboy": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", - "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", - "dependencies": { - "streamsearch": "^1.1.0" - }, - "engines": { - "node": ">=10.16.0" - } - }, "node_modules/bytes": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", @@ -10534,17 +10502,6 @@ "node": ">= 0.10.0" } }, - "node_modules/express-fileupload": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-1.4.0.tgz", - "integrity": "sha512-RjzLCHxkv3umDeZKeFeMg8w7qe0V09w3B7oGZprr/oO2H/ISCgNzuqzn7gV3HRWb37GjRk429CCpSLS2KNTqMQ==", - "dependencies": { - "busboy": "^1.6.0" - }, - "engines": { - "node": ">=12.0.0" - } - }, "node_modules/express-ws": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/express-ws/-/express-ws-5.0.2.tgz", @@ -18200,14 +18157,6 @@ "node": ">= 0.10.0" } }, - "node_modules/streamsearch": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", - "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", - "engines": { - "node": ">=10.0.0" - } - }, "node_modules/streamx": { "version": "2.15.6", "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.6.tgz", @@ -24429,15 +24378,6 @@ "@types/node": "*" } }, - "@types/busboy": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/@types/busboy/-/busboy-1.5.3.tgz", - "integrity": "sha512-YMBLFN/xBD8bnqywIlGyYqsNFXu6bsiY7h3Ae0kO17qEuTjsqeyYMRPSUDacIKIquws2Y6KjmxAyNx8xB3xQbw==", - "dev": true, - "requires": { - "@types/node": "*" - } - }, "@types/cacheable-request": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.3.tgz", @@ -24510,16 +24450,6 @@ "@types/serve-static": "*" } }, - "@types/express-fileupload": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@types/express-fileupload/-/express-fileupload-1.5.0.tgz", - "integrity": "sha512-Y9v88IC5ItAxkKwfnyIi1y0jSZwTMY4jqXUQLZ3jFhYJlLdRnN919bKBNM8jbVVD2cxywA/uEC1kNNpZQGwx7Q==", - "dev": true, - "requires": { - "@types/busboy": "*", - "@types/express": "*" - } - }, "@types/express-serve-static-core": { "version": "4.17.42", "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.42.tgz", @@ -26358,14 +26288,6 @@ "resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-2.0.0.tgz", "integrity": "sha512-8KPx+JfZWi0K8L5sycIOA6/ZFZbaFKXDeUIXaqwUnhed1Ge1cB0wyq+bNDjKnL9AR2Uj3m/khkF6CDolsyMitA==" }, - "busboy": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", - "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", - "requires": { - "streamsearch": "^1.1.0" - } - }, "bytes": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", @@ -28516,14 +28438,6 @@ } } }, - "express-fileupload": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-1.4.0.tgz", - "integrity": "sha512-RjzLCHxkv3umDeZKeFeMg8w7qe0V09w3B7oGZprr/oO2H/ISCgNzuqzn7gV3HRWb37GjRk429CCpSLS2KNTqMQ==", - "requires": { - "busboy": "^1.6.0" - } - }, "express-ws": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/express-ws/-/express-ws-5.0.2.tgz", @@ -34223,11 +34137,6 @@ "integrity": "sha512-uyQK/mx5QjHun80FLJTfaWE7JtwfRMKBLkMne6udYOmvH0CawotVa7TfgYHzAnpphn4+TweIx1QKMnRIbipmUg==", "optional": true }, - "streamsearch": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", - "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==" - }, "streamx": { "version": "2.15.6", "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.6.tgz", diff --git a/package.json b/package.json index 5505af83ae..c22ec70c3a 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "@timfish/forge-externals-plugin": "^0.2.1", "@types/archiver": "^6.0.2", "@types/ejs": "^3.1.5", - "@types/express-fileupload": "1.5.0", "@types/jest": "^29.5.11", "@types/react": "^18.2.42", "@types/react-dom": "^18.2.17", @@ -108,7 +107,6 @@ "date-fns": "^3.3.1", "electron-squirrel-startup": "^1.0.0", "express": "4.19.2", - "express-fileupload": "1.4.0", "file-stream-rotator": "^1.0.0", "follow-redirects": "1.15.6", "fs-extra": "11.1.1", diff --git a/vendor/wp-now/src/encode-as-multipart.ts b/vendor/wp-now/src/encode-as-multipart.ts deleted file mode 100644 index 7cd8d6d32f..0000000000 --- a/vendor/wp-now/src/encode-as-multipart.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Encodes the Express request with files into multipart/form-data request body. - * Adaptation of https://github.com/WordPress/wordpress-playground/blob/45bf16970867cc6f23738224dacf201905adcab6/packages/php-wasm/universal/src/lib/encode-as-multipart.ts - */ -export async function encodeAsMultipart( req: Express.Request ) { - const boundary = `----${ Math.random().toString( 36 ).slice( 2 ) }`; - const contentType = `multipart/form-data; boundary=${ boundary }`; - - const textEncoder = new TextEncoder(); - const parts: ( string | Uint8Array )[] = []; - const data = ( req as any ).body as Record< string, string >; - for ( const [ name, value ] of Object.entries( data ) ) { - parts.push( `--${ boundary }\r\n` ); - parts.push( `Content-Disposition: form-data; name="${ name }"` ); - parts.push( `\r\n` ); - parts.push( `\r\n` ); - parts.push( textEncoder.encode(value) ); - parts.push( `\r\n` ); - } - const files = req.files; - for ( const [ name, value ] of Object.entries( files ) ) { - if ( ! Array.isArray( value ) ) { - parts.push( `--${ boundary }\r\n` ); - parts.push( `Content-Disposition: form-data; name="${ name }"` ); - parts.push( ...['; filename="', textEncoder.encode(value.name), '"' ] ); - parts.push( `\r\n` ); - parts.push( `Content-Type: ${ value.mimetype }` ); - parts.push( `\r\n` ); - parts.push( `\r\n` ); - parts.push( value.data ); - parts.push( `\r\n` ); - } - } - parts.push( `--${ boundary }--\r\n` ); - - const length = parts.reduce( ( acc, part ) => acc + part.length, 0 ); - const bytes = new Uint8Array( length ); - let offset = 0; - for ( const part of parts ) { - bytes.set( typeof part === 'string' ? textEncoder.encode( part ) : part, offset ); - offset += part.length; - } - - return { bytes, contentType }; -} diff --git a/vendor/wp-now/src/start-server.ts b/vendor/wp-now/src/start-server.ts index 9de5b0a075..267363a90d 100644 --- a/vendor/wp-now/src/start-server.ts +++ b/vendor/wp-now/src/start-server.ts @@ -4,13 +4,11 @@ import { HTTPMethod } from '@php-wasm/universal'; import express from 'express'; import compression from 'compression'; import compressible from 'compressible'; -import fileUpload from 'express-fileupload'; import { portFinder } from './port-finder'; import { NodePHP } from '@php-wasm/node'; import startWPNow from './wp-now'; import { output } from './output'; import { addTrailingSlash } from './add-trailing-slash'; -import { encodeAsMultipart } from './encode-as-multipart'; const requestBodyToBytes = async ( req ): Promise< Uint8Array > => await new Promise( ( resolve ) => { @@ -45,7 +43,6 @@ export async function startServer( ); } const app = express(); - app.use(fileUpload({ defCharset: 'utf8', defParamCharset: 'utf8'})); app.use(compression({ filter: shouldCompress })); app.use(addTrailingSlash('/wp-admin')); const port = options.port ?? await portFinder.getOpenPort(); @@ -61,19 +58,11 @@ export async function startServer( } } - let body: Uint8Array; - if ( requestHeaders[ 'content-type' ]?.startsWith( 'multipart/form-data' ) ) { - const multipart = await encodeAsMultipart( req ); - body = multipart.bytes; - requestHeaders[ 'content-type' ] = multipart.contentType; - } else { - body = await requestBodyToBytes( req ); - } const data = { url: req.url, headers: requestHeaders, method: req.method as HTTPMethod, - body, + body: await requestBodyToBytes( req ), }; const resp = await php.request(data); res.statusCode = resp.httpStatusCode;