Skip to content

Commit 3d496d5

Browse files
author
lhy
committed
refactor: 将backendUrl作为参数传递给getUserKey方法
重构了getUserKey方法,将backendUrl作为参数传递,而不是从全局配置中获取。这样可以提高代码的灵活性和可测试性,同时确保在不同环境下正确使用指定的后端URL。
1 parent 79d20bd commit 3d496d5

4 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/PawSQLSidebarProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,11 @@ export class PawSQLTreeProvider
970970
password: string;
971971
backendUrl: string;
972972
}) {
973-
const result = await ApiService.getUserKey(config.email, config.password);
973+
const result = await ApiService.getUserKey(
974+
config.backendUrl,
975+
config.email,
976+
config.password
977+
);
974978
if (!result) {
975979
await vscode.workspace
976980
.getConfiguration("pawsql")

src/apiService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ export const validateUserKey = async (userKey: string): Promise<boolean> => {
311311
};
312312

313313
export const getUserKey = async (
314+
backendUrl: string,
314315
email: string,
315316
password: string
316317
): Promise<{ apikey: string; frontendUrl: string } | null> => {
317-
const { DOMAIN } = getUrls();
318-
const url = `${DOMAIN.Backend}/api/v1/getUserKey`;
318+
const url = `${backendUrl}/api/v1/getUserKey`;
319319

320320
try {
321321
// 发送请求以验证 userKey

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class PawSQLExtension {
7070
setTimeout(() => reject(new Error("请求超时")), 5000);
7171
});
7272

73-
const userKeyPromise = ApiService.getUserKey(email, password);
73+
const userKeyPromise = ApiService.getUserKey(backendUrl, email, password);
7474

7575
const result = await Promise.race([userKeyPromise, timeout]).catch(
7676
(error) => {

src/webviewProvider.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,19 @@ export class WebviewProvider {
126126
}
127127
) {
128128
try {
129-
// These operations need to be awaited as they involve async operations
130-
await Promise.all([
131-
this.treeProvider.updateApikey(config),
132-
this.passwordManager.storePassword(config.password),
133-
vscode.workspace
134-
.getConfiguration("pawsql")
135-
.update("email", config.email, true),
136-
vscode.workspace
137-
.getConfiguration("pawsql")
138-
.update("backendUrl", config.backendUrl, true),
139-
]);
129+
// 按顺序执行配置更新操作
130+
await vscode.workspace
131+
.getConfiguration("pawsql")
132+
.update("email", config.email, true);
133+
await vscode.workspace
134+
.getConfiguration("pawsql")
135+
.update("backendUrl", config.backendUrl, true);
136+
await this.treeProvider.updateApikey(config);
137+
await this.passwordManager.storePassword(config.password);
140138

141139
const result = await this.treeProvider.validatePawSQLConfig();
140+
141+
// 发送验证结果
142142
panel.webview.postMessage({
143143
command: "validateConfig",
144144
validateResult: result,

0 commit comments

Comments
 (0)