MCPcopy Create free account
hub / github.com/apache/fesod / processAvatars

Function processAvatars

website/github-avatar.js:92–119  ·  view source on GitHub ↗

* Processes a list of githubIds and adds avatar_base64 property * @param {Array} ids - Array of id * @returns {Promise } Array of avatar_base64

(ids)

Source from the content-addressed store, hash-verified

90 * @returns {Promise<Array>} Array of avatar_base64
91 */
92async function processAvatars(ids) {
93 const processedArray = [];
94
95 for (let i = 0; i < ids.length; i++) {
96 const _id = ids[i];
97
98 try {
99 console.log(`-- Fetching avatar for ${_id} ... [${i + 1}/${ids.length}]`);
100
101 // Fetch avatar and convert to base64
102 const avatarBase64 = await fetchAvatarAsBase64(_id);
103
104 processedArray.push({
105 id: _id,
106 avatar_base64: avatarBase64
107 });
108 console.log(`✓ Successfully processed ${_id}`);
109 } catch (error) {
110 console.error(`✗ Error processing ${_id}: ${error.message}`);
111 }
112
113 // Add random delay between 100-2000 millisecond before next request (except for the last member)
114 if (i < ids.length - 1) {
115 await new Promise((resolve) => setTimeout(resolve, getRandomDelay(100, 2000)));
116 }
117 }
118 return processedArray;
119}
120
121/**
122 * Processes blog authors data and adds avatar_base64 property

Callers 1

mainFunction · 0.85

Calls 2

fetchAvatarAsBase64Function · 0.85
getRandomDelayFunction · 0.85

Tested by

no test coverage detected