@@ -4,6 +4,7 @@ var request = require('request');
44var util = require ( 'util' ) ;
55
66var h = require ( '../helper' ) ;
7+ var config = require ( '../config' ) ;
78var log = require ( '../log' ) ;
89var Plugin = require ( '../plugin' ) ;
910var Queue = require ( '../queue' ) ;
@@ -18,20 +19,9 @@ var session = require('../session');
1819//
1920// https://github.com/skygragon/leetcode-cli-plugins/blob/master/docs/lintcode.md
2021//
21- const plugin = new Plugin ( 15 , 'lintcode' , '2018.05.29 ' ,
22+ const plugin = new Plugin ( 15 , 'lintcode' , '2018.05.30 ' ,
2223 'Plugin to talk with lintcode APIs.' ) ;
2324
24- const config = {
25- URL_PROBLEMS : 'https://www.lintcode.com/api/problems/?page=$page' ,
26- URL_PROBLEM : 'https://www.lintcode.com/problem/$slug/description' ,
27- URL_PROBLEM_DETAIL : 'https://www.lintcode.com/api/problems/detail/?unique_name_or_alias=$slug&_format=detail' ,
28- URL_PROBLEM_CODE : 'https://www.lintcode.com/api/problems/$id/reset/?language=$lang' ,
29- URL_TEST : 'https://www.lintcode.com/api/submissions/' ,
30- URL_TEST_VERIFY : 'https://www.lintcode.com/api/submissions/refresh/?id=$id&is_test_submission=true' ,
31- URL_SUBMIT_VERIFY : 'https://www.lintcode.com/api/submissions/refresh/?id=$id' ,
32- URL_LOGIN : 'https://www.lintcode.com/api/accounts/signin/?next=%2F'
33- } ;
34-
3525// FIXME: add more langs
3626const LANGS = [
3727 { value : 'cpp' , text : 'C++' } ,
@@ -92,6 +82,17 @@ function _strip(s) {
9282 return util . inspect ( s . trim ( ) ) ;
9383}
9484
85+ plugin . init = function ( ) {
86+ config . sys . urls . problems = 'https://www.lintcode.com/api/problems/?page=$page' ;
87+ config . sys . urls . problem = 'https://www.lintcode.com/problem/$slug/description' ;
88+ config . sys . urls . problem_detail = 'https://www.lintcode.com/api/problems/detail/?unique_name_or_alias=$slug&_format=detail' ;
89+ config . sys . urls . problem_code = 'https://www.lintcode.com/api/problems/$id/reset/?language=$lang' ;
90+ config . sys . urls . test = 'https://www.lintcode.com/api/submissions/' ;
91+ config . sys . urls . test_verify = 'https://www.lintcode.com/api/submissions/refresh/?id=$id&is_test_submission=true' ;
92+ config . sys . urls . submit_verify = 'https://www.lintcode.com/api/submissions/refresh/?id=$id' ;
93+ config . sys . urls . login = 'https://www.lintcode.com/api/accounts/signin/?next=%2F' ;
94+ } ;
95+
9596plugin . getProblems = function ( cb ) {
9697 log . debug ( 'running lintcode.getProblems' ) ;
9798
@@ -118,7 +119,7 @@ plugin.getProblems = function(cb) {
118119
119120plugin . getPageProblems = function ( page , cb ) {
120121 log . debug ( 'running lintcode.getPageProblems: ' + page ) ;
121- const opts = makeOpts ( config . URL_PROBLEMS . replace ( '$page' , page ) ) ;
122+ const opts = makeOpts ( config . sys . urls . problems . replace ( '$page' , page ) ) ;
122123
123124 spin . text = 'Downloading page ' + page ;
124125 request ( opts , function ( e , resp , body ) {
@@ -141,7 +142,7 @@ plugin.getPageProblems = function(page, cb) {
141142 companies : p . company_tags ,
142143 tags : [ ]
143144 } ;
144- problem . link = config . URL_PROBLEM . replace ( '$slug' , problem . slug ) ;
145+ problem . link = config . sys . urls . problem . replace ( '$slug' , problem . slug ) ;
145146 switch ( p . user_status ) {
146147 case 'Accepted' : problem . state = 'ac' ; break ;
147148 case 'Failed' : problem . state = 'notac' ; break ;
@@ -158,7 +159,7 @@ plugin.getPageProblems = function(page, cb) {
158159
159160plugin . getProblem = function ( problem , cb ) {
160161 log . debug ( 'running lintcode.getProblem' ) ;
161- const link = config . URL_PROBLEM_DETAIL . replace ( '$slug' , problem . slug ) ;
162+ const link = config . sys . urls . problem_detail . replace ( '$slug' , problem . slug ) ;
162163 const opts = makeOpts ( link ) ;
163164
164165 const spin = h . spin ( 'Downloading ' + problem . slug ) ;
@@ -194,8 +195,8 @@ plugin.getProblem = function(problem, cb) {
194195
195196plugin . getProblemCode = function ( problem , lang , cb ) {
196197 log . debug ( 'running lintcode.getProblemCode:' + lang . value ) ;
197- const url = config . URL_PROBLEM_CODE . replace ( '$id' , problem . id )
198- . replace ( '$lang' , lang . text . replace ( / \+ / g, '%2B' ) ) ;
198+ const url = config . sys . urls . problem_code . replace ( '$id' , problem . id )
199+ . replace ( '$lang' , lang . text . replace ( / \+ / g, '%2B' ) ) ;
199200 const opts = makeOpts ( url ) ;
200201
201202 const spin = h . spin ( 'Downloading code for ' + lang . text ) ;
@@ -211,7 +212,7 @@ plugin.getProblemCode = function(problem, lang, cb) {
211212
212213function runCode ( problem , isTest , cb ) {
213214 const lang = _ . find ( LANGS , x => x . value === h . extToLang ( problem . file ) ) ;
214- const opts = makeOpts ( config . URL_TEST ) ;
215+ const opts = makeOpts ( config . sys . urls . test ) ;
215216 opts . headers . referer = problem . link ;
216217 opts . form = {
217218 problem_id : problem . id ,
@@ -239,7 +240,7 @@ function runCode(problem, isTest, cb) {
239240
240241function verifyResult ( id , isTest , cb ) {
241242 log . debug ( 'running verifyResult:' + id ) ;
242- var url = isTest ? config . URL_TEST_VERIFY : config . URL_SUBMIT_VERIFY ;
243+ var url = isTest ? config . sys . urls . test_verify : config . sys . urls . submit_verify ;
243244 var opts = makeOpts ( url . replace ( '$id' , id ) ) ;
244245
245246 request ( opts , function ( e , resp , body ) {
@@ -321,7 +322,7 @@ plugin.starProblem = function(problem, starred, cb) {
321322plugin . login = function ( user , cb ) {
322323 log . debug ( 'running lintcode.login' ) ;
323324 const opts = {
324- url : config . URL_LOGIN ,
325+ url : config . sys . urls . login ,
325326 headers : {
326327 'x-csrftoken' : null
327328 } ,
0 commit comments