11import crypto from 'node:crypto'
22import yaml from 'yaml'
33import defu from 'defu'
4- import { ZodError , z } from 'zod'
4+ import { ZodError } from 'zod'
55import type { CompleteConfig , Service , Tag } from '~/types'
6+ import { configSchema } from '~/server/validations'
67
78type DraftService = Omit < Service , 'id' >
89
@@ -39,52 +40,6 @@ export function getDefaultConfig(): CompleteConfig {
3940 }
4041}
4142
42- export function validateConfigSchema ( config : any ) {
43- const status = z . object ( {
44- enabled : z . boolean ( ) . optional ( ) ,
45- interval : z . number ( ) . optional ( ) ,
46- } )
47-
48- const icon = z . object ( {
49- url : z . string ( ) . optional ( ) ,
50- name : z . string ( ) . optional ( ) ,
51- wrap : z . boolean ( ) . optional ( ) ,
52- background : z . string ( ) . optional ( ) ,
53- color : z . string ( ) . optional ( ) ,
54- } )
55-
56- const tag = z . object ( {
57- name : z . string ( ) ,
58- color : z . string ( ) ,
59- } )
60-
61- const service = z . object ( {
62- title : z . string ( ) . nullish ( ) . optional ( ) ,
63- description : z . string ( ) . nullish ( ) . optional ( ) ,
64- link : z . string ( ) . nullish ( ) . optional ( ) ,
65- target : z . string ( ) . optional ( ) ,
66- icon : icon . optional ( ) ,
67- status : status . optional ( ) ,
68- type : z . string ( ) . optional ( ) ,
69- options : z . record ( z . any ( ) ) . optional ( ) ,
70- secrets : z . record ( z . any ( ) ) . optional ( ) ,
71- } )
72-
73- const schema = z . object ( {
74- title : z . string ( ) . optional ( ) ,
75- lang : z . string ( ) . optional ( ) ,
76- theme : z . string ( ) . optional ( ) ,
77- checkUpdates : z . boolean ( ) . optional ( ) ,
78- tags : z . array ( tag ) . optional ( ) ,
79- services : z . union ( [
80- z . array ( service ) ,
81- z . record ( z . array ( service ) ) ,
82- ] ) ,
83- } )
84-
85- return schema . parse ( config )
86- }
87-
8843function createTagMap ( tags : Tag [ ] ) : TagMap {
8944 return tags . reduce ( ( acc , tag ) => {
9045 acc . set ( tag . name , tag )
@@ -108,7 +63,7 @@ export async function loadLocalConfig(): Promise<CompleteConfig> {
10863 const services : CompleteConfig [ 'services' ] = [ ]
10964 const tags : TagMap = createTagMap ( config . tags || [ ] )
11065
111- validateConfigSchema ( config )
66+ configSchema . parse ( config )
11267
11368 if ( Array . isArray ( config . services ) ) {
11469 services . push ( {
0 commit comments