Add follow-redirects
Will probably switch to node-fetch when this project goes to ESM
This commit is contained in:
parent
fcfc6b72d8
commit
48b9273bfb
|
|
@ -9,10 +9,12 @@
|
||||||
"version": "110.0.0",
|
"version": "110.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.15.2",
|
||||||
"tar-fs": "^2.1.1"
|
"tar-fs": "^2.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsconfig/node14": "^1.0.3",
|
"@tsconfig/node14": "^1.0.3",
|
||||||
|
"@types/follow-redirects": "^1.14.1",
|
||||||
"@types/node": "^18.11.18",
|
"@types/node": "^18.11.18",
|
||||||
"@types/tar-fs": "^2.0.1",
|
"@types/tar-fs": "^2.0.1",
|
||||||
"clean-modules": "^2.0.6",
|
"clean-modules": "^2.0.6",
|
||||||
|
|
@ -28,6 +30,15 @@
|
||||||
"integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==",
|
"integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/@types/node": {
|
||||||
"version": "18.11.18",
|
"version": "18.11.18",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
|
||||||
|
|
@ -215,6 +226,25 @@
|
||||||
"node": ">=6"
|
"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": {
|
"node_modules/fs-constants": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,12 @@
|
||||||
"test": "make clean && make && make pretest && make test"
|
"test": "make clean && make && make pretest && make test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.15.2",
|
||||||
"tar-fs": "^2.1.1"
|
"tar-fs": "^2.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsconfig/node14": "^1.0.3",
|
"@tsconfig/node14": "^1.0.3",
|
||||||
|
"@types/follow-redirects": "^1.14.1",
|
||||||
"@types/node": "^18.11.18",
|
"@types/node": "^18.11.18",
|
||||||
"@types/tar-fs": "^2.0.1",
|
"@types/tar-fs": "^2.0.1",
|
||||||
"clean-modules": "^2.0.6",
|
"clean-modules": "^2.0.6",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
import { unlink } from "node:fs";
|
import { unlink } from "node:fs";
|
||||||
import { get } from "node:https";
|
import { https } from "follow-redirects";
|
||||||
import { tmpdir } from "node:os";
|
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) => {
|
export const isValidUrl = (input: string) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -13,9 +19,11 @@ export const isValidUrl = (input: string) => {
|
||||||
|
|
||||||
export const downloadAndExtract = async (url: string) =>
|
export const downloadAndExtract = async (url: string) =>
|
||||||
new Promise<string>((resolve, reject) => {
|
new Promise<string>((resolve, reject) => {
|
||||||
|
const getOptions = parse(url) as FollowRedirOptions;
|
||||||
|
getOptions.maxBodyLength = 60 * 1024 * 1024; // 60mb
|
||||||
const destDir = `${tmpdir()}/chromium-pack`
|
const destDir = `${tmpdir()}/chromium-pack`
|
||||||
const extractObj = extract(destDir)
|
const extractObj = extract(destDir)
|
||||||
get(url, (response) => {
|
https.get(url, (response) => {
|
||||||
response.pipe(extractObj);
|
response.pipe(extractObj);
|
||||||
extractObj.on('finish', () => {
|
extractObj.on('finish', () => {
|
||||||
resolve(destDir);
|
resolve(destDir);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue