fix: forward compability for case sensitive
This commit is contained in:
parent
e51e912972
commit
902fc1bef5
1 changed files with 10 additions and 4 deletions
|
|
@ -13,10 +13,16 @@ export default eventHandler(async (event) => {
|
|||
|
||||
if (slug && !reserveSlug.includes(slug) && slugRegex.test(slug) && cloudflare) {
|
||||
const { KV } = cloudflare.env
|
||||
const link: z.infer<typeof LinkSchema> | null = await KV.get(
|
||||
`link:${caseSensitive ? slug : slug.toLowerCase()}`,
|
||||
{ type: 'json', cacheTtl: linkCacheTtl },
|
||||
)
|
||||
|
||||
let link: z.infer<typeof LinkSchema> | null = null
|
||||
|
||||
const getLink = async (key: string) =>
|
||||
await KV.get(`link:${key}`, { type: 'json', cacheTtl: linkCacheTtl })
|
||||
|
||||
link = await getLink(slug)
|
||||
if (!caseSensitive && !link) {
|
||||
link = await getLink(slug.toLowerCase())
|
||||
}
|
||||
|
||||
if (link) {
|
||||
event.context.link = link
|
||||
|
|
|
|||
Loading…
Reference in a new issue