@@ -2,10 +2,7 @@ import { Request, Response } from 'express';
22import { GitHubClient } from '../utils/github-client.js' ;
33import { CardRenderer } from '../components/card-renderer.js' ;
44import sharp from 'sharp' ;
5- import { themes } from '../utils/themes.js' ;
6- import { Controller } from './controller.js' ;
7-
8- export class StatsController extends Controller {
5+ export class StatsController {
96 private static githubClient : GitHubClient ;
107 private static cache : Map < string , { data : string ; timestamp : number } > ;
118 private static CACHE_DURATION : number ;
@@ -18,62 +15,6 @@ export class StatsController extends Controller {
1815 this . CACHE_DURATION = cacheDuration ;
1916 }
2017
21- static async get ( req : Request , res : Response ) {
22- try {
23- const { username, theme = 'default' , hide_title = 'false' , hide_border = 'false' , hide_rank = 'false' , show_icons = 'true' , avatar_mode = 'none' , custom_title, data_border_style = 'solid' , data_border_frame = 'out' , format = 'svg' } = req . query ;
24-
25- if ( ! username || typeof username !== 'string' ) {
26- return res . status ( 400 ) . send ( 'Username is required' ) ;
27- }
28-
29- // Build the SVG URL
30- const params = new URLSearchParams ( ) ;
31- params . set ( 'username' , username ) ;
32- if ( theme !== 'default' ) params . set ( 'theme' , theme as string ) ;
33- if ( hide_title === 'true' ) params . set ( 'hide_title' , 'true' ) ;
34- if ( hide_border === 'true' ) params . set ( 'hide_border' , 'true' ) ;
35- if ( hide_rank === 'true' ) params . set ( 'hide_rank' , 'true' ) ;
36- if ( show_icons !== 'true' ) params . set ( 'show_icons' , 'false' ) ;
37- if ( avatar_mode !== 'none' ) params . set ( 'avatar_mode' , avatar_mode as string ) ;
38- if ( data_border_style !== 'solid' ) params . set ( 'data_border_style' , data_border_style as string ) ;
39- if ( data_border_frame !== 'out' ) params . set ( 'data_border_frame' , data_border_frame as string ) ;
40- if ( custom_title ) params . set ( 'custom_title' , custom_title as string ) ;
41-
42- const host = req . get ( 'host' ) ;
43- const svgUrl = `/stats?${ params . toString ( ) } &format=svg` ;
44- const APP_ENV = process . env . APP_ENV || 'development' ;
45- const PROTOCOL = APP_ENV === 'production' ? 'https' : 'http' ;
46-
47- const fullUrl = `${ PROTOCOL } ://${ host } /stats?${ params . toString ( ) } ` ;
48-
49- const payloads = {
50- ...Controller . defaultConfig ,
51- title : `${ username } 's GitHub Stats - StackDev` ,
52- description : `View ${ username } 's GitHub statistics with customizable themes and options. Generate dynamic SVG cards for your README or profile.` ,
53- keywords : `github stats, github readme, github card, github statistics, readme stats, github api, svg card, github profile, developer stats, contribution tracker, ${ username } stats` ,
54- page : 'stats' ,
55- username,
56- theme,
57- hideTitle : hide_title === 'true' ,
58- hideBorder : hide_border === 'true' ,
59- hideRank : hide_rank === 'true' ,
60- showIcons : show_icons === 'true' ,
61- avatarMode : avatar_mode ,
62- dataBorderStyle : data_border_style ,
63- dataBorderFramePosition : data_border_frame ,
64- customTitle : custom_title || '' ,
65- svgUrl,
66- fullUrl,
67- themes : Object . keys ( themes )
68- }
69-
70- res . render ( 'layouts/main' , payloads ) ;
71- } catch ( error ) {
72- console . error ( 'Error rendering stats view:' , error ) ;
73- res . status ( 500 ) . send ( `Error: ${ error instanceof Error ? error . message : 'Unknown error' } ` ) ;
74- }
75- }
76-
7718 static async getSvg ( req : Request , res : Response ) {
7819 try {
7920 const {
@@ -144,7 +85,6 @@ export class StatsController extends Controller {
14485 } ) ;
14586
14687 const card = CardRenderer . generateStatsCard ( stats , {
147- username,
14888 theme : theme as string ,
14989 hideTitle : hide_title === 'true' ,
15090 hideBorder : hide_border === 'true' ,
0 commit comments