diff --git a/lib/config.js b/lib/config.js index 82cfee1..10627db 100644 --- a/lib/config.js +++ b/lib/config.js @@ -52,6 +52,7 @@ const DEFAULT_CONFIG = { linkedin_session_request: 'https://www.linkedin.com/checkpoint/lg/login-submit', // questions urls problems: 'https://leetcode.com/api/problems/$category/', + all_problems: 'https://leetcode.com/api/problems/all/', problem: 'https://leetcode.com/problems/$slug/description/', test: 'https://leetcode.com/problems/$slug/interpret_solution/', session: 'https://leetcode.com/session/', diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index 93d6605..d7f7c16 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -57,32 +57,9 @@ plugin.init = function() { plugin.getProblems = function (needTranslation, cb) { log.debug('running leetcode.getProblems'); let problems = []; - const getCategory = function(category, queue, cb) { - plugin.getCategoryProblems(category, function(e, _problems) { - if (e) { - log.debug(category + ': failed to getProblems: ' + e.msg); - } else { - log.debug(category + ': getProblems got ' + _problems.length + ' problems'); - problems = problems.concat(_problems); - } - return cb(e); - }); - }; - - spin = h.spin('Downloading problems'); - const q = new Queue(config.sys.categories, {}, getCategory); - q.run(null, function(e) { - spin.stop(); - return cb(e, problems); - }); -}; + const opts = plugin.makeOpts(config.sys.urls.all_problems); -plugin.getCategoryProblems = function(category, cb) { - log.debug('running leetcode.getCategoryProblems: ' + category); - const opts = plugin.makeOpts(config.sys.urls.problems.replace('$category', category)); - - spin.text = 'Downloading category ' + category; - request(opts, function(e, resp, body) { + request(opts, function (e, resp, body) { e = plugin.checkError(e, resp, 200); if (e) return cb(e); @@ -96,27 +73,30 @@ plugin.getCategoryProblems = function(category, cb) { } const problems = json.stat_status_pairs - .filter((p) => !p.stat.question__hide) - .map(function(p) { - return { - state: p.status || 'None', - id: p.stat.question_id, - fid: p.stat.frontend_question_id, - name: p.stat.question__title, - slug: p.stat.question__title_slug, - link: config.sys.urls.problem.replace('$slug', p.stat.question__title_slug), - locked: p.paid_only, - percent: p.stat.total_acs * 100 / p.stat.total_submitted, - level: h.levelToName(p.difficulty.level), - starred: p.is_favor, - category: json.category_slug - }; - }); + .filter((p) => !p.stat.question__hide) + .map(function (p) { + return { + state: p.status || 'None', + id: p.stat.question_id, + fid: p.stat.frontend_question_id, + name: p.stat.question__title, + slug: p.stat.question__title_slug, + link: config.sys.urls.problem.replace('$slug', p.stat.question__title_slug), + locked: p.paid_only, + percent: p.stat.total_acs * 100 / p.stat.total_submitted, + level: h.levelToName(p.difficulty.level), + starred: p.is_favor, + category: json.category_slug + }; + }); return cb(null, problems); }); + return cb(null, problems); }; + + plugin.getProblem = function(problem, needTranslation, cb) { log.debug('running leetcode.getProblem'); const user = session.getUser(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy