-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { NextRequest } from 'next/server' | ||
import { badgen } from 'badgen' | ||
import statsEndpoint from './stats' | ||
|
||
const statsSvgEndpoint = async (req: NextRequest) => { | ||
let totalCount = 0 | ||
|
||
try { | ||
const apiResponse = await (await statsEndpoint(req)).json() | ||
if (apiResponse.total_count) { | ||
totalCount = apiResponse.total_count | ||
} | ||
} catch (ex) { | ||
console.error(ex) | ||
} | ||
|
||
const svg = totalCount | ||
? badgen({ | ||
subject: '', | ||
status: `${totalCount} repositories`, | ||
color: 'black', | ||
style: 'flat' | ||
}) | ||
: badgen({ | ||
subject: '', | ||
status: `thousands of repositories`, | ||
color: 'black', | ||
style: 'flat' | ||
}) | ||
|
||
return new Response(svg, { | ||
status: 200, | ||
headers: { | ||
'content-type': 'image/svg+xml', | ||
'cache-control': | ||
'public, immutable, no-transform, max-age=60, s-maxage=86400' | ||
} | ||
}) | ||
} | ||
|
||
export const config = { | ||
runtime: 'experimental-edge' | ||
} | ||
|
||
export default statsSvgEndpoint |