Skip to content

Commit

Permalink
fix: spoof user agent to avoid occasional blocks
Browse files Browse the repository at this point in the history
fixes #89
  • Loading branch information
lightpohl committed Nov 7, 2024
1 parent bddda47 commit 494c74b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bin/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
const pipeline = promisify(stream.pipeline);

const BYTES_IN_MB = 1000000;
const USER_AGENT =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36";

const download = async (options) => {
const {
Expand Down Expand Up @@ -67,6 +69,7 @@ const download = async (options) => {
responseType: "json",
headers: {
accept: "*/*",
"user-agent": USER_AGENT,
},
});
} catch (error) {
Expand Down Expand Up @@ -108,7 +111,9 @@ const download = async (options) => {
});

await pipeline(
got.stream(url).on("downloadProgress", onDownloadProgress),
got
.stream(url, { headers: { "user-agent": USER_AGENT } })
.on("downloadProgress", onDownloadProgress),
fs.createWriteStream(tempOutputPath)
);
} catch (error) {
Expand Down

0 comments on commit 494c74b

Please sign in to comment.