init: the first public commit for AFFiNE

This commit is contained in:
DarkSky
2022-07-22 15:49:21 +08:00
commit e3e3741393
1451 changed files with 108124 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
const PREFIX_URL = 'https://api.figma.com/v1/';
async function initializeApi(token) {
const got = await import('got');
const api = got.got.extend({
prefixUrl: PREFIX_URL,
headers: {
'X-Figma-Token': token,
},
});
return {
async getChildren(fileId, nodeId) {
const decodedNodeId = decodeURIComponent(nodeId);
console.log(
`Fetching: ${`${PREFIX_URL}files/${fileId}/nodes?ids=${decodedNodeId}`}`
);
let data;
try {
data = await api({
url: `files/${fileId}/nodes?ids=${decodedNodeId}`,
}).json();
} catch (error) {
console.log(`Error: ${error}`);
}
return data.nodes[decodedNodeId].document.children;
},
async getIconsUrl(fileId, iconId) {
console.log(
`Fetching: ${`${PREFIX_URL}images/${fileId}/?ids=${iconId}&format=svg`}`
);
let body;
try {
body = await api({
url: `images/${fileId}/?ids=${iconId}&format=svg`,
}).json();
} catch (error) {
console.log(`Error: ${error}`);
}
return body.images;
},
async downloadIcon(iconUrl) {
const { body } = await got.got({
url: iconUrl,
});
return body;
},
};
}
module.exports = initializeApi;