Skip to content

Commit fffa3c4

Browse files
committed
refactor: use URLSearchParams instead of manually building
1 parent f4a5133 commit fffa3c4

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

server/api/card/[...pkg].get.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@ export default defineEventHandler(async event => {
2020
const query = getQuery(event)
2121
const theme = query.theme === 'light' ? 'light' : 'dark'
2222
const rawColor = typeof query.color === 'string' ? query.color : null
23-
const color =
24-
rawColor && (ACCENT_COLOR_IDS as readonly string[]).includes(rawColor)
25-
? `&color=${rawColor}`
26-
: ''
27-
28-
return sendRedirect(
29-
event,
30-
`/__og-image__/image/share-card/${packageName}/og.png?theme=${theme}${color}`,
31-
302,
32-
)
23+
24+
const params = new URLSearchParams({ theme })
25+
if (rawColor && (ACCENT_COLOR_IDS as readonly string[]).includes(rawColor)) {
26+
params.set('color', rawColor)
27+
}
28+
29+
return sendRedirect(event, `/__og-image__/image/share-card/${packageName}/og.png?${params}`, 302)
3330
})

0 commit comments

Comments
 (0)