Last active
October 28, 2021 08:03
-
-
Save BobD/933624b93caf605965efea864f2b01fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { exec } = require("child_process"); | |
const inputChunks = []; | |
process.stdin.resume(); | |
process.stdin.setEncoding("utf8"); | |
process.stdin.on("data", (chunk) => inputChunks.push(chunk)); | |
process.stdin.on("end", function () { | |
const inputJSON = inputChunks.join(""); | |
const prismicData = JSON.parse(inputJSON); | |
const curlCommand = getCurlToDownloadAllImages(prismicData); | |
exec(curlCommand); | |
}); | |
function getCurlToDownloadAllImages(data) { | |
const { results: entries } = data; | |
const allImageUrls = []; | |
for (const entry of entries) { | |
const { | |
data: { | |
image: { url }, | |
}, | |
} = entry; | |
if (!url) { | |
continue; | |
} | |
allImageUrls.push(url.slice(0, url.indexOf("?auto=compress,format"))); | |
} | |
return `curl ${[...new Set(allImageUrls)] | |
.map((url) => ` -O ${url}`) | |
.join("")}`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment