Skip to content

Commit

Permalink
Merge pull request #1 from MicroCBer/patch-1
Browse files Browse the repository at this point in the history
fix: fix binary file downloads
  • Loading branch information
rdwz authored Sep 26, 2023
2 parents 900b0df + dc2334d commit 6a5df76
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ async function main() {
const deploymentId = VERCEL_DEPLOYMENT.startsWith("dpl_")
? VERCEL_DEPLOYMENT
: await oraPromise(
getDeploymentId(VERCEL_DEPLOYMENT),
"Getting deployment id"
);
getDeploymentId(VERCEL_DEPLOYMENT),
"Getting deployment id"
);
const srcFiles = await oraPromise(
getDeploymentSource(deploymentId),
"Loading source files tree"
Expand Down Expand Up @@ -78,17 +78,18 @@ async function getDeploymentId(domain) {
async function downloadFile(deploymentId, fileId, destination) {
let path = `/v6/deployments/${deploymentId}/files/${fileId}`;
if (VERCEL_TEAM) path += `?teamId=${VERCEL_TEAM}`;
const response = await getFromAPI(path);
const response = await getFromAPI(path, true);
return new Promise((resolve, reject) => {
fs.writeFile(destination, response.body, function (err) {
if (err) reject(err);
resolve();
});
const writeStream = fs.createWriteStream(destination);
response.pipe(writeStream);
response.on('error', reject);
writeStream.on('error', reject);
writeStream.on("finish", resolve);
});
}

function getFromAPI(path) {
return got(`https://api.vercel.com${path}`, {
function getFromAPI(path, binary = false) {
return (binary ? got.stream : got)(`https://api.vercel.com${path}`, {
headers: {
Authorization: `Bearer ${VERCEL_TOKEN}`,
},
Expand Down

0 comments on commit 6a5df76

Please sign in to comment.