Files
librechat.ai/pages/api/github-stats.ts
Danny Avila 54f77a1719 🎨 feat: Adds Image Gen Docs, fix broken links, usage stats, missing .env vars, formatting issues, bump Next.js (#288)
* docs: enhance API key setup instructions for clarity

* docs: update section title for API key setup clarity

* docs: add comprehensive guide for OpenAI image generation and editing tools

* docs: clarify Stable Diffusion section and update link in Image Generation overview

* docs: add Flux cloud generator configuration details and environment variables

* fix: Firebase CDN configuration link

* docs: enhance fileStrategy section with CDN options and notes

* docs: enhance Image Generation section with improved structure and pricing details

* docs: add Code Interpreter section with environment variable details and enterprise plan notes

* fix: formatting

* chore: bump next

* fix: correct markdown formatting for artifact example in agents documentation

* docs: add deprecation notices for tools, plugins, presets, and enhance image generation section

* feat: implement GitHub stats API and update Usage component to fetch stars dynamically

* fix: update Docker pulls value in Usage component
2025-04-25 12:21:27 -04:00

39 lines
1.1 KiB
TypeScript

import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios'
type GitHubResponse = {
stargazers_count: number
}
type ResponseData = {
stars: number
error?: string
}
export default async function handler(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
try {
// GitHub API endpoint for the LibreChat repository
const response = await axios.get<GitHubResponse>(
'https://api.github.com/repos/danny-avila/LibreChat',
{
headers: {
Accept: 'application/vnd.github.v3+json',
// Use GitHub token if available in environment variables
...(process.env.GITHUB_TOKEN && {
Authorization: `token ${process.env.GITHUB_TOKEN}`,
}),
},
},
)
// Cache the response for 1 hour (3600 seconds)
res.setHeader('Cache-Control', 's-maxage=3600, stale-while-revalidate')
// Return the star count
return res.status(200).json({ stars: response.data.stargazers_count })
} catch (error) {
console.error('Error fetching GitHub stats:', error)
return res.status(500).json({ stars: 0, error: 'Failed to fetch GitHub stats' })
}
}