feat: 增强API请求和邀请码验证的日志记录
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* 邀请码验证服务
|
||||
*/
|
||||
import * as vscode from 'vscode';
|
||||
import { verifyInvitationCode, checkInvitationStatus } from './apiClient';
|
||||
import * as vscode from "vscode";
|
||||
import { verifyInvitationCode, checkInvitationStatus } from "./apiClient";
|
||||
|
||||
/**
|
||||
* 邀请码验证服务类
|
||||
@ -13,34 +13,51 @@ export class InvitationService {
|
||||
*/
|
||||
static async isVerified(context: vscode.ExtensionContext): Promise<boolean> {
|
||||
// 【临时】使用本地验证,不调用后端
|
||||
const localVerified = context.globalState.get<boolean>('invitationCodeVerified');
|
||||
const localVerified = context.globalState.get<boolean>(
|
||||
"invitationCodeVerified",
|
||||
);
|
||||
return localVerified || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证邀请码
|
||||
*/
|
||||
static async verifyCode(code: string): Promise<{ success: boolean; message: string }> {
|
||||
static async verifyCode(
|
||||
code: string,
|
||||
): Promise<{ success: boolean; message: string }> {
|
||||
try {
|
||||
console.log('[InvitationService] 验证邀请码:', code);
|
||||
// console.log('[InvitationService] ========== 开始验证邀请码 ==========');
|
||||
// console.log('[InvitationService] 邀请码:', code);
|
||||
// console.log('[InvitationService] 邀请码长度:', code.length);
|
||||
|
||||
const response = await verifyInvitationCode(code);
|
||||
|
||||
// console.log('[InvitationService] 收到响应:', JSON.stringify(response, null, 2));
|
||||
// console.log('[InvitationService] 响应代码:', response.code);
|
||||
// console.log('[InvitationService] 响应消息:', response.msg);
|
||||
// console.log('[InvitationService] 验证结果:', response.data?.verified);
|
||||
|
||||
if (response.code === 200 && response.data?.verified) {
|
||||
console.log("[InvitationService] ✓ 验证成功");
|
||||
return {
|
||||
success: true,
|
||||
message: response.msg || '验证成功'
|
||||
message: response.msg || "验证成功",
|
||||
};
|
||||
} else {
|
||||
console.log("[InvitationService] ✗ 验证失败");
|
||||
return {
|
||||
success: false,
|
||||
message: response.msg || '验证失败'
|
||||
message: response.msg || "验证失败",
|
||||
};
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('[InvitationService] 验证邀请码失败:', error);
|
||||
// console.error('[InvitationService] ========== 验证邀请码异常 ==========');
|
||||
// console.error('[InvitationService] 错误类型:', error.constructor.name);
|
||||
// console.error('[InvitationService] 错误消息:', error.message);
|
||||
// console.error('[InvitationService] 错误堆栈:', error.stack);
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '网络连接失败,请检查网络后重试'
|
||||
message: error.message || "网络连接失败,请检查网络后重试",
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -51,20 +68,25 @@ export class InvitationService {
|
||||
static async saveVerificationStatus(
|
||||
context: vscode.ExtensionContext,
|
||||
code: string,
|
||||
verifiedTime?: string
|
||||
verifiedTime?: string,
|
||||
): Promise<void> {
|
||||
await context.globalState.update('invitationCodeVerified', true);
|
||||
await context.globalState.update('invitationCode', code);
|
||||
await context.globalState.update('invitationVerifiedTime', verifiedTime || new Date().toISOString());
|
||||
await context.globalState.update("invitationCodeVerified", true);
|
||||
await context.globalState.update("invitationCode", code);
|
||||
await context.globalState.update(
|
||||
"invitationVerifiedTime",
|
||||
verifiedTime || new Date().toISOString(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除验证状态(用于退出登录或更换邀请码)
|
||||
*/
|
||||
static async clearVerificationStatus(context: vscode.ExtensionContext): Promise<void> {
|
||||
await context.globalState.update('invitationCodeVerified', undefined);
|
||||
await context.globalState.update('invitationCode', undefined);
|
||||
await context.globalState.update('invitationVerifiedTime', undefined);
|
||||
static async clearVerificationStatus(
|
||||
context: vscode.ExtensionContext,
|
||||
): Promise<void> {
|
||||
await context.globalState.update("invitationCodeVerified", undefined);
|
||||
await context.globalState.update("invitationCode", undefined);
|
||||
await context.globalState.update("invitationVerifiedTime", undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,18 +94,18 @@ export class InvitationService {
|
||||
*/
|
||||
static async showInputDialog(): Promise<string | undefined> {
|
||||
const code = await vscode.window.showInputBox({
|
||||
prompt: '请输入邀请码以继续使用 IC Coder',
|
||||
placeHolder: '例如:INVITE2024ABC',
|
||||
prompt: "请输入邀请码以继续使用 IC Coder",
|
||||
placeHolder: "例如:INVITE2024ABC",
|
||||
ignoreFocusOut: true,
|
||||
validateInput: (value) => {
|
||||
if (!value || value.trim().length === 0) {
|
||||
return '邀请码不能为空';
|
||||
return "邀请码不能为空";
|
||||
}
|
||||
if (value.trim().length < 6) {
|
||||
return '邀请码格式不正确';
|
||||
return "邀请码格式不正确";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return code?.trim();
|
||||
|
||||
Reference in New Issue
Block a user