@@ -11,7 +11,7 @@ function makeOpts(url) {
1111 if ( core . isLogin ( ) ) {
1212 var user = core . getUser ( ) ;
1313 opts . headers [ 'Cookie' ] = 'PHPSESSID=' + user . session_id + ';csrftoken=' + user . session_csrf + ';' ;
14- // opts.headers['X-CSRFToken'] = user.session_csrf;
14+ opts . headers [ 'X-CSRFToken' ] = user . session_csrf ;
1515 }
1616 return opts ;
1717}
@@ -132,7 +132,7 @@ leetcode_client.testProblem = function(problem, cb) {
132132 opts . json = true ;
133133 opts . body = {
134134 data_input : problem . testcase ,
135- lang : h . fileLang ( problem . file ) ,
135+ lang : h . extToLang ( problem . file ) ,
136136 question_id : parseInt ( problem . id ) ,
137137 test_mode : false ,
138138 typed_code : h . fileData ( problem . file )
@@ -153,4 +153,31 @@ leetcode_client.testProblem = function(problem, cb) {
153153 } ) ;
154154} ;
155155
156+ leetcode_client . submitProblem = function ( problem , cb ) {
157+ var opts = makeOpts ( ) ;
158+ opts . url = config . SUBMIT_URL . replace ( '$key' , problem . key ) ;
159+ opts . headers [ 'Origin' ] = config . BASE_URL ;
160+ opts . headers [ 'Referer' ] = problem . link ;
161+ opts . headers [ 'X-Requested-With' ] = 'XMLHttpRequest' ;
162+ opts . json = true ;
163+ opts . body = {
164+ judge_type : 'large' ,
165+ lang : h . extToLang ( problem . file ) ,
166+ question_id : parseInt ( problem . id ) ,
167+ test_mode : false ,
168+ typed_code : h . fileData ( problem . file )
169+ } ;
170+
171+ request . post ( opts , function ( e , resp , body ) {
172+ if ( e ) return cb ( e ) ;
173+ if ( resp . statusCode != 200 ) return cb ( 'HTTP failed:' + resp . statusCode ) ;
174+
175+ opts . json = false ;
176+ opts . body = null ;
177+
178+ var jobs = [ { name : 'Your' , id : body . submission_id } ] ;
179+ verify_test ( opts , jobs , [ ] , cb ) ;
180+ } ) ;
181+ } ;
182+
156183module . exports = leetcode_client ;
0 commit comments