@@ -140,9 +140,11 @@ export const documentUploadSchema = z
140140 . min ( 1 , "Document name is required" )
141141 . max ( 255 , "Document name too long" ) ,
142142 url : filePathSchema ,
143- storageType : z . enum ( [ "S3_PATH" , "VERCEL_BLOB" ] , {
144- errorMap : ( ) => ( { message : "Invalid storage type" } ) ,
145- } ) ,
143+ storageType : z
144+ . enum ( [ "S3_PATH" , "VERCEL_BLOB" ] , {
145+ errorMap : ( ) => ( { message : "Invalid storage type" } ) ,
146+ } )
147+ . optional ( ) ,
146148 numPages : z . number ( ) . int ( ) . positive ( ) . optional ( ) ,
147149 type : z . enum (
148150 SUPPORTED_DOCUMENT_SIMPLE_TYPES as unknown as readonly [
@@ -166,12 +168,18 @@ export const documentUploadSchema = z
166168 errorMap : ( ) => ( { message : "Unsupported content type" } ) ,
167169 } ,
168170 )
169- . or ( z . literal ( "text/html" ) ) , // Allow text/html for Notion documents
171+ . or ( z . literal ( "text/html" ) ) // Allow text/html for Notion documents
172+ . optional ( ) , // Make contentType optional for Notion files
170173 createLink : z . boolean ( ) . optional ( ) ,
171174 fileSize : z . number ( ) . int ( ) . positive ( ) . optional ( ) ,
172175 } )
173176 . refine (
174177 ( data ) => {
178+ // Skip content type validation if it's not provided (e.g., for Notion files)
179+ if ( ! data . contentType ) {
180+ return true ;
181+ }
182+
175183 // Validate that content type matches the declared file type
176184 const expectedType = getSupportedContentType ( data . contentType ) ;
177185
@@ -189,6 +197,26 @@ export const documentUploadSchema = z
189197 )
190198 . refine (
191199 ( data ) => {
200+ // Skip storage type validation if not provided (e.g., for Notion files)
201+ if ( ! data . storageType ) {
202+ // For Notion URLs, storage type is not required
203+ if ( data . url . startsWith ( "https://" ) ) {
204+ try {
205+ const urlObj = new URL ( data . url ) ;
206+ const hostname = urlObj . hostname ;
207+ return (
208+ hostname === "www.notion.so" ||
209+ hostname === "notion.so" ||
210+ hostname . endsWith ( ".notion.site" )
211+ ) ;
212+ } catch {
213+ return false ;
214+ }
215+ }
216+ // For file paths without storage type, this is invalid
217+ return false ;
218+ }
219+
192220 // Validate storage type consistency with path format
193221 if ( data . storageType === "S3_PATH" ) {
194222 // S3_PATH should use file paths, not URLs
@@ -217,7 +245,8 @@ export const documentUploadSchema = z
217245 return false ;
218246 } ,
219247 {
220- message : "Storage type does not match the URL/path format" ,
248+ message :
249+ "Storage type does not match the URL/path format, or missing storage type for non-Notion files" ,
221250 path : [ "storageType" ] ,
222251 } ,
223252 ) ;
0 commit comments