Changes
2 changed files (+41/-3)
-
-
@@ -3,5 +3,39 @@export async function fetchFile(client, fileKey) { const fileResponse = await client.file(fileKey); return fileResponse.data; const frames = listAllFrames(fileResponse.data.document); const imageResponse = await client.fileImages(fileKey, { ids: frames.map((frame) => frame.id), scale: 1, format: "svg", }); const images = []; for (const [nodeId, image] of Object.entries(imageResponse.data.images)) { const res = await fetch(image); images.push({ nodeId, data: await res.buffer(), }); } return { response: fileResponse.data, images, }; } function listAllFrames(node) { if ("absoluteBoundingBox" in node) { return [node]; } if (!node.children || node.children.length === 0) { return []; } return node.children.map(listAllFrames).flat(); }
-
-
-
@@ -73,9 +73,13 @@ return [{ filename: "file.json", data: program.pretty ? JSON.stringify(file, null, 2) : JSON.stringify(file), ? JSON.stringify(file.response, null, 2) : JSON.stringify(file.response), }, ...file.images.map((image) => ({ filename: `${image.nodeId}.svg`, data: image.data, })), ]; })();
-