@@ -15,6 +15,8 @@ var session = require('../session');
15
15
var plugin = new Plugin ( 10 , 'leetcode' , '' ,
16
16
'Plugin to talk with leetcode APIs.' ) ;
17
17
18
+ var spin ;
19
+
18
20
// update options with user credentials
19
21
function signOpts ( opts , user ) {
20
22
opts . headers . Cookie = 'LEETCODE_SESSION=' + user . sessionId +
@@ -49,7 +51,6 @@ function checkError(e, resp, expectedStatus) {
49
51
50
52
plugin . getProblems = function ( cb ) {
51
53
log . debug ( 'running leetcode.getProblems' ) ;
52
-
53
54
var problems = [ ] ;
54
55
var doTask = function ( category , taskDone ) {
55
56
plugin . getCategoryProblems ( category , function ( e , _problems ) {
@@ -63,7 +64,9 @@ plugin.getProblems = function(cb) {
63
64
} ) ;
64
65
} ;
65
66
67
+ spin = h . spin ( 'Downloading problems' ) ;
66
68
queue . run ( config . sys . categories , doTask , function ( e ) {
69
+ spin . stop ( ) ;
67
70
return cb ( e , problems ) ;
68
71
} ) ;
69
72
} ;
@@ -72,6 +75,7 @@ plugin.getCategoryProblems = function(category, cb) {
72
75
log . debug ( 'running leetcode.getCategoryProblems: ' + category ) ;
73
76
var opts = makeOpts ( config . sys . urls . problems . replace ( '$category' , category ) ) ;
74
77
78
+ spin . text = 'Downloading category ' + category ;
75
79
request ( opts , function ( e , resp , body ) {
76
80
e = checkError ( e , resp , 200 ) ;
77
81
if ( e ) return cb ( e ) ;
@@ -140,7 +144,9 @@ plugin.getProblem = function(problem, cb) {
140
144
operationName : 'getQuestionDetail'
141
145
} ;
142
146
147
+ spin = h . spin ( 'Downloading ' + problem . slug ) ;
143
148
request . post ( opts , function ( e , resp , body ) {
149
+ spin . stop ( ) ;
144
150
e = checkError ( e , resp , 200 ) ;
145
151
if ( e ) return cb ( e ) ;
146
152
@@ -175,7 +181,9 @@ function runCode(opts, problem, cb) {
175
181
typed_code : h . getFileData ( problem . file )
176
182
} ) ;
177
183
184
+ spin = h . spin ( 'Sending code to judge' ) ;
178
185
request ( opts , function ( e , resp , body ) {
186
+ spin . stop ( ) ;
179
187
e = checkError ( e , resp , 200 ) ;
180
188
if ( e ) return cb ( e ) ;
181
189
@@ -207,7 +215,9 @@ function verifyResult(opts, jobs, results, cb) {
207
215
opts . method = 'GET' ;
208
216
opts . url = config . sys . urls . verify . replace ( '$id' , jobs [ 0 ] . id ) ;
209
217
218
+ spin = h . spin ( 'Waiting for judge result' ) ;
210
219
request ( opts , function ( e , resp , body ) {
220
+ spin . stop ( ) ;
211
221
e = checkError ( e , resp , 200 ) ;
212
222
if ( e ) return cb ( e ) ;
213
223
@@ -366,7 +376,9 @@ plugin.getFavorites = function(cb) {
366
376
367
377
plugin . signin = function ( user , cb ) {
368
378
log . debug ( 'running leetcode.signin' ) ;
379
+ spin = h . spin ( 'Signing in leetcode.com' ) ;
369
380
request ( config . sys . urls . login , function ( e , resp , body ) {
381
+ spin . stop ( ) ;
370
382
e = checkError ( e , resp , 200 ) ;
371
383
if ( e ) return cb ( e ) ;
372
384
0 commit comments