feat: migrate road card endpoint (#5583)
parent
043bf59c87
commit
32cbfd6699
4 changed files with 54 additions and 2 deletions
@ -0,0 +1,17 @@ |
||||
export async function getRoadCard( |
||||
version: 'tall' | 'wide', |
||||
userId: string, |
||||
variant: 'dark' | 'light', |
||||
roadmaps: string = '', |
||||
) { |
||||
const url = new URL( |
||||
`${import.meta.env.PUBLIC_API_URL}/v1-badge/${version}/${userId}`, |
||||
); |
||||
url.searchParams.set('variant', variant); |
||||
if (roadmaps) { |
||||
url.searchParams.set('roadmaps', roadmaps); |
||||
} |
||||
|
||||
const response = await fetch(url.toString()); |
||||
return response.text(); |
||||
} |
@ -0,0 +1,34 @@ |
||||
import type { APIRoute } from 'astro'; |
||||
import { getDefaultOpenGraphImageBuffer } from '../../../lib/open-graph'; |
||||
import { getRoadCard } from '../../../lib/road-card'; |
||||
|
||||
export const prerender = false; |
||||
|
||||
type Params = { |
||||
version: 'tall' | 'wide'; |
||||
userId: string; |
||||
}; |
||||
|
||||
export const GET: APIRoute<any, Params> = async (context) => { |
||||
const { userId, version } = context.params; |
||||
|
||||
if (!userId || !version) { |
||||
const buffer = await getDefaultOpenGraphImageBuffer(); |
||||
return new Response(buffer, { |
||||
headers: { |
||||
'Content-Type': 'image/png', |
||||
}, |
||||
}); |
||||
} |
||||
|
||||
const searchParams = new URLSearchParams(context.url.searchParams); |
||||
const variant = (searchParams.get('variant') as 'dark' | 'light') || 'dark'; |
||||
const roadmaps = searchParams.get('roadmaps') || ''; |
||||
|
||||
const svg = await getRoadCard(version, userId, variant, roadmaps); |
||||
return new Response(svg, { |
||||
headers: { |
||||
'Content-Type': 'image/svg+xml', |
||||
}, |
||||
}); |
||||
}; |
Loading…
Reference in new issue