A Neovim plugin enabling you to solve LeetCode problems.
feat: check if question is for premium users only
6 files changed, +29 -6
+6-1lua/leetcode/api/types.lua
| @@ -249,7 +249,7 @@ | ||
| 249 | 249 | ---@field frontend_id integer |
| 250 | 250 | ---@field title string |
| 251 | 251 | ---@field title_slug string |
| 252 | ----@field id_paid_only boolean | |
| 252 | +---@field is_paid_only boolean | |
| 253 | 253 | ---@field difficulty string |
| 254 | 254 | ---@field likes integer |
| 255 | 255 | ---@field dislikes integer |
| @@ -261,9 +261,14 @@ | ||
| 261 | 261 | ---@field testcase_list string[] |
| 262 | 262 | ---@field meta_data lc.metadata |
| 263 | 263 | ---@field stats question_stats |
| 264 | +---@field topic_tags lc.topic_tag[] | |
| 264 | 265 | |
| 265 | 266 | ---@alias lc.question_res lc.QuestionResponse |
| 266 | 267 | |
| 268 | +---@class lc.topic_tag | |
| 269 | +---@field name string | |
| 270 | +---@field slug string | |
| 271 | + | |
| 267 | 272 | ---@class question_stats |
| 268 | 273 | ---@field acRate string |
| 269 | 274 | ---@field totalAccepted string |
+2-0lua/leetcode/config/init.lua
| @@ -27,7 +27,9 @@ function config.apply(cfg) | ||
| 27 | 27 | |
| 28 | 28 | config.debug = config.user.debug or false ---@diagnostic disable-line |
| 29 | 29 | config.domain = "https://leetcode." .. config.user.domain |
| 30 | + | |
| 30 | 31 | config.lang = config.user.lang |
| 32 | + config.sql = config.user.sql | |
| 31 | 33 | end |
| 32 | 34 | |
| 33 | 35 | return config |
+1-0lua/leetcode/config/template.lua
| @@ -24,6 +24,7 @@ | ||
| 24 | 24 | ---| "mysql" |
| 25 | 25 | ---| "mssql" |
| 26 | 26 | ---| "oraclesql" |
| 27 | +---| "postgresql" | |
| 27 | 28 | |
| 28 | 29 | ---@alias lc.domain |
| 29 | 30 | ---| "com" |
+9-2lua/leetcode/pickers/question.lua
| @@ -95,11 +95,18 @@ return { | ||
| 95 | 95 | sorter = conf.generic_sorter(opts), |
| 96 | 96 | attach_mappings = function(prompt_bufnr, map) |
| 97 | 97 | actions.select_default:replace(function() |
| 98 | - actions.close(prompt_bufnr) | |
| 99 | 98 | local selection = action_state.get_selected_entry() |
| 100 | 99 | |
| 101 | 100 | if not selection then return end |
| 102 | - Question:init(selection.value) | |
| 101 | + | |
| 102 | + local q = selection.value | |
| 103 | + if q.paid_only and not config.auth.is_premium then | |
| 104 | + log.warn("Question is for premium users only") | |
| 105 | + return | |
| 106 | + end | |
| 107 | + | |
| 108 | + actions.close(prompt_bufnr) | |
| 109 | + Question:init(q) | |
| 103 | 110 | end) |
| 104 | 111 | return true |
| 105 | 112 | end, |
+10-2lua/leetcode/ui/question.lua
| @@ -12,6 +12,7 @@ local utils = require("leetcode.utils") | ||
| 12 | 12 | ---@field bufnr integer |
| 13 | 13 | ---@field console lc.Console |
| 14 | 14 | ---@field lang string |
| 15 | +---@field sql string | |
| 15 | 16 | local question = {} |
| 16 | 17 | question.__index = question |
| 17 | 18 | |
| @@ -23,7 +24,6 @@ _Lc_curr_question = 0 | ||
| 23 | 24 | ---@private |
| 24 | 25 | function question:create_file() |
| 25 | 26 | local snippets = self.q.code_snippets |
| 26 | - | |
| 27 | 27 | local snippet = {} |
| 28 | 28 | |
| 29 | 29 | for _, snip in pairs(snippets ~= vim.NIL and snippets or {}) do |
| @@ -89,11 +89,18 @@ function question:init(problem) | ||
| 89 | 89 | local tabp = utils.detect_duplicate_question(problem.title_slug, config.lang) |
| 90 | 90 | if tabp then |
| 91 | 91 | pcall(vim.cmd.tabnext, tabp) |
| 92 | - return log.info("Question already opened") | |
| 92 | + log.info("Question already opened") | |
| 93 | + return | |
| 93 | 94 | end |
| 94 | 95 | |
| 95 | 96 | local q = api_question.by_title_slug(problem.title_slug) |
| 97 | + if q.is_paid_only and not config.auth.is_premium then | |
| 98 | + log.warn("Question is for premium users only") | |
| 99 | + return | |
| 100 | + end | |
| 101 | + | |
| 96 | 102 | local lang = config.lang |
| 103 | + local sql = config.sql | |
| 97 | 104 | |
| 98 | 105 | local ft = utils.filetype(lang) |
| 99 | 106 | local fn = string.format("%s.%s.%s", q.frontend_id, q.title_slug, ft) |
| @@ -103,6 +110,7 @@ function question:init(problem) | ||
| 103 | 110 | file = file, |
| 104 | 111 | q = q, |
| 105 | 112 | lang = lang, |
| 113 | + sql = sql, | |
| 106 | 114 | }, self) |
| 107 | 115 | |
| 108 | 116 | return obj:mount() |