@@ -16,49 +16,54 @@ const description = z
1616
1717const content = z
1818 . string ( )
19- . refine ( ( str ) => str === null || str === "" || str . length >= 10 , {
19+ . refine ( ( str ) => str === "" || str . length >= 10 , {
2020 message : "Must be at least 10 characters long"
2121 } )
22- . refine ( ( str ) => str === null || str === "" || str . includes ( " " ) , {
22+ . refine ( ( str ) => str === "" || str . includes ( " " ) , {
2323 message : "You have no spaces, this is supposed to be at least a couple of words, ideally a few sentences."
2424 } )
2525
2626const categoryKeys = Object . keys ( scriptCategories ) as TScriptCategories
2727const ScriptCategoryEnum = z . enum ( categoryKeys as [ TScriptCategories [ number ] , ...TScriptCategories ] )
2828
29- export const baseScriptSchema = z . object ( {
29+ export const scriptInfoSchema = z . object ( {
3030 title : title ,
3131 description : description ,
3232 content : content ,
3333 status : z . boolean ( ) . default ( false ) ,
3434 type : z . boolean ( ) . default ( false ) ,
3535 categories : z . array ( ScriptCategoryEnum ) . min ( 1 , "You should have at least 1 category." ) ,
36- published : z . boolean ( ) . default ( true ) ,
37- simba : z
38- . string ( )
39- . length ( 10 , "Simba versions must be exactly 10 characters long" )
40- . regex ( / ^ [ a - f A - F 0 - 9 ] + $ / , "Must be a valid hexadecimal string" ) ,
41- wasplib : z
42- . string ( )
43- . regex ( / ^ \d { 4 } \. \d { 2 } \. \d { 2 } - [ a - f A - F 0 - 9 ] { 7 } $ / , "Must match format YYYY.MM.DD-HEX with valid hex" ) ,
44- xp_min : z
45- . number ( )
46- . int ( "Only whole numbers are allowed." )
47- . gte ( 0 , "There's no way to lose experience in OSRS." ) ,
48- xp_max : z . number ( ) . int ( "Only whole numbers are allowed." ) . max ( 60000 , "That exceeds the reasonable limit." ) ,
49- gp_min : z
50- . number ( )
51- . int ( "Only whole numbers are allowed." )
52- . gte ( - 200000 , "That exceeds the reasonable loss limit." ) ,
53- gp_max : z
54- . number ( )
55- . int ( "Only whole numbers are allowed." )
56- . max ( 600000 , "That exceeds the reasonable profit limit." ) ,
57- trackers : z . string ( ) . array ( ) . min ( 0 ) ,
58- minima : z . number ( ) . int ( "Only whole numbers are allowed." ) . array ( ) . min ( 0 ) ,
59- maxima : z . number ( ) . int ( "Only whole numbers are allowed." ) . array ( ) . min ( 0 )
36+ published : z . boolean ( ) . default ( true )
6037} )
6138
39+ export const scriptStatsSchema = z
40+ . object ( {
41+ xp_min : z
42+ . number ( )
43+ . int ( "Only whole numbers are allowed." )
44+ . gte ( 0 , "There's no way to lose experience in OSRS." ) ,
45+ xp_max : z
46+ . number ( )
47+ . int ( "Only whole numbers are allowed." )
48+ . max ( 60000 , "That exceeds the reasonable limit." ) ,
49+ gp_min : z
50+ . number ( )
51+ . int ( "Only whole numbers are allowed." )
52+ . gte ( - 200000 , "That exceeds the reasonable loss limit." ) ,
53+ gp_max : z
54+ . number ( )
55+ . int ( "Only whole numbers are allowed." )
56+ . max ( 600000 , "That exceeds the reasonable profit limit." ) ,
57+ trackers : z . array ( z . string ( ) ) ,
58+ minima : z . array ( z . number ( ) . int ( "Only whole numbers are allowed." ) ) ,
59+ maxima : z . array ( z . number ( ) . int ( "Only whole numbers are allowed." ) )
60+ } )
61+ . refine (
62+ ( schema ) => schema . xp_min <= schema . xp_max ,
63+ "Minimum experience cannot exceed the maximum experience."
64+ )
65+ . refine ( ( schema ) => schema . gp_min <= schema . gp_max , "Minimum gold cannot exceed the maximum gold." )
66+
6267export const coverImage = z
6368 . instanceof ( File , { message : "Please upload a file." } )
6469 . refine ( ( file ) => file . size <= 3 * MB_SIZE , "Max image size is 3MB." )
@@ -72,51 +77,69 @@ export const bannerImage = z
7277export const scriptFile = z
7378 . instanceof ( File , { message : "Please upload a file." } )
7479 . refine ( ( file ) => file . size <= 5 * MB_SIZE , "Max script size is 5MB." )
75- . refine ( ( file ) => file . name . endsWith ( ".simba" ) , "Only .simba files are allowed." )
76-
77- export const addScriptClientSchema = baseScriptSchema
78- . extend ( {
79- cover : coverImage . refine (
80- async ( file ) => await checkClientImageDimensions ( file , 300 , 200 ) ,
81- "The image must be 300 by 200 pixels."
82- ) ,
83- banner : bannerImage . refine (
84- async ( file ) => await checkClientImageDimensions ( file , 1920 , 768 ) ,
85- "The image must be 1920 by 768 pixels."
86- ) ,
87- script : scriptFile
88- } )
8980 . refine (
90- ( schema ) => schema . xp_min <= schema . xp_max ,
91- "Minimum experience cannot exceed the maximum experience."
81+ ( file ) =>
82+ file . name . endsWith ( ".simba" ) ||
83+ file . name . endsWith ( ".png" ) ||
84+ file . name . endsWith ( ".bmp" ) ||
85+ file . name . endsWith ( ".txt" ) ||
86+ file . name . endsWith ( ".ini" ) ||
87+ file . name . endsWith ( ".json" ) ||
88+ file . name . endsWith ( ".zip" ) ||
89+ file . name . endsWith ( ".bin" ) ||
90+ file . name . endsWith ( ".graph" ) ||
91+ file . name . endsWith ( ".obj" ) ||
92+ file . name . endsWith ( ".mtl" ) ,
93+ "This file type is not allowed."
9294 )
93- . refine ( ( schema ) => schema . gp_min <= schema . gp_max , "Minimum gold cannot exceed the maximum gold." )
95+
96+ export const addScriptClientSchema = scriptInfoSchema . extend ( {
97+ simba : z
98+ . string ( )
99+ . length ( 10 , "Simba versions must be exactly 10 characters long" )
100+ . regex ( / ^ [ a - f A - F 0 - 9 ] + $ / , "Must be a valid hexadecimal string" ) ,
101+ wasplib : z
102+ . string ( )
103+ . regex ( / ^ \d { 4 } \. \d { 2 } \. \d { 2 } - [ a - f A - F 0 - 9 ] { 7 } $ / , "Must match format YYYY.MM.DD-HEX with valid hex" ) ,
104+ cover : coverImage . refine (
105+ async ( file ) => await checkClientImageDimensions ( file , 300 , 200 ) ,
106+ "The image must be 300 by 200 pixels."
107+ ) ,
108+ banner : bannerImage . refine (
109+ async ( file ) => await checkClientImageDimensions ( file , 1920 , 768 ) ,
110+ "The image must be 1920 by 768 pixels."
111+ ) ,
112+ script : scriptFile . array ( ) ,
113+ main : z . string ( ) . nonempty ( )
114+ } )
94115
95116export type AddScriptSchema = z . infer < typeof addScriptClientSchema >
96117
97- export const updateScriptClientSchema = baseScriptSchema
98- . extend ( {
99- cover : coverImage
100- . refine (
101- async ( file ) => await checkClientImageDimensions ( file , 300 , 200 ) ,
102- "The image must be 300 by 200 pixels."
103- )
104- . optional ( ) ,
105- banner : bannerImage
106- . refine (
107- async ( file ) => await checkClientImageDimensions ( file , 1920 , 768 ) ,
108- "The image must be 1920 by 768 pixels."
109- )
110- . optional ( ) ,
111- script : scriptFile . optional ( )
112- } )
113- . refine (
114- ( schema ) => schema . xp_min <= schema . xp_max ,
115- "Minimum experience cannot exceed the maximum experience."
116- )
117- . refine ( ( schema ) => schema . gp_min <= schema . gp_max , "Minimum gold cannot exceed the maximum gold." )
118+ export const scriptFilesSchema = z . object ( {
119+ simba : z
120+ . string ( )
121+ . length ( 10 , "Simba versions must be exactly 10 characters long" )
122+ . regex ( / ^ [ a - f A - F 0 - 9 ] + $ / , "Must be a valid hexadecimal string" ) ,
123+ wasplib : z
124+ . string ( )
125+ . regex ( / ^ \d { 4 } \. \d { 2 } \. \d { 2 } - [ a - f A - F 0 - 9 ] { 7 } $ / , "Must match format YYYY.MM.DD-HEX with valid hex" ) ,
126+ cover : coverImage
127+ . refine (
128+ async ( file ) => await checkClientImageDimensions ( file , 300 , 200 ) ,
129+ "The image must be 300 by 200 pixels."
130+ )
131+ . optional ( ) ,
132+ banner : bannerImage
133+ . refine (
134+ async ( file ) => await checkClientImageDimensions ( file , 1920 , 768 ) ,
135+ "The image must be 1920 by 768 pixels."
136+ )
137+ . optional ( ) ,
138+ script : z . array ( scriptFile ) . min ( 1 ) . optional ( ) ,
139+ main : z . string ( ) . optional ( )
140+ } )
118141
119- export type UpdateScriptSchema = z . infer < typeof updateScriptClientSchema >
142+ export type UpdateScriptSchema = z . infer < typeof scriptFilesSchema >
120143
121144export const postSchema = z . object ( {
122145 title : title ,
0 commit comments