@@ -2,18 +2,19 @@ const fs = require('fs');
22const fetch = require ( 'node-fetch' ) ;
33const { execSync } = require ( 'child_process' ) ;
44
5- // Get the API URL from environment variables
65const API_URL = process . env . API_URL || 'http://localhost:3000' ;
7- const IMAGE_TOKEN = process . env . IMAGE_TOKEN ;
6+ const GITHUB_TOKEN = process . env . GITHUB_TOKEN ;
7+ const REPO_OWNER = 'Open-Dev-Society' ;
8+ const REPO_NAME = 'openreadme' ;
89
910async function generateProfileImage ( username , userId ) {
1011 try {
1112 console . log ( `Generating image for ${ username } ...` ) ;
1213
13- // First, get the user data from GitHub API
14+ // Get user data from GitHub API
1415 const userResponse = await fetch ( `https://api.github.com/users/${ username } ` , {
1516 headers : {
16- 'Authorization' : `token ${ IMAGE_TOKEN } ` ,
17+ 'Authorization' : `token ${ GITHUB_TOKEN } ` ,
1718 'Accept' : 'application/vnd.github.v3+json'
1819 }
1920 } ) ;
@@ -24,27 +25,28 @@ async function generateProfileImage(username, userId) {
2425
2526 const userData = await userResponse . json ( ) ;
2627
27- // Prepare the data for the OpenReadme API
28- // Build the API URL with all parameters
28+ // Build API URL with repository parameters
2929 const params = new URLSearchParams ( {
3030 n : userData . name || username ,
3131 i : userData . avatar_url || '' ,
3232 github : username ,
3333 x : userData . twitter_username || '' ,
34- l : '' , // LinkedIn would need to be handled separately
35- p : userData . blog || userData . html_url ,
36- t : 'classic' // Default theme
34+ l : userData . blog || userData . html_url ,
35+ p : userData . html_url ,
36+ t : 'classic' ,
37+ repo : `${ REPO_OWNER } /${ REPO_NAME } ` ,
38+ path : 'stats/usage-log.json'
3739 } ) ;
3840
3941 const apiUrl = `${ API_URL } ?${ params . toString ( ) } ` ;
4042 console . log ( `Calling API: ${ apiUrl } ` ) ;
4143
42- // Call the OpenReadme API with proper headers
4344 const response = await fetch ( apiUrl , {
4445 method : 'GET' ,
4546 headers : {
4647 'Accept' : 'application/json' ,
47- 'Content-Type' : 'application/json'
48+ 'Content-Type' : 'application/json' ,
49+ 'Authorization' : `token ${ GITHUB_TOKEN } `
4850 }
4951 } ) ;
5052
@@ -57,7 +59,6 @@ async function generateProfileImage(username, userId) {
5759
5860 const result = await response . json ( ) ;
5961 console . log ( `✅ Successfully generated image for ${ username } : ${ result . url } ` ) ;
60-
6162 return result . url ;
6263
6364 } catch ( error ) {
@@ -73,7 +74,6 @@ async function generateProfileImage(username, userId) {
7374
7475 for ( const mapping of mappings ) {
7576 if ( ! mapping ) continue ;
76-
7777 const [ username , userId ] = mapping . split ( '=' ) ;
7878 if ( ! username || ! userId ) continue ;
7979
@@ -82,17 +82,12 @@ async function generateProfileImage(username, userId) {
8282 try {
8383 const imageUrl = await generateProfileImage ( username , userId ) ;
8484 if ( imageUrl ) {
85- // Here you could update the user-mapping.json with the new image URL if needed
8685 console . log ( `Image URL: ${ imageUrl } ` ) ;
8786 }
88-
89- // Add delay to avoid rate limiting (1 second between requests)
9087 await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
91-
9288 } catch ( error ) {
9389 console . error ( `Error processing ${ username } :` , error ) ;
9490 }
9591 }
96-
9792 console . log ( '\n--- All users processed ---' ) ;
9893} ) ( ) ;
0 commit comments