Skip to content

domain name change #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2022
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- [Custom Code](https://github.com/shuzijun/leetcode-editor/blob/master/doc/CustomCode.md) ([demo](https://github.com/shuzijun/leetcode-question))

## Introduction
Do Leetcode exercises in IDE, support `leetcode.com` and `leetcode-cn.com`, to meet the basic needs of doing exercises.
Do Leetcode exercises in IDE, support `leetcode.com` and `leetcode.cn`, to meet the basic needs of doing exercises.
Support theoretically: IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion GoLand DataGrip Rider MPS Android Studio.
<a href="http://shuzijun.cn/leetcode-editor/monitor.html" target="_blank">be with you!</a>

Expand All @@ -35,7 +35,7 @@
</p>

- **Configuration path**: `File` -> `settings`->`tools`->`leetcode plugin`
- **`URL options`**: `leetcode.com`OR`leetcode-cn.com`
- **`URL options`**: `leetcode.com`OR`leetcode.cn`
- **`Code Type`**: `Java`,`Python`,`C++`,`Python3`,`C`,`C#`,`JavaScript`,`Ruby`,`Swift`,`Go` ,`Scala`,`Kotlin`,`Rust`,`PHP`,`Bash`,`SQL`
- **`LoginName`**: Login Username
- **`Password`**: Login password
Expand Down
4 changes: 2 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- [自定义代码生成](https://github.com/shuzijun/leetcode-editor/blob/master/doc/CustomCode_ZH.md) ([示例](https://github.com/shuzijun/leetcode-question))

## 简介
在IDE中解决LeetCode问题,支持`leetcode.com`与`leetcode-cn.com`,满足基本的做题需求。
在IDE中解决LeetCode问题,支持`leetcode.com`与`leetcode.cn`,满足基本的做题需求。
理论上支持: IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion GoLand DataGrip Rider MPS Android Studio。
[be with you!](http://shuzijun.cn/leetcode-editor/monitor.html)

Expand All @@ -35,7 +35,7 @@
</p>

- **配置路径**: `File` -> `settings`->`tools`->`leetcode plugin`
- **`URL可选项`**: `leetcode.com`与`leetcode-cn.com`
- **`URL可选项`**: `leetcode.com`与`leetcode.cn`
- **`Code Type`**: `Java`,`Python`,`C++`,`Python3`,`C`,`C#`,`JavaScript`,`Ruby`,`Swift`,`Go` ,`Scala`,`Kotlin`,`Rust`,`PHP`,`Bash`,`SQL`
- **`LoginName`**: 登录用户名
- **`Password`**: 登录密码
Expand Down
2 changes: 1 addition & 1 deletion doc/LoginHelp_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- [中文文档](#登录配置)
登录方式:配置用户名密码登录,cookie登录,浏览器登录
## 用户名密码登录
在leetcode插件配置页配置用户名密码,如登录失败将加载下面两种登录方式,此方式仅支持leetcode-cn.com
在leetcode插件配置页配置用户名密码,如登录失败将加载下面两种登录方式,此方式仅支持leetcode.cn
## cookie登录
首先在浏览器中登录leetcode,打开浏览器控制台,复制cookie到登录弹出框,点击login.[参考](https://developers.google.com/web/tools/chrome-devtools/network?hl=zh_cn)
<p align="center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void actionPerformed(AnActionEvent anActionEvent, Config config) {
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null"));
return;
}
if(!URLUtils.getLeetcodeHost().equals(leetcodeEditor.getHost())){
if(!URLUtils.equalsHost(leetcodeEditor.getHost())){
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.host"));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void update(@NotNull AnActionEvent anActionEvent) {
return;
}
LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(anActionEvent.getProject()).getEditor(vf.getPath());
if (leetcodeEditor == null || StringUtils.isBlank(leetcodeEditor.getTitleSlug()) || !URLUtils.getLeetcodeHost().equals(leetcodeEditor.getHost())) {
if (leetcodeEditor == null || StringUtils.isBlank(leetcodeEditor.getTitleSlug()) || !URLUtils.equalsHost(leetcodeEditor.getHost())) {
anActionEvent.getPresentation().setEnabled(false);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ public boolean isModified(Config config){
if(config ==null){
return false;
}
if (!Objects.equals(version, config.version)) return false;
if (!Objects.equals(loginName, config.loginName)) return false;
if (!Objects.equals(filePath, config.filePath)) return false;
if (!Objects.equals(codeType, config.codeType)) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class Constant {
public static final Integer PLUGIN_CONFIG_VERSION_1 = 1;
//第二版本,不兼容之前的临时目录,从此版本开始更换新临时目录
public static final Integer PLUGIN_CONFIG_VERSION_2 = 2;
//第三版本,域名更新,需要将cookie更改一下域名
public static final Integer PLUGIN_CONFIG_VERSION_3 = 3;

/**
* 默认题目颜色
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
import com.intellij.openapi.components.*;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.shuzijun.leetcode.plugin.model.Config;
import com.shuzijun.leetcode.plugin.model.Constant;
import com.shuzijun.leetcode.plugin.model.PluginConstant;
import com.shuzijun.leetcode.plugin.utils.MessageUtils;
import com.shuzijun.leetcode.plugin.utils.PropertiesUtils;
import com.shuzijun.leetcode.plugin.utils.URLUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
Expand Down Expand Up @@ -46,11 +50,27 @@ public void loadState(@NotNull PersistentConfig persistentConfig) {
}

public Config getInitConfig() {
return initConfig.get(INITNAME);
Config config = initConfig.get(INITNAME);
if (config != null && config.getVersion() != null && config.getVersion() < Constant.PLUGIN_CONFIG_VERSION_3) {
if (URLUtils.leetcodecnOld.equals(config.getUrl())) {
config.setUrl(URLUtils.leetcodecn);
}
Iterator<String> iterator = config.getUserCookie().keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
String value = config.getCookie(key);
if (StringUtils.isBlank(value) || key.startsWith(URLUtils.leetcodecnOld)) {
iterator.remove();
}
}
config.setVersion(Constant.PLUGIN_CONFIG_VERSION_3);
setInitConfig(config);
}
return config;
}

public Config getConfig() {
Config config = initConfig.get(INITNAME);
Config config = getInitConfig();
if (config == null) {
MessageUtils.showAllWarnMsg("warning", PropertiesUtils.getInfo("config.first"));
throw new UnsupportedOperationException("not configured:File -> settings->tools->leetcode plugin");
Expand All @@ -69,10 +89,10 @@ public String getTempFilePath() {
}

public void savePassword(String password, String username) {
if(username == null || password == null){
if (username == null || password == null) {
return;
}
PasswordSafe.getInstance().set(new CredentialAttributes(PluginConstant.PLUGIN_ID, username, this.getClass()), new Credentials(username, password==null?"":password));
PasswordSafe.getInstance().set(new CredentialAttributes(PluginConstant.PLUGIN_ID, username, this.getClass()), new Credentials(username, password == null ? "" : password));
}

public String getPassword(String username) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package com.shuzijun.leetcode.plugin.setting;

import com.intellij.openapi.components.*;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.util.xmlb.annotations.MapAnnotation;
import com.shuzijun.leetcode.plugin.model.LeetcodeEditor;
import com.shuzijun.leetcode.plugin.model.PluginConstant;
import com.shuzijun.leetcode.plugin.utils.URLUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
* @author shuzijun
*/
@State(name = "LeetcodeEditor" + PluginConstant.ACTION_SUFFIX, storages = {@Storage(value = PluginConstant.ACTION_PREFIX+"/editor.xml")})
public class ProjectConfig implements PersistentStateComponent<ProjectConfig.InnerState> {
@State(name = "LeetcodeEditor" + PluginConstant.ACTION_SUFFIX, storages = {@Storage(value = PluginConstant.ACTION_PREFIX + "/editor.xml")})
public class ProjectConfig implements PersistentStateComponent<ProjectConfig.InnerState> {

public Map<String, LeetcodeEditor> idProjectConfig = new HashMap<>();

Expand All @@ -37,24 +41,34 @@ public ProjectConfig.InnerState getState() {
public void loadState(@NotNull ProjectConfig.InnerState innerState) {
this.innerState = innerState;
idProjectConfig.clear();
this.innerState.projectConfig.forEach((s, leetcodeEditor) -> {
idProjectConfig.put(leetcodeEditor.getFrontendQuestionId(),leetcodeEditor);
});
Iterator<String> iter = this.innerState.projectConfig.keySet().iterator();
while (iter.hasNext()) {
String key = iter.next();
LeetcodeEditor leetcodeEditor = this.innerState.projectConfig.get(key);
if (StringUtils.isBlank(leetcodeEditor.getFrontendQuestionId())) {
iter.remove();
continue;
} else if (leetcodeEditor.getFrontendQuestionId().startsWith(URLUtils.leetcodecnOld)) {
leetcodeEditor.setHost(URLUtils.leetcodecn);
leetcodeEditor.setFrontendQuestionId(leetcodeEditor.getFrontendQuestionId().replace(URLUtils.leetcodecnOld, URLUtils.leetcodecn));
}
idProjectConfig.put(leetcodeEditor.getFrontendQuestionId(), leetcodeEditor);
}
}


public LeetcodeEditor getDefEditor(String frontendQuestionId) {
LeetcodeEditor leetcodeEditor = idProjectConfig.get(frontendQuestionId);
if (leetcodeEditor == null) {
leetcodeEditor = new LeetcodeEditor();
idProjectConfig.put(frontendQuestionId,leetcodeEditor);
idProjectConfig.put(frontendQuestionId, leetcodeEditor);
}
return leetcodeEditor;
}

public void addLeetcodeEditor(LeetcodeEditor leetcodeEditor) {
idProjectConfig.put(leetcodeEditor.getFrontendQuestionId(), leetcodeEditor);
if(StringUtils.isNotBlank(leetcodeEditor.getPath())) {
if (StringUtils.isNotBlank(leetcodeEditor.getPath())) {
innerState.projectConfig.put(leetcodeEditor.getPath(), leetcodeEditor);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ public void apply() {
}

public void process(Config config) {
config.setVersion(Constant.PLUGIN_CONFIG_VERSION_2);
if(config.getVersion() == null) {
config.setVersion(Constant.PLUGIN_CONFIG_VERSION_3);
}
config.setLoginName(userNameField.getText());
config.setFilePath(fileFolderBtn.getText());
config.setCodeType(codeComboBox.getSelectedItem().toString());
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/shuzijun/leetcode/plugin/utils/URLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
public class URLUtils {

public static final String leetcode = "leetcode.com";
public static final String leetcodecn = "leetcode-cn.com";
public static final String leetcodecn = "leetcode.cn";
public static final String leetcodecnOld = "leetcode-cn.com";

private static String leetcodeUrl = "https://";
private static String leetcodeLogin = "/accounts/login/";
Expand All @@ -35,6 +36,17 @@ public static String getLeetcodeHost() {
return host;
}

public static boolean equalsHost(String host) {
String thisHost = getLeetcodeHost();
if(thisHost.equals(host)){
return true;
}else if(thisHost.equals(leetcodecn) && leetcodecnOld.equals(host)){
return true;
}else {
return false;
}
}

public static String getLeetcodeUrl() {
return leetcodeUrl + getLeetcodeHost();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class HttpLogin {
public static boolean ajaxLogin(Config config, NavigatorTable navigatorTable, Project project) {

if (URLUtils.leetcode.equals(URLUtils.getLeetcodeHost())) {
if (!URLUtils.isCn()) {
return Boolean.FALSE;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

<description><![CDATA[
<div>
<p>Support for leetcode.com and leetcode-cn.com, can test and submit questions.
<p>Support for leetcode.com and leetcode.cn, can test and submit questions.
More tutorial please visit: <a href="https://github.com/shuzijun/leetcode-editor">here</a></p>
</div>
<div>
<h2>Introduction</h2>
<br>
<ul>
<li>Support for leetcode.com and leetcode-cn.com, can test and submit questions</li>
<li>Support for leetcode.com and leetcode.cn, can test and submit questions</li>
<li>More tutorial please visit: <a href="https://github.com/shuzijun/leetcode-editor">here</a></li>
</ul>
<ul>
<li>支持leetcode.com和leetcode-cn.com,可测试与提交问题</li>
<li>支持leetcode.com和leetcode.cn,可测试与提交问题</li>
<li>更多的插件使用教程: <a href="https://github.com/shuzijun/leetcode-editor">插件使用介绍</a></li>
</ul>
</div>
Expand Down Expand Up @@ -47,7 +47,7 @@
<h3>Configuration path: File -> settings->tools->leetcode plugin</h3>
<br>
<ul>
<li>URL options: leetcode.com and leetcode-cn.com</li>
<li>URL options: leetcode.com and leetcode.cn</li>
<li>Code Type: Java, Python, C++, Python3, C, C#, JavaScript, Ruby, Swift, Go, Scala, Kotlin, Rust, PHP</li>
<li> Login Name: Login Username</li>
<li> Password: Login password</li>
Expand Down