@@ -54,6 +54,21 @@ type UiConfig = {
5454 photoResize : number | string ;
5555} ;
5656
57+ /**
58+ * Generates an XML string representation of the provided data.
59+ *
60+ * @param {any } data - The data to be converted into XML format.
61+ * @returns {string } - A string containing the XML representation of the data.
62+ */
63+ function generateXML ( data : any ) : string {
64+ let xml = `<stats>\n` ;
65+ for ( const key in data ) {
66+ xml += ` <${ key } >${ escapeHTML ( data [ key ] ) } </${ key } >\n` ;
67+ }
68+ xml += `</stats>` ;
69+ return xml ;
70+ }
71+
5772/**
5873 * Handles the generation card of a GitHub stats based on user data and specified options.
5974 *
@@ -119,7 +134,13 @@ async function readmeStats(req: any, res: any): Promise<any> {
119134 res . setHeader ( "Cache-Control" , "s-maxage=7200, stale-while-revalidate" ) ;
120135
121136 if ( uiConfig . Format === "json" ) {
137+ fetchStats . picture = `data:image/png;base64,${ fetchStats . picture } ` ;
122138 res . json ( fetchStats ) ;
139+ } else if ( uiConfig . Format === "xml" ) {
140+ fetchStats . picture = `data:image/png;base64,${ fetchStats . picture } ` ;
141+ const xmlData = generateXML ( fetchStats ) ;
142+ res . setHeader ( "Content-Type" , "application/xml" ) ;
143+ res . send ( xmlData ) ;
123144 } else if ( uiConfig . Format === "png" ) {
124145 const svgString = await card ( fetchStats , uiConfig ) ;
125146 const resvg = new Resvg ( svgString , { font : { defaultFontFamily : "Segoe UI" } } ) ;
0 commit comments