Skip to content

Commit da53ca2

Browse files
committed
domain name change
1 parent 1b46197 commit da53ca2

File tree

15 files changed

+140
-164
lines changed

15 files changed

+140
-164
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'com.shuzijun.leetcode'
8-
version (System.getenv('LD_VERSION')==null ? "6.10":System.getenv('LD_VERSION')) + (project.build_env.isEmpty() ? "" : "-") + project.build_env
8+
version (System.getenv('LD_VERSION')==null ? "6.11":System.getenv('LD_VERSION')) + (project.build_env.isEmpty() ? "" : "-") + project.build_env
99

1010
sourceCompatibility = 1.8
1111
targetCompatibility = 1.8
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.shuzijun.leetcode.plugin.actions.toolbar;
2+
3+
import com.intellij.ide.BrowserUtil;
4+
import com.intellij.openapi.actionSystem.AnAction;
5+
import com.intellij.openapi.actionSystem.AnActionEvent;
6+
7+
/**
8+
* @author shuzijun
9+
*/
10+
public class DonateAction extends AnAction {
11+
@Override
12+
public void actionPerformed(AnActionEvent anActionEvent) {
13+
BrowserUtil.browse("https://shuzijun.cn/donate.html");
14+
}
15+
16+
}

src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindTagAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void setSelected(AnActionEvent anActionEvent, boolean b) {
5151
@Override
5252
public void run(@NotNull ProgressIndicator progressIndicator) {
5353
if (b) {
54-
ViewManager.loadServiceData(tree, anActionEvent.getProject(), tag.getSlug());
54+
ViewManager.loadServiceData(tree, anActionEvent.getProject(), tag.getType());
5555
} else {
5656
ViewManager.loadServiceData(tree, anActionEvent.getProject());
5757
}

src/main/java/com/shuzijun/leetcode/plugin/manager/QuestionManager.java

Lines changed: 61 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -32,67 +32,21 @@ public class QuestionManager {
3232
private final static String TRANSLATIONNAME = "translation.json";
3333

3434

35-
public static List<Question> getQuestionService(Project project, String categorySlug) {
36-
Boolean isPremium = false;
37-
if (HttpRequestUtils.isLogin()) {
38-
HttpRequest httpRequest = HttpRequest.post(URLUtils.getLeetcodeGraphql(), "application/json");
39-
httpRequest.setBody("{\"query\":\"\\n query globalData {\\n userStatus {\\n isSignedIn\\n isPremium\\n username\\n realName\\n avatar\\n userSlug\\n isAdmin\\n useTranslation\\n premiumExpiredAt\\n isTranslator\\n isSuperuser\\n isPhoneVerified\\n }\\n jobsMyCompany {\\n nameSlug\\n }\\n commonNojPermissionTypes\\n}\\n \",\"variables\":{},\"operationName\":\"globalData\"}");
40-
httpRequest.addHeader("Accept", "application/json");
41-
HttpResponse response = HttpRequestUtils.executePost(httpRequest);
42-
if (response != null && response.getStatusCode() == 200) {
43-
JSONObject user = JSONObject.parseObject(response.getBody()).getJSONObject("data").getJSONObject("userStatus");
44-
isPremium = user.getBoolean("isPremium");
45-
ApplicationManager.getApplication().invokeAndWait(() -> {
46-
WindowFactory.updateTitle(project, user.getString("username"));
47-
});
48-
} else {
49-
LogUtils.LOG.error("Request userStatus failed, status:" + response == null ? "" : response.getStatusCode());
50-
}
51-
}
52-
List<Question> questionList = new ArrayList<>();
53-
int skip = 0;
54-
int limit = 100;
55-
int total = -1;
56-
while(true) {
57-
try {
58-
Map<String, Object> page = getQuestionPage(categorySlug, skip, limit, isPremium);
59-
if (total < 0) {
60-
total = (int) page.get("total");
61-
}
62-
questionList.addAll((List) page.get("questionList"));
63-
skip = skip + limit;
64-
if(total <= skip){
65-
break;
66-
}
67-
} catch (Exception e) {
68-
return null;
69-
}
35+
public static List<Question> getQuestionService(Project project, String url) {
36+
List<Question> questionList = null;
7037

38+
HttpRequest httpRequest = HttpRequest.get(url);
39+
HttpResponse response = HttpRequestUtils.executeGet(httpRequest);
40+
if (response != null && response.getStatusCode() == 200) {
41+
questionList = parseQuestion(response.getBody());
42+
JSONObject jsonObject = JSONObject.parseObject(response.getBody());
43+
ApplicationManager.getApplication().invokeAndWait(() -> {
44+
WindowFactory.updateTitle(project, jsonObject.getString("user_name"));
45+
});
46+
} else {
47+
LogUtils.LOG.error("Request question list failed, status:" + response == null ? "" : response.getStatusCode());
7148
}
7249

73-
String dayQuestion = questionOfToday();
74-
Collections.sort(questionList, new Comparator<Question>() {
75-
@Override
76-
public int compare(Question arg0, Question arg1) {
77-
String frontendId0 = arg0.getFrontendQuestionId();
78-
String frontendId1 = arg1.getFrontendQuestionId();
79-
if (frontendId0.equals(dayQuestion)) {
80-
return -1;
81-
} else if (frontendId1.equals(dayQuestion)) {
82-
return 1;
83-
} else if (StringUtils.isNumeric(frontendId0) && StringUtils.isNumeric(frontendId1)) {
84-
return Integer.valueOf(frontendId0).compareTo(Integer.valueOf(frontendId1));
85-
} else if (StringUtils.isNumeric(frontendId0)) {
86-
return -1;
87-
} else if (StringUtils.isNumeric(frontendId1)) {
88-
return 1;
89-
} else {
90-
return frontendId0.compareTo(frontendId1);
91-
}
92-
93-
}
94-
});
95-
9650
if (questionList != null && !questionList.isEmpty()) {
9751
String filePath = PersistentConfig.getInstance().getTempFilePath() + ALLNAME;
9852
FileUtils.saveFile(filePath, JSON.toJSONString(questionList));
@@ -102,28 +56,6 @@ public int compare(Question arg0, Question arg1) {
10256

10357
}
10458

105-
private static Map<String, Object> getQuestionPage(String categorySlug, int skip, int limit, Boolean isPremium) throws Exception {
106-
HttpRequest httpRequest = HttpRequest.post(URLUtils.getLeetcodeGraphql(), "application/json");
107-
if (URLUtils.isCn()) {
108-
httpRequest.setBody("{\"query\":\"\\n query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) {\\n problemsetQuestionList(\\n categorySlug: $categorySlug\\n limit: $limit\\n skip: $skip\\n filters: $filters\\n ) {\\n hasMore\\n total\\n questions {\\n acRate\\n difficulty\\n freqBar\\n frontendQuestionId\\n isFavor\\n paidOnly\\n solutionNum\\n status\\n title\\n titleCn\\n titleSlug\\n topicTags {\\n name\\n nameTranslated\\n id\\n slug\\n }\\n extra {\\n hasVideoSolution\\n topCompanyTags {\\n imgUrl\\n slug\\n numSubscribed\\n }\\n }\\n }\\n }\\n}\\n \",\"variables\":{\"categorySlug\":\""+categorySlug+"\",\"skip\":" + skip + ",\"limit\":" + limit + ",\"filters\":{}},\"operationName\":\"problemsetQuestionList\"}");
109-
} else {
110-
httpRequest.setBody("{\"query\":\"\\n query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) {\\n problemsetQuestionList: questionList(\\n categorySlug: $categorySlug\\n limit: $limit\\n skip: $skip\\n filters: $filters\\n ) {\\n total: totalNum\\n questions: data {\\n acRate\\n difficulty\\n freqBar\\n frontendQuestionId: questionFrontendId\\n isFavor\\n paidOnly: isPaidOnly\\n status\\n title\\n titleSlug\\n topicTags {\\n name\\n id\\n slug\\n }\\n hasSolution\\n hasVideoSolution\\n }\\n }\\n}\\n \",\"variables\":{\"categorySlug\":\"" + categorySlug + "\",\"skip\":" + skip + ",\"limit\":" + limit + ",\"filters\":{}},\"operationName\":\"problemsetQuestionList\"}");
111-
}
112-
httpRequest.addHeader("Accept", "application/json");
113-
HttpResponse response = HttpRequestUtils.executePost(httpRequest);
114-
if (response != null && response.getStatusCode() == 200) {
115-
List questionList = parseQuestion(response.getBody(), isPremium);
116-
Integer total = JSONObject.parseObject(response.getBody()).getJSONObject("data").getJSONObject("problemsetQuestionList").getInteger("total");
117-
Map<String, Object> page = new HashMap<>();
118-
page.put("total", total);
119-
page.put("questionList", questionList);
120-
return page;
121-
} else {
122-
LogUtils.LOG.error("Request question list failed, status:" + response == null ? "" : response.getStatusCode());
123-
throw new RuntimeException("Request question list failed");
124-
}
125-
}
126-
12759
public static List<Question> getQuestionCache() {
12860
if (QUESTIONLIST != null) {
12961
return QUESTIONLIST;
@@ -243,15 +175,15 @@ public static List<Tag> getLists() {
243175
return tags;
244176
}
245177

246-
public static List<Tag> getCategory(String categorySlug) {
178+
public static List<Tag> getCategory(String url) {
247179
List<Tag> tags = new ArrayList<>();
248180

249181
HttpRequest httpRequest = HttpRequest.get(URLUtils.getLeetcodeCardInfo());
250182
HttpResponse response = HttpRequestUtils.executeGet(httpRequest);
251183
if (response != null && response.getStatusCode() == 200) {
252184
try {
253185
String body = response.getBody();
254-
tags = parseCategory(body, categorySlug);
186+
tags = parseCategory(body, url);
255187
} catch (Exception e1) {
256188
LogUtils.LOG.error("Request CardInfo exception", e1);
257189
}
@@ -262,52 +194,75 @@ public static List<Tag> getCategory(String categorySlug) {
262194
}
263195

264196

265-
private static List<Question> parseQuestion(String str, Boolean isPremium) {
197+
private static List<Question> parseQuestion(String str) {
266198

267199
List<Question> questionList = new ArrayList<Question>();
268200

269201
if (StringUtils.isNotBlank(str)) {
270-
JSONObject jsonObject = JSONObject.parseObject(str).getJSONObject("data").getJSONObject("problemsetQuestionList");
271-
JSONArray jsonArray = jsonObject.getJSONArray("questions");
202+
JSONObject jsonObject = JSONObject.parseObject(str);
203+
Boolean isPremium = new Integer("0").equals(jsonObject.getInteger("frequency_high")); //Premium users display frequency
204+
JSONArray jsonArray = jsonObject.getJSONArray("stat_status_pairs");
272205
for (int i = 0; i < jsonArray.size(); i++) {
273206
JSONObject object = jsonArray.getJSONObject(i);
274-
Question question = new Question(object.getString("title"));
275-
if (URLUtils.isCn() && !PersistentConfig.getInstance().getConfig().getEnglishContent()) {
276-
question.setTitle(object.getString("titleCn"));
277-
}
207+
Question question = new Question(object.getJSONObject("stat").getString("question__title"));
278208
question.setLeaf(Boolean.TRUE);
279-
question.setQuestionId(object.getString("frontendQuestionId"));
280-
question.setFrontendQuestionId(object.getString("frontendQuestionId"));
209+
question.setQuestionId(object.getJSONObject("stat").getString("question_id"));
210+
question.setFrontendQuestionId(object.getJSONObject("stat").getString("frontend_question_id"));
281211
try {
282-
if (object.getBoolean("paidOnly") && !isPremium) {
283-
question.setStatus("lock");
212+
if (object.getBoolean("paid_only") && isPremium) {
213+
question.setStatus(object.getBoolean("paid_only") ? "lock" : null);
284214
} else {
285-
question.setStatus(object.get("status") == null ? "" : object.getString("status").toLowerCase());
215+
question.setStatus(object.get("status") == null ? "" : object.getString("status"));
286216
}
287217
} catch (Exception ee) {
288218
question.setStatus("");
289219
}
290-
question.setTitleSlug(object.getString("titleSlug"));
291-
question.setLevel(object.getString("difficulty"));
220+
question.setTitleSlug(object.getJSONObject("stat").getString("question__title_slug"));
221+
question.setLevel(object.getJSONObject("difficulty").getInteger("level"));
292222
try {
293-
if (object.containsKey("hasSolution")) {
294-
if (object.getBoolean("hasSolution")) {
295-
question.setArticleLive(Constant.ARTICLE_LIVE_ONE);
296-
question.setArticleSlug(object.getString("titleSlug"));
297-
} else {
223+
if (object.getJSONObject("stat").containsKey("question__article__live")) {
224+
if (object.getJSONObject("stat").get("question__article__live") == null
225+
|| !object.getJSONObject("stat").getBoolean("question__article__live")) {
298226
question.setArticleLive(Constant.ARTICLE_LIVE_NONE);
227+
} else {
228+
question.setArticleLive(Constant.ARTICLE_LIVE_ONE);
229+
question.setArticleSlug(object.getJSONObject("stat").getString("question__title_slug"));
299230
}
300-
} else if (object.containsKey("solutionNum")) {
301-
question.setArticleLive(Constant.ARTICLE_LIVE_LIST);
302231
} else {
303-
question.setArticleLive(Constant.ARTICLE_LIVE_NONE);
232+
question.setArticleLive(Constant.ARTICLE_LIVE_LIST);
304233
}
305234
} catch (Exception e) {
306235
LogUtils.LOG.error("Identify abnormal article", e);
307236
question.setArticleLive(Constant.ARTICLE_LIVE_NONE);
308237
}
309238
questionList.add(question);
310239
}
240+
241+
translation(questionList);
242+
243+
String dayQuestion = questionOfToday();
244+
245+
Collections.sort(questionList, new Comparator<Question>() {
246+
@Override
247+
public int compare(Question arg0, Question arg1) {
248+
String frontendId0 = arg0.getFrontendQuestionId();
249+
String frontendId1 = arg1.getFrontendQuestionId();
250+
if (frontendId0.equals(dayQuestion)) {
251+
return -1;
252+
} else if (frontendId1.equals(dayQuestion)) {
253+
return 1;
254+
} else if (StringUtils.isNumeric(frontendId0) && StringUtils.isNumeric(frontendId1)) {
255+
return Integer.valueOf(frontendId0).compareTo(Integer.valueOf(frontendId1));
256+
} else if (StringUtils.isNumeric(frontendId0)) {
257+
return -1;
258+
} else if (StringUtils.isNumeric(frontendId1)) {
259+
return 1;
260+
} else {
261+
return frontendId0.compareTo(frontendId1);
262+
}
263+
264+
}
265+
});
311266
}
312267
return questionList;
313268

@@ -399,7 +354,7 @@ private static List<Tag> parseTag(String str) {
399354
return tags;
400355
}
401356

402-
private static List<Tag> parseCategory(String str, String categorySlug) {
357+
private static List<Tag> parseCategory(String str, String url) {
403358
List<Tag> tags = new ArrayList<Tag>();
404359

405360
if (StringUtils.isNotBlank(str)) {
@@ -411,7 +366,7 @@ private static List<Tag> parseCategory(String str, String categorySlug) {
411366
tag.setSlug(object.getString("slug"));
412367
tag.setType(URLUtils.getLeetcodeUrl() + "/api" + object.getString("url").replace("problemset", "problems"));
413368
tag.setName(object.getString("title"));
414-
if (categorySlug.contains(tag.getSlug())) {
369+
if (url.contains(tag.getType())) {
415370
tag.setSelect(true);
416371
}
417372
tags.add(tag);

src/main/java/com/shuzijun/leetcode/plugin/manager/ViewManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.shuzijun.leetcode.plugin.model.Tag;
1212
import com.shuzijun.leetcode.plugin.utils.MessageUtils;
1313
import com.shuzijun.leetcode.plugin.utils.PropertiesUtils;
14+
import com.shuzijun.leetcode.plugin.utils.URLUtils;
1415
import com.shuzijun.leetcode.plugin.window.WindowFactory;
1516

1617
import javax.swing.*;
@@ -35,11 +36,11 @@ public class ViewManager {
3536
private static boolean intersection = Boolean.FALSE;
3637

3738
public static void loadServiceData(JTree tree, Project project) {
38-
loadServiceData(tree, project, "");
39+
loadServiceData(tree, project, URLUtils.getLeetcodeAll());
3940
}
4041

41-
public static void loadServiceData(JTree tree, Project project, String categorySlug) {
42-
List<Question> questionList = QuestionManager.getQuestionService(project, categorySlug);
42+
public static void loadServiceData(JTree tree, Project project, String url) {
43+
List<Question> questionList = QuestionManager.getQuestionService(project, url);
4344
if (questionList == null || questionList.isEmpty()) {
4445
MessageUtils.getInstance(project).showWarnMsg("warning", PropertiesUtils.getInfo("response.cache"));
4546
questionList = QuestionManager.getQuestionCache();
@@ -60,7 +61,7 @@ public String apply(Question question) {
6061
filter.put(Constant.FIND_TYPE_STATUS, QuestionManager.getStatus());
6162
filter.put(Constant.FIND_TYPE_LISTS, QuestionManager.getLists());
6263
filter.put(Constant.FIND_TYPE_TAGS, QuestionManager.getTags());
63-
filter.put(Constant.FIND_TYPE_CATEGORY, QuestionManager.getCategory(categorySlug));
64+
filter.put(Constant.FIND_TYPE_CATEGORY, QuestionManager.getCategory(url));
6465

6566

6667
DefaultTreeModel treeMode = (DefaultTreeModel) tree.getModel();

src/main/java/com/shuzijun/leetcode/plugin/model/Question.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,6 @@ public void setLevel(Integer level) {
104104
this.level = level;
105105
}
106106

107-
public void setLevel(String difficulty) {
108-
if(difficulty == null){
109-
this.level = 0;
110-
}else if("easy".equalsIgnoreCase(difficulty)){
111-
this.level = 1;
112-
}else if("medium".equalsIgnoreCase(difficulty)){
113-
this.level = 2;
114-
}else if("hard".equalsIgnoreCase(difficulty)){
115-
this.level = 3;
116-
}else {
117-
this.level = 0;
118-
}
119-
}
120-
121107
public String getStatus() {
122108
return status;
123109
}

src/main/java/com/shuzijun/leetcode/plugin/model/Tag.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.shuzijun.leetcode.plugin.model;
22

3-
import org.apache.commons.lang3.StringUtils;
4-
53
import java.util.Comparator;
64
import java.util.TreeSet;
75

@@ -17,15 +15,7 @@ public class Tag {
1715
private TreeSet<String> questions = new TreeSet<String>(new Comparator<String>() {
1816
@Override
1917
public int compare(String arg0, String arg1) {
20-
if (StringUtils.isNumeric(arg0) && StringUtils.isNumeric(arg1)) {
21-
return Integer.valueOf(arg0).compareTo(Integer.valueOf(arg1));
22-
} else if (StringUtils.isNumeric(arg0)) {
23-
return -1;
24-
} else if (StringUtils.isNumeric(arg1)) {
25-
return 1;
26-
} else {
27-
return arg0.compareTo(arg1);
28-
}
18+
return Integer.valueOf(arg0).compareTo(Integer.valueOf(arg1));
2919
}
3020
});
3121

0 commit comments

Comments
 (0)