Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down
62 changes: 21 additions & 41 deletions lib/plugins/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
Expand Down