38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import vine from '@vinejs/vine'
|
|
|
|
const NAME = /^[a-z0-9][a-z0-9-]{0,40}$/
|
|
const DOMAIN = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$/
|
|
const GIT_URL = /^(https?:\/\/|ssh:\/\/|git@)[^\s]+$/
|
|
|
|
export const createProjectValidator = vine.create({
|
|
type: vine.enum(['node', 'adonis', 'wordpress', 'static'] as const),
|
|
name: vine.string().trim().toLowerCase().regex(NAME),
|
|
category: vine.enum(['api', 'frontend', 'fullstack', 'wordpress'] as const),
|
|
gitUrl: vine
|
|
.string()
|
|
.trim()
|
|
.regex(GIT_URL)
|
|
.optional()
|
|
.requiredWhen('type', 'in', ['node', 'adonis']),
|
|
port: vine
|
|
.number()
|
|
.withoutDecimals()
|
|
.range([1, 65535])
|
|
.optional()
|
|
.requiredWhen('type', 'in', ['node', 'adonis']),
|
|
command: vine.string().trim().maxLength(500).optional(),
|
|
env: vine.string().maxLength(20_000).optional(),
|
|
createDatabase: vine.boolean(),
|
|
domain: vine.string().trim().toLowerCase().regex(DOMAIN),
|
|
addCaddy: vine.boolean(),
|
|
spa: vine.boolean(),
|
|
})
|
|
|
|
export const projectActionValidator = vine.create({
|
|
commit: vine
|
|
.string()
|
|
.trim()
|
|
.regex(/^[0-9a-f]{7,40}$/)
|
|
.optional(),
|
|
})
|