Skip to content

Commit 79a62fa

Browse files
authored
chore: store return URLs in session (#1117)
1 parent 4ca425f commit 79a62fa

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"nuxt": "4.3.0",
8484
"nuxt-og-image": "5.1.13",
8585
"ofetch": "1.5.1",
86+
"ohash": "2.0.11",
8687
"perfect-debounce": "2.1.0",
8788
"sanitize-html": "2.17.0",
8889
"semver": "7.7.3",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/api/registry/badge/[type]/[...pkg].get.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as v from 'valibot'
2+
import { hash } from 'ohash'
23
import { createError, getRouterParam, getQuery, setHeader } from 'h3'
34
import { PackageRouteParamsSchema } from '#shared/schemas/package'
45
import { CACHE_MAX_AGE_ONE_HOUR, ERROR_NPM_FETCH_FAILED } from '#shared/utils/constants'
@@ -11,11 +12,13 @@ const OSV_QUERY_API = 'https://api.osv.dev/v1/query'
1112
const BUNDLEPHOBIA_API = 'https://bundlephobia.com/api/size'
1213
const NPMS_API = 'https://api.npms.io/v2/package'
1314

15+
const SafeStringSchema = v.pipe(v.string(), v.regex(/^[^<>"&]*$/, 'Invalid characters'))
16+
1417
const QUERY_SCHEMA = v.object({
15-
color: v.optional(v.string()),
18+
color: v.optional(SafeStringSchema),
1619
name: v.optional(v.string()),
17-
labelColor: v.optional(v.string()),
18-
label: v.optional(v.string()),
20+
labelColor: v.optional(SafeStringSchema),
21+
label: v.optional(SafeStringSchema),
1922
})
2023

2124
const COLORS = {
@@ -338,7 +341,7 @@ export default defineCachedEventHandler(
338341
const type = getRouterParam(event, 'type') ?? 'version'
339342
const pkg = getRouterParam(event, 'pkg') ?? ''
340343
const query = getQuery(event)
341-
return `badge:${type}:${pkg}:${JSON.stringify(query)}`
344+
return `badge:${type}:${pkg}:${hash(query)}`
342345
},
343346
},
344347
)

0 commit comments

Comments
 (0)