@@ -11,7 +11,7 @@ function makeOpts(url) {
11
11
if ( core . isLogin ( ) ) {
12
12
var user = core . getUser ( ) ;
13
13
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 ;
15
15
}
16
16
return opts ;
17
17
}
@@ -132,7 +132,7 @@ leetcode_client.testProblem = function(problem, cb) {
132
132
opts . json = true ;
133
133
opts . body = {
134
134
data_input : problem . testcase ,
135
- lang : h . fileLang ( problem . file ) ,
135
+ lang : h . extToLang ( problem . file ) ,
136
136
question_id : parseInt ( problem . id ) ,
137
137
test_mode : false ,
138
138
typed_code : h . fileData ( problem . file )
@@ -153,4 +153,31 @@ leetcode_client.testProblem = function(problem, cb) {
153
153
} ) ;
154
154
} ;
155
155
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
+
156
183
module . exports = leetcode_client ;
0 commit comments