Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9017eda

Browse files
authored
Refine the result parsing logic (LeetCode-OpenSource#501)
1 parentc20a2d5 commit9017eda

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

‎package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,6 @@
683683
"markdown-it":"^8.4.2",
684684
"require-from-string":"^2.0.2",
685685
"unescape-js":"^1.1.1",
686-
"vsc-leetcode-cli":"2.6.20"
686+
"vsc-leetcode-cli":"2.6.22"
687687
}
688688
}

‎src/leetCodeManager.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import * as wsl from "./utils/wslUtils";
1414
classLeetCodeManagerextendsEventEmitter{
1515
privatecurrentUser:string|undefined;
1616
privateuserStatus:UserStatus;
17+
privatereadonlysuccessRegex:RegExp=/(?:.*)Successfully.*loginas(.*)/i;
18+
privatereadonlyfailRegex:RegExp=/.*\[ERROR\].*/i;
1719

1820
constructor(){
1921
super();
@@ -42,11 +44,6 @@ class LeetCodeManager extends EventEmitter {
4244
detail:"Use LeetCode account to login",
4345
value:"LeetCode",
4446
},
45-
{
46-
label:"LeetCode Cookie",
47-
detail:"Use LeetCode cookie copied from browser to login",
48-
value:"Cookie",
49-
},
5047
{
5148
label:"Third-Party: GitHub",
5249
detail:"Use GitHub account to login",
@@ -57,6 +54,11 @@ class LeetCodeManager extends EventEmitter {
5754
detail:"Use LinkedIn account to login",
5855
value:"LinkedIn",
5956
},
57+
{
58+
label:"LeetCode Cookie",
59+
detail:"Use LeetCode cookie copied from browser to login",
60+
value:"Cookie",
61+
},
6062
);
6163
constchoice:IQuickItemEx<string>|undefined=awaitvscode.window.showQuickPick(picks);
6264
if(!choice){
@@ -87,20 +89,22 @@ class LeetCodeManager extends EventEmitter {
8789
if(data.includes("twoFactorCode")){
8890
consttwoFactor:string|undefined=awaitvscode.window.showInputBox({
8991
prompt:"Enter two-factor code.",
92+
ignoreFocusOut:true,
9093
validateInput:(s:string):string|undefined=>s&&s.trim() ?undefined :"The input must not be empty",
9194
});
9295
if(!twoFactor){
9396
childProc.kill();
9497
returnresolve(undefined);
9598
}
9699
childProc.stdin.write(`${twoFactor}\n`);
100+
}
101+
constsuccessMatch:RegExpMatchArray|null=data.match(this.successRegex);
102+
if(successMatch&&successMatch[1]){
97103
childProc.stdin.end();
98-
}else{
99-
constmatch:RegExpMatchArray|null=data.match(/(?:.*)Successfully.*loginas(.*)/i);
100-
if(match&&match[1]){
101-
childProc.stdin.end();
102-
returnresolve(match[1]);
103-
}
104+
returnresolve(successMatch[1]);
105+
}elseif(data.match(this.failRegex)){
106+
childProc.stdin.end();
107+
returnreject(newError("Faile to login"));
104108
}
105109
});
106110

@@ -109,6 +113,7 @@ class LeetCodeManager extends EventEmitter {
109113
childProc.on("error",reject);
110114
constname:string|undefined=awaitvscode.window.showInputBox({
111115
prompt:"Enter username or E-mail.",
116+
ignoreFocusOut:true,
112117
validateInput:(s:string):string|undefined=>s&&s.trim() ?undefined :"The input must not be empty",
113118
});
114119
if(!name){
@@ -119,18 +124,14 @@ class LeetCodeManager extends EventEmitter {
119124
constpwd:string|undefined=awaitvscode.window.showInputBox({
120125
prompt:isByCookie ?"Enter cookie" :"Enter password.",
121126
password:true,
127+
ignoreFocusOut:true,
122128
validateInput:(s:string):string|undefined=>s ?undefined :isByCookie ?"Cookie must not be empty" :"Password must not be empty",
123129
});
124130
if(!pwd){
125131
childProc.kill();
126132
returnresolve(undefined);
127133
}
128134
childProc.stdin.write(`${pwd}\n`);
129-
childProc.on("close",(code:number)=>{
130-
if(code!==0){
131-
reject(newError("Failed to login."));
132-
}
133-
});
134135
});
135136
if(userName){
136137
vscode.window.showInformationMessage(`Successfully${inMessage}.`);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp