feat: generate default slug lenght if not provided in link creation using api

This commit is contained in:
MinerAle 2025-02-16 20:24:40 +01:00
parent ab4fc66da9
commit 69018f0ed5

View file

@ -1,7 +1,15 @@
import { LinkSchema } from '@/schemas/link'
import { LinkSchema, nanoid } from '@/schemas/link'
export default eventHandler(async (event) => {
const link = await readValidatedBody(event, LinkSchema.parse)
const body = await readBody(event)
// If no slug provided, generate one with default length from env
if (!body.slug) {
const { slugDefaultLength } = useRuntimeConfig().public
body.slug = nanoid(+slugDefaultLength)()
}
const link = await LinkSchema.parse(body)
const { caseSensitive } = useRuntimeConfig(event)