fix(deps): patch rss-parser to support gzip (#20619)

This commit is contained in:
Tony
2025-12-03 04:11:56 +08:00
committed by GitHub
parent f6c7483ea6
commit a64a33f132
4 changed files with 77 additions and 14 deletions

View File

@@ -17,6 +17,7 @@ RUN \
fi;
COPY ./tsconfig.json /app/
COPY ./patches /app/patches
COPY ./pnpm-lock.yaml /app/
COPY ./package.json /app/

View File

@@ -27,11 +27,10 @@
],
"scripts": {
"build": "npm run build:routes && tsdown",
"build:routes": "tsx scripts/workflow/build-routes.ts",
"build:vercel": "npm run build:routes && tsdown --config ./tsdown-vercel.config.ts && mv dist/server.mjs dist/index.mjs && tsx scripts/workflow/build-vercel-packagejson.ts",
"build:docs": "npm run build:routes && tsx scripts/workflow/build-docs.ts",
"build:lib": "npm run build:routes && tsdown --config ./tsdown-lib.config.ts",
"prepublishOnly": "npm run build:lib",
"build:routes": "tsx scripts/workflow/build-routes.ts",
"build:vercel": "npm run build:routes && tsdown --config ./tsdown-vercel.config.ts && mv dist/server.mjs dist/index.mjs && tsx scripts/workflow/build-vercel-packagejson.ts",
"dev": "cross-env NODE_ENV=dev NODE_OPTIONS='--max-http-header-size=32768' tsx watch --inspect --clear-screen=false lib/index.ts",
"dev:cache": "cross-env NODE_ENV=production NODE_OPTIONS='--max-http-header-size=32768' tsx watch --clear-screen=false lib/index.ts",
"format": "eslint --cache --fix \"**/*.{ts,tsx,js,yml}\" --concurrency auto && prettier . --write --experimental-cli",
@@ -39,6 +38,7 @@
"format:staged": "lint-staged",
"lint": "eslint --cache . --concurrency auto",
"prepare": "husky || true",
"prepublishOnly": "npm run build:lib",
"profiling": "cross-env NODE_ENV=production tsx --prof lib/index.ts",
"start": "cross-env NODE_ENV=production NODE_OPTIONS='--max-http-header-size=32768' node dist/index.mjs",
"test": "npm run format:check && npm run vitest:coverage",
@@ -234,9 +234,15 @@
"google-play-scraper>tough-cookie": "^6.0.0",
"hasown": "npm:@nolyfill/hasown@^1",
"is-core-module": "npm:@nolyfill/is-core-module@^1",
"js-beautify@1.15.4>glob": "^10.5.0",
"rss-parser@3.13.0>entities": "^7.0.0",
"rss-parser@3.13.0>xml2js": "^0.6.2",
"safe-buffer": "npm:@nolyfill/safe-buffer@^1",
"safer-buffer": "npm:@nolyfill/safer-buffer@^1",
"side-channel": "npm:@nolyfill/side-channel@^1"
},
"patchedDependencies": {
"rss-parser@3.13.0": "patches/rss-parser@3.13.0.patch"
}
}
}

View File

@@ -0,0 +1,48 @@
diff --git a/lib/parser.js b/lib/parser.js
index 2852b5f9249a59adf8f51f3451181ac2c994bc54..50e16ca0a97c98d7048122d5427fe467058485fb 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -3,6 +3,7 @@ const http = require('http');
const https = require('https');
const xml2js = require('xml2js');
const url = require('url');
+const zlib = require('zlib');
const fields = require('./fields');
const utils = require('./utils');
@@ -88,14 +89,27 @@ class Parser {
return reject(new Error("Status code " + res.statusCode))
}
let encoding = utils.getEncodingFromContentType(res.headers['content-type']);
- res.setEncoding(encoding);
- res.on('data', (chunk) => {
- xml += chunk;
- });
- res.on('end', () => {
- return this.parseString(xml).then(resolve, reject);
- });
- })
+ const contentEncoding = (res.headers['content-encoding'] || '').toLowerCase();
+ if (contentEncoding === 'gzip') {
+ const gunzip = zlib.createGunzip();
+ const chunks = [];
+ gunzip.on('data', (chunk) => chunks.push(chunk));
+ gunzip.on('end', () => {
+ const decompressed = Buffer.concat(chunks).toString(encoding);
+ return this.parseString(decompressed).then(resolve, reject);
+ });
+ gunzip.on('error', reject);
+ res.pipe(gunzip);
+ } else {
+ res.setEncoding(encoding);
+ res.on('data', (chunk) => {
+ xml += chunk;
+ });
+ res.on('end', () => {
+ return this.parseString(xml).then(resolve, reject);
+ });
+ }
+ });
req.on('error', reject);
timeout = setTimeout(() => {
return reject(new Error("Request timed out after " + this.options.timeout + "ms"));

30
pnpm-lock.yaml generated
View File

@@ -13,10 +13,18 @@ overrides:
google-play-scraper>tough-cookie: ^6.0.0
hasown: npm:@nolyfill/hasown@^1
is-core-module: npm:@nolyfill/is-core-module@^1
js-beautify@1.15.4>glob: ^10.5.0
rss-parser@3.13.0>entities: ^7.0.0
rss-parser@3.13.0>xml2js: ^0.6.2
safe-buffer: npm:@nolyfill/safe-buffer@^1
safer-buffer: npm:@nolyfill/safer-buffer@^1
side-channel: npm:@nolyfill/side-channel@^1
patchedDependencies:
rss-parser@3.13.0:
hash: e1697dd9dde771024b5d0669a3eff6237e75fbac78381a6127012b67593bb2b7
path: patches/rss-parser@3.13.0.patch
importers:
.:
@@ -227,7 +235,7 @@ importers:
version: 1.5.4
rss-parser:
specifier: 3.13.0
version: 3.13.0
version: 3.13.0(patch_hash=e1697dd9dde771024b5d0669a3eff6237e75fbac78381a6127012b67593bb2b7)
sanitize-html:
specifier: 2.17.0
version: 2.17.0
@@ -3924,8 +3932,8 @@ packages:
resolution: {integrity: sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==}
engines: {node: '>=10.13.0'}
glob@10.4.5:
resolution: {integrity: sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==}
glob@10.5.0:
resolution: {integrity: sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==}
hasBin: true
glob@13.0.0:
@@ -6229,8 +6237,8 @@ packages:
resolution: {integrity: sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==}
engines: {node: '>=18'}
xml2js@0.5.0:
resolution: {integrity: sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==}
xml2js@0.6.2:
resolution: {integrity: sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==}
engines: {node: '>=4.0.0'}
xmlbuilder@11.0.1:
@@ -10093,7 +10101,7 @@ snapshots:
dependencies:
is-glob: 4.0.3
glob@10.4.5:
glob@10.5.0:
dependencies:
foreground-child: 3.3.1
jackspeak: 3.4.3
@@ -10535,7 +10543,7 @@ snapshots:
dependencies:
config-chain: 1.1.13
editorconfig: 1.0.4
glob: 10.4.5
glob: 10.5.0
js-cookie: 3.0.5
nopt: 7.2.1
@@ -11838,10 +11846,10 @@ snapshots:
'@rollup/rollup-win32-x64-msvc': 4.53.2
fsevents: 2.3.3
rss-parser@3.13.0:
rss-parser@3.13.0(patch_hash=e1697dd9dde771024b5d0669a3eff6237e75fbac78381a6127012b67593bb2b7):
dependencies:
entities: 2.2.0
xml2js: 0.5.0
entities: 7.0.0
xml2js: 0.6.2
run-parallel@1.2.0:
dependencies:
@@ -12643,7 +12651,7 @@ snapshots:
xml-name-validator@5.0.0: {}
xml2js@0.5.0:
xml2js@0.6.2:
dependencies:
sax: 1.4.1
xmlbuilder: 11.0.1