Merge pull request #57 from Sparticuz/fix/followRedirects

This commit is contained in:
Kyle McNally 2023-02-10 14:03:17 -05:00 committed by GitHub
commit b077bd9340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 4 deletions

View File

@ -17,7 +17,7 @@ test:
npm install --fund=false --package-lock=false
npm run build
mkdir -p nodejs
npm install --prefix nodejs/ tar-fs@2.1.1 --bin-links=false --fund=false --omit=optional --omit=dev --package-lock=false --save=false
npm install --prefix nodejs/ tar-fs@2.1.1 follow-redirects@1.15.2 --bin-links=false --fund=false --omit=optional --omit=dev --package-lock=false --save=false
npm pack
mkdir -p nodejs/node_modules/@sparticuz/chromium/
tar --directory nodejs/node_modules/@sparticuz/chromium/ --extract --file sparticuz-chromium-*.tgz --strip-components=1

30
package-lock.json generated
View File

@ -9,10 +9,12 @@
"version": "110.0.0",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.2",
"tar-fs": "^2.1.1"
},
"devDependencies": {
"@tsconfig/node14": "^1.0.3",
"@types/follow-redirects": "^1.14.1",
"@types/node": "^18.11.18",
"@types/tar-fs": "^2.0.1",
"clean-modules": "^2.0.6",
@ -28,6 +30,15 @@
"integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==",
"dev": true
},
"node_modules/@types/follow-redirects": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/@types/follow-redirects/-/follow-redirects-1.14.1.tgz",
"integrity": "sha512-THBEFwqsLuU/K62B5JRwab9NW97cFmL4Iy34NTMX0bMycQVzq2q7PKOkhfivIwxdpa/J72RppgC42vCHfwKJ0Q==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/node": {
"version": "18.11.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
@ -215,6 +226,25 @@
"node": ">=6"
}
},
"node_modules/follow-redirects": {
"version": "1.15.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/fs-constants": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",

View File

@ -36,10 +36,12 @@
"test": "make clean && make && make pretest && make test"
},
"dependencies": {
"follow-redirects": "^1.15.2",
"tar-fs": "^2.1.1"
},
"devDependencies": {
"@tsconfig/node14": "^1.0.3",
"@types/follow-redirects": "^1.14.1",
"@types/node": "^18.11.18",
"@types/tar-fs": "^2.0.1",
"clean-modules": "^2.0.6",

View File

@ -1,7 +1,13 @@
import { unlink } from "node:fs";
import { get } from "node:https";
import { https } from "follow-redirects";
import { tmpdir } from "node:os";
import { extract } from 'tar-fs';
import { extract } from "tar-fs";
import { parse } from "node:url";
import type { UrlWithStringQuery } from "node:url";
interface FollowRedirOptions extends UrlWithStringQuery {
maxBodyLength: number;
}
export const isValidUrl = (input: string) => {
try {
@ -13,9 +19,11 @@ export const isValidUrl = (input: string) => {
export const downloadAndExtract = async (url: string) =>
new Promise<string>((resolve, reject) => {
const getOptions = parse(url) as FollowRedirOptions;
getOptions.maxBodyLength = 60 * 1024 * 1024; // 60mb
const destDir = `${tmpdir()}/chromium-pack`
const extractObj = extract(destDir)
get(url, (response) => {
https.get(url, (response) => {
response.pipe(extractObj);
extractObj.on('finish', () => {
resolve(destDir);