From a87676ce500270f3eae78b3cab6a0637115b303a Mon Sep 17 00:00:00 2001 From: Ancient77 <76914086+Ancient77@users.noreply.github.com> Date: Tue, 6 Jun 2023 10:05:20 +0000 Subject: [PATCH] fixed not finding problems which have not category --- lib/config.js | 1 + lib/plugins/leetcode.js | 62 ++++++++++++++--------------------------- 2 files changed, 22 insertions(+), 41 deletions(-) diff --git a/lib/config.js b/lib/config.js index 82cfee17..10627dbc 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 93d66053..d7f7c164 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();