@@ -242,21 +242,20 @@ function verifyResult(opts, jobs, results, cb) {
242242 } ) ;
243243}
244244
245- leetcodeClient . testProblem = function ( problem , cb ) {
246- var opts = makeOpts ( ) ;
245+ function runCode ( opts , problem , cb ) {
247246 opts . method = 'POST' ;
248- opts . url = config . URL_TEST . replace ( '$key' , problem . key ) ;
249247 opts . headers . Origin = config . URL_BASE ;
250248 opts . headers . Referer = problem . link ;
251249 opts . headers [ 'X-Requested-With' ] = 'XMLHttpRequest' ;
252250 opts . json = true ;
253- opts . body = {
254- 'data_input' : problem . testcase ,
251+
252+ opts . body = opts . body || { } ;
253+ _ . extendOwn ( opts . body , {
255254 'lang' : h . extToLang ( problem . file ) ,
256255 'question_id' : parseInt ( problem . id , 10 ) ,
257256 'test_mode' : false ,
258257 'typed_code' : h . getFileData ( problem . file )
259- } ;
258+ } ) ;
260259
261260 requestWithReLogin ( opts , function ( e , resp , body ) {
262261 e = checkError ( e , resp , 200 ) ;
@@ -265,38 +264,35 @@ leetcodeClient.testProblem = function(problem, cb) {
265264 opts . json = false ;
266265 opts . body = null ;
267266
267+ return cb ( null , body ) ;
268+ } ) ;
269+ }
270+
271+ leetcodeClient . testProblem = function ( problem , cb ) {
272+ var opts = makeOpts ( ) ;
273+ opts . url = config . URL_TEST . replace ( '$key' , problem . key ) ;
274+ opts . body = { 'data_input' : problem . testcase } ;
275+
276+ runCode ( opts , problem , function ( e , task ) {
277+ if ( e ) return cb ( e ) ;
278+
268279 var jobs = [
269- { name : 'Your' , id : body . interpret_id } ,
270- { name : 'Expected' , id : body . interpret_expected_id }
280+ { name : 'Your' , id : task . interpret_id } ,
281+ { name : 'Expected' , id : task . interpret_expected_id }
271282 ] ;
272283 verifyResult ( opts , jobs , [ ] , cb ) ;
273284 } ) ;
274285} ;
275286
276287leetcodeClient . submitProblem = function ( problem , cb ) {
277288 var opts = makeOpts ( ) ;
278- opts . method = 'POST' ;
279289 opts . url = config . URL_SUBMIT . replace ( '$key' , problem . key ) ;
280- opts . headers . Origin = config . URL_BASE ;
281- opts . headers . Referer = problem . link ;
282- opts . headers [ 'X-Requested-With' ] = 'XMLHttpRequest' ;
283- opts . json = true ;
284- opts . body = {
285- 'judge_type' : 'large' ,
286- 'lang' : h . extToLang ( problem . file ) ,
287- 'question_id' : parseInt ( problem . id , 10 ) ,
288- 'test_mode' : false ,
289- 'typed_code' : h . getFileData ( problem . file )
290- } ;
290+ opts . body = { 'judge_type' : 'large' } ;
291291
292- requestWithReLogin ( opts , function ( e , resp , body ) {
293- e = checkError ( e , resp , 200 ) ;
292+ runCode ( opts , problem , function ( e , task ) {
294293 if ( e ) return cb ( e ) ;
295294
296- opts . json = false ;
297- opts . body = null ;
298-
299- var jobs = [ { name : 'Your' , id : body . submission_id } ] ;
295+ var jobs = [ { name : 'Your' , id : task . submission_id } ] ;
300296 verifyResult ( opts , jobs , [ ] , cb ) ;
301297 } ) ;
302298} ;
0 commit comments