Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/llms-txt-hub / apps/web/app/api/debug/github-contributions/route.ts |
| Date | Not specified in source |
| Repository | Janady13/llms-txt-hub |
| Revision | e0f4bf978d4df168369c7601d9c5f5ea89e84377 |
| Branch | main |
| Path or archive member | apps/web/app/api/debug/github-contributions/route.ts |
| Original SHA-256 | eefa04c449e792005e367a3437b3ab22487590c9468d57eb5203f34a3e9a8574 |
| Git blob SHA | aea2aadc7ef042bd15c7218f8d3af86f4b73c70d |
| Reading-copy SHA-256 | eefa04c449e792005e367a3437b3ab22487590c9468d57eb5203f34a3e9a8574 |
Recovered source transcript
Download complete source text ↓81 lines · 2.3 KB
import { createHash } from 'node:crypto'
import { logger } from '@thedaviddias/logging'
import { type NextRequest, NextResponse } from 'next/server'
import { ensureDebugAccess } from '@/app/api/debug/_utils'
import { getUserContributions } from '@/lib/github-contributions'
/**
* Creates a SHA-256 hash of the username for logging purposes
*
* @param username - The username to hash
* @returns The hex digest of the username hash
*/
function hashUsername(username: string | null | undefined): string {
const input = username || ''
return createHash('sha256').update(input).digest('hex')
}
/**
* GET handler for debugging GitHub contributions fetching
*
* @param request - NextRequest with username query parameter
* @returns Promise resolving to NextResponse with contributions data or error
*/
export async function GET(request: NextRequest) {
const access = await ensureDebugAccess(request)
if (!access.ok) {
return access.response
}
const { searchParams } = new URL(request.url)
const username = searchParams.get('username')
if (!username) {
return NextResponse.json({ error: 'Username parameter required' }, { status: 400 })
}
try {
logger.info('Debug: Fetching GitHub contributions', {
data: { usernameHash: hashUsername(username) },
tags: { type: 'debug', component: 'github-contributions' }
})
const contributions = await getUserContributions(username)
return NextResponse.json({
username,
contributions,
timestamp: new Date().toISOString()
})
} catch (error) {
logger.error('Debug: Error fetching GitHub contributions', {
data: {
usernameHash: hashUsername(username),
error: error instanceof Error ? error.message : 'Unknown error'
},
tags: { type: 'debug', component: 'github-contributions', error: 'fetch-failed' }
})
const errorResponse: {
error: string
timestamp: string
details?: string
} = {
error: 'Failed to fetch contributions',
timestamp: new Date().toISOString()
}
// Only include error details in development
if (process.env.NODE_ENV !== 'production') {
errorResponse.details = error instanceof Error ? error.message : 'Unknown error'
}
return NextResponse.json(errorResponse, {
status: 500,
headers: {
'Cache-Control': 'no-store'
}
})
}
}