MCPcopy
hub / github.com/skygragon/leetcode-cli / runCode

Function runCode

lib/plugins/leetcode.js:177–218  ·  view source on GitHub ↗
(opts, problem, cb)

Source from the content-addressed store, hash-verified

175};
176
177function runCode(opts, problem, cb) {
178 opts.method = 'POST';
179 opts.headers.Origin = config.sys.urls.base;
180 opts.headers.Referer = problem.link;
181 opts.json = true;
182 opts._delay = opts._delay || config.network.delay || 1; // in seconds
183
184 opts.body = opts.body || {};
185 _.extendOwn(opts.body, {
186 lang: problem.lang,
187 question_id: parseInt(problem.id, 10),
188 test_mode: false,
189 typed_code: file.data(problem.file)
190 });
191
192 const spin = h.spin('Sending code to judge');
193 request(opts, function(e, resp, body) {
194 spin.stop();
195 e = plugin.checkError(e, resp, 200);
196 if (e) return cb(e);
197
198 if (body.error) {
199 if (!body.error.includes('too soon'))
200 return cb(body.error);
201
202 // hit 'run code too soon' error, have to wait a bit
203 log.debug(body.error);
204
205 // linear wait
206 ++opts._delay;
207 log.debug('Will retry after %d seconds...', opts._delay);
208
209 const reRun = _.partial(runCode, opts, problem, cb);
210 return setTimeout(reRun, opts._delay * 1000);
211 }
212
213 opts.json = false;
214 opts.body = null;
215
216 return cb(null, body);
217 });
218}
219
220function verifyResult(task, queue, cb) {
221 const opts = queue.ctx.opts;

Callers 1

leetcode.jsFile · 0.85

Calls 1

cbFunction · 0.85

Tested by

no test coverage detected