@@ -11,13 +11,15 @@ import { Attempts } from '@/lib/types';
1111import { Skeleton } from '../ui/skeleton' ;
1212import Editor from "@monaco-editor/react" ;
1313import { Tabs , TabsList , TabsTrigger , TabsContent } from "@/components/ui/tabs" ;
14+ import { minimatch } from "minimatch" ;
1415
1516interface SubmissionUploadFormProps {
1617 problemId : string ;
1718 uploadLimits : {
1819 max_num : number ;
1920 max_size : number ;
2021 upload_form ?: boolean ;
22+ upload_files ?: string [ ] ;
2123 editor ?: boolean ;
2224 editor_files ?: string [ ] ;
2325 } ;
@@ -98,7 +100,20 @@ export default function SubmissionUploadForm({ problemId, uploadLimits }: Submis
98100 const fileInputRef = useRef < HTMLInputElement > ( null ) ;
99101 const folderInputRef = useRef < HTMLInputElement > ( null ) ;
100102
103+ const uploadFiles = uploadLimits . upload_files || [ ] ;
104+
101105 const addFiles = useCallback ( ( newFiles : File [ ] ) => {
106+
107+ if ( uploadFiles . length > 0 ) {
108+ newFiles = newFiles . filter ( file =>
109+ uploadFiles . some ( pattern => minimatch ( ( ( file as FileWithPath ) . path || ( file as any ) . webkitRelativePath || file . name ) . replace ( / ^ \/ + / , "" ) . replace ( / ^ ( \. \/ ) + / , "" ) , pattern ) )
110+ ) ;
111+ if ( newFiles . length === 0 ) {
112+ toast ( { variant : 'destructive' , title : 'No valid files' , description : `No selected files match the allowed patterns: ${ uploadFiles . join ( ', ' ) } ` } ) ;
113+ return ;
114+ }
115+ }
116+
102117 const allFiles = [ ...files , ...newFiles ] ;
103118 if ( uploadLimits . max_num > 0 && allFiles . length > uploadLimits . max_num ) {
104119 toast ( { variant : 'destructive' , title : 'Too many files' , description : `You can upload a maximum of ${ uploadLimits . max_num } files.` } ) ;
@@ -183,7 +198,7 @@ export default function SubmissionUploadForm({ problemId, uploadLimits }: Submis
183198 setIsSubmitting ( true ) ;
184199 const formData = new FormData ( ) ;
185200 filesToSubmit . forEach ( file => {
186- const filePath = ( file as FileWithPath ) . path || ( file as any ) . webkitRelativePath || file . name ;
201+ const filePath = ( ( file as FileWithPath ) . path || ( file as any ) . webkitRelativePath || file . name ) . replace ( / ^ \/ + / , "" ) . replace ( / ^ ( \. \/ ) + / , "" ) ;
187202 formData . append ( 'files' , file , btoaUTF8 ( filePath ) ) ;
188203 } ) ;
189204
0 commit comments