MCPcopy Create free account
hub / github.com/MigoXLab/coderio / fetchFigmaImages

Function fetchFigmaImages

src/tools/figma-tool/figma.ts:37–61  ·  view source on GitHub ↗
(
    fileId: string,
    nodeIds: string,
    token: string,
    format?: FigmaImageFormat
)

Source from the content-addressed store, hash-verified

35 * @returns Figma image
36 */
37export const fetchFigmaImages = async (
38 fileId: string,
39 nodeIds: string,
40 token: string,
41 format?: FigmaImageFormat
42): Promise<Record<string, string>> => {
43 const url = `https://api.figma.com/v1/images/${fileId}`;
44 try {
45 const data = await get<{ images: Record<string, string> }>(url, {
46 headers: {
47 'X-Figma-Token': token,
48 },
49 params: {
50 ids: nodeIds,
51 format: format || 'png',
52 },
53 });
54 const images = data.images || {};
55 // format node id to match the format from response to request
56 return Object.fromEntries(Object.entries(images));
57 } catch (error) {
58 logger.printErrorLog(`Failed to fetch Figma images: ${error instanceof Error ? error.message : 'Unknown error'}`);
59 return {};
60 }
61};
62
63/**
64 * Clean Figma node and children. Remove invisible nodes and children.

Callers 2

fetchAndCleanMethod · 0.90
fetchImagesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected