feat: generate default slug lenght if not provided in link creation using api
This commit is contained in:
parent
ab4fc66da9
commit
69018f0ed5
1 changed files with 10 additions and 2 deletions
|
|
@ -1,7 +1,15 @@
|
||||||
import { LinkSchema } from '@/schemas/link'
|
import { LinkSchema, nanoid } from '@/schemas/link'
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
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)
|
const { caseSensitive } = useRuntimeConfig(event)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue