in lib/api.ts [187:218]
await retry(
async () => {
const response = await fetch(
`https://api.figma.com/v1/images/${page.fileKey}?ids=${page.id}&format=png&scale=1`,
{
headers: {
"X-FIGMA-TOKEN": process.env.FIGMA_AUTH_TOKEN,
},
}
);
const contentType = response.headers.get("Content-Type");
if (contentType === "application/json; charset=utf-8") {
const json = await response.json();
if (json.images && json.images[page.id]) {
const imageUrl = json.images[page.id];
console.log(`Image generation for [${page.key}] was successful!`);
try {
const dimensions = await saveImageToDisk(imageUrl, page.key);
image.height = dimensions.height;
image.width = dimensions.width;
console.log("Image saved to disk successfully.");
} catch (er) {
console.log(`There was a problem saving the image to disk.`);
console.log(er);
}
} else {
throw new Error(JSON.stringify(json));
}
} else {
throw new Error(await response.text());
}
},