fix: forward compability for case sensitive

This commit is contained in:
ZL Asica 2024-12-06 10:19:40 -06:00
parent e51e912972
commit 902fc1bef5
No known key found for this signature in database
GPG key ID: 5B1ED5BE09CE4C01

View file

@ -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