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) {
|
if (slug && !reserveSlug.includes(slug) && slugRegex.test(slug) && cloudflare) {
|
||||||
const { KV } = cloudflare.env
|
const { KV } = cloudflare.env
|
||||||
const link: z.infer<typeof LinkSchema> | null = await KV.get(
|
|
||||||
`link:${caseSensitive ? slug : slug.toLowerCase()}`,
|
let link: z.infer<typeof LinkSchema> | null = null
|
||||||
{ type: 'json', cacheTtl: linkCacheTtl },
|
|
||||||
)
|
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) {
|
if (link) {
|
||||||
event.context.link = link
|
event.context.link = link
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue