Skip to content

Commit 3a9a148

Browse files
committed
检验增加积分数量显示
1 parent a08d07d commit 3a9a148

4 files changed

Lines changed: 98 additions & 26 deletions

File tree

front/common.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,11 +1603,14 @@ async function verifyProjectId(filename) {
16031603
if (response.ok && data.success) {
16041604
// 成功时显示绿色成功消息和Project ID
16051605
const tierLine = data.subscription_tier ? `\nTier: ${data.subscription_tier}` : '';
1606-
const successMsg = `✅ 检验成功!\n文件: ${filename}\nProject ID: ${data.project_id}${tierLine}\n\n${data.message}`;
1606+
const creditLine = data.credit_amount !== undefined && data.credit_amount !== null
1607+
? `\n积分: ${data.credit_amount}`
1608+
: '';
1609+
const successMsg = `✅ 检验成功!\n文件: ${filename}\nProject ID: ${data.project_id}${tierLine}${creditLine}\n\n${data.message}`;
16071610
showStatus(successMsg.replace(/\n/g, '<br>'), 'success');
16081611

16091612
// 弹出成功提示
1610-
showMessageModal('检验成功', `✅ 检验成功!\n\n文件: ${filename}\nProject ID: ${data.project_id}${tierLine}\n\n${data.message}`, 'success');
1613+
showMessageModal('检验成功', `✅ 检验成功!\n\n文件: ${filename}\nProject ID: ${data.project_id}${tierLine}${creditLine}\n\n${data.message}`, 'success');
16111614

16121615
await AppState.creds.refresh();
16131616
} else {
@@ -1637,11 +1640,14 @@ async function verifyAntigravityProjectId(filename) {
16371640
if (response.ok && data.success) {
16381641
// 成功时显示绿色成功消息和Project ID
16391642
const tierLine = data.subscription_tier ? `\nTier: ${data.subscription_tier}` : '';
1640-
const successMsg = `✅ 检验成功!\n文件: ${filename}\nProject ID: ${data.project_id}${tierLine}\n\n${data.message}`;
1643+
const creditLine = data.credit_amount !== undefined && data.credit_amount !== null
1644+
? `\n积分: ${data.credit_amount}`
1645+
: '';
1646+
const successMsg = `✅ 检验成功!\n文件: ${filename}\nProject ID: ${data.project_id}${tierLine}${creditLine}\n\n${data.message}`;
16411647
showStatus(successMsg.replace(/\n/g, '<br>'), 'success');
16421648

16431649
// 弹出成功提示
1644-
showMessageModal('检验成功', `✅ Antigravity检验成功!\n\n文件: ${filename}\nProject ID: ${data.project_id}${tierLine}\n\n${data.message}`, 'success');
1650+
showMessageModal('检验成功', `✅ Antigravity检验成功!\n\n文件: ${filename}\nProject ID: ${data.project_id}${tierLine}${creditLine}\n\n${data.message}`, 'success');
16451651

16461652
await AppState.antigravityCreds.refresh();
16471653
} else {
@@ -2114,7 +2120,13 @@ async function batchVerifyProjectIds() {
21142120
const data = await response.json();
21152121

21162122
if (response.ok && data.success) {
2117-
return { success: true, filename, projectId: data.project_id, message: data.message };
2123+
return {
2124+
success: true,
2125+
filename,
2126+
projectId: data.project_id,
2127+
creditAmount: data.credit_amount,
2128+
message: data.message
2129+
};
21182130
} else {
21192131
return { success: false, filename, error: data.message || '失败' };
21202132
}
@@ -2134,7 +2146,10 @@ async function batchVerifyProjectIds() {
21342146
results.forEach(result => {
21352147
if (result.success) {
21362148
successCount++;
2137-
resultMessages.push(`✅ ${result.filename}: ${result.projectId}`);
2149+
const creditSuffix = result.creditAmount !== undefined && result.creditAmount !== null
2150+
? ` (积分: ${result.creditAmount})`
2151+
: '';
2152+
resultMessages.push(`✅ ${result.filename}: ${result.projectId}${creditSuffix}`);
21382153
} else {
21392154
failCount++;
21402155
resultMessages.push(`❌ ${result.filename}: ${result.error}`);
@@ -2183,7 +2198,13 @@ async function batchVerifyAntigravityProjectIds() {
21832198
const data = await response.json();
21842199

21852200
if (response.ok && data.success) {
2186-
return { success: true, filename, projectId: data.project_id, message: data.message };
2201+
return {
2202+
success: true,
2203+
filename,
2204+
projectId: data.project_id,
2205+
creditAmount: data.credit_amount,
2206+
message: data.message
2207+
};
21872208
} else {
21882209
return { success: false, filename, error: data.message || '失败' };
21892210
}
@@ -2203,7 +2224,10 @@ async function batchVerifyAntigravityProjectIds() {
22032224
results.forEach(result => {
22042225
if (result.success) {
22052226
successCount++;
2206-
resultMessages.push(`✅ ${result.filename}: ${result.projectId}`);
2227+
const creditSuffix = result.creditAmount !== undefined && result.creditAmount !== null
2228+
? ` (积分: ${result.creditAmount})`
2229+
: '';
2230+
resultMessages.push(`✅ ${result.filename}: ${result.projectId}${creditSuffix}`);
22072231
} else {
22082232
failCount++;
22092233
resultMessages.push(`❌ ${result.filename}: ${result.error}`);

src/google_oauth_api.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,9 @@ async def select_default_project(projects: List[Dict[str, Any]]) -> Optional[str
534534
async def fetch_project_id_and_tier(
535535
access_token: str,
536536
user_agent: str,
537-
api_base_url: str
538-
) -> Tuple[Optional[str], Optional[str]]:
537+
api_base_url: str,
538+
include_credits: bool = False,
539+
) -> Tuple[Optional[str], Optional[str]] | Tuple[Optional[str], Optional[str], Optional[int]]:
539540
"""
540541
从 API 获取 project_id 和订阅等级
541542
@@ -545,8 +546,10 @@ async def fetch_project_id_and_tier(
545546
api_base_url: API base URL (e.g., antigravity or code assist endpoint)
546547
547548
Returns:
548-
(project_id, subscription_tier) 元组
549+
默认返回 (project_id, subscription_tier)
550+
当 include_credits=True 时返回 (project_id, subscription_tier, credit_amount)
549551
subscription_tier 可能是 "FREE", "PRO", "ULTRA" 或 None
552+
credit_amount 为积分数量(整数)或 None
550553
"""
551554
headers = {
552555
'User-Agent': user_agent,
@@ -572,18 +575,32 @@ def _map_raw_tier(raw_tier: Optional[str]) -> Optional[str]:
572575
return tier_mapping.get(raw_tier.lower(), "pro")
573576

574577
subscription_tier = None
578+
credit_amount: Optional[int] = None
575579

576580
# 步骤 1: 尝试 loadCodeAssist
577581
try:
578-
project_id, raw_tier = await _try_load_code_assist(api_base_url, headers)
582+
project_id, raw_tier, raw_credit_amount = await _try_load_code_assist(api_base_url, headers)
579583
subscription_tier = _map_raw_tier(raw_tier)
580584

585+
if raw_credit_amount is not None:
586+
try:
587+
credit_amount = int(raw_credit_amount)
588+
log.info(
589+
f"[fetch_project_id_and_tier] Found credit_amount: {credit_amount}"
590+
)
591+
except (TypeError, ValueError):
592+
log.warning(
593+
f"[fetch_project_id_and_tier] Invalid credit_amount: {raw_credit_amount}"
594+
)
595+
581596
if raw_tier:
582597
log.info(
583598
f"[fetch_project_id_and_tier] Raw tier '{raw_tier}' mapped to '{subscription_tier}'"
584599
)
585600

586601
if project_id:
602+
if include_credits:
603+
return project_id, subscription_tier, credit_amount
587604
return project_id, subscription_tier
588605

589606
log.warning("[fetch_project_id_and_tier] loadCodeAssist did not return project_id, falling back to onboardUser")
@@ -596,28 +613,35 @@ def _map_raw_tier(raw_tier: Optional[str]) -> Optional[str]:
596613
try:
597614
project_id = await _try_onboard_user(api_base_url, headers)
598615
if project_id:
616+
if include_credits:
617+
return project_id, subscription_tier, credit_amount
599618
return project_id, subscription_tier
600619

601620
log.error("[fetch_project_id_and_tier] Failed to get project_id from both loadCodeAssist and onboardUser")
621+
if include_credits:
622+
return None, subscription_tier, credit_amount
602623
return None, subscription_tier
603624

604625
except Exception as e:
605626
log.error(f"[fetch_project_id_and_tier] onboardUser failed: {type(e).__name__}: {e}")
606627
import traceback
607628
log.debug(f"[fetch_project_id_and_tier] Traceback: {traceback.format_exc()}")
629+
if include_credits:
630+
return None, subscription_tier, credit_amount
608631
return None, subscription_tier
609632

610633

611634
async def _try_load_code_assist(
612635
api_base_url: str,
613636
headers: dict
614-
) -> Tuple[Optional[str], Optional[str]]:
637+
) -> Tuple[Optional[str], Optional[str], Optional[str]]:
615638
"""
616639
尝试通过 loadCodeAssist 获取 project_id 和订阅等级
617640
618641
Returns:
619-
(project_id, subscription_tier) 元组
642+
(project_id, subscription_tier, credit_amount) 元组
620643
subscription_tier 可能是 "FREE", "PRO", "ULTRA" 或 None
644+
credit_amount 为字符串格式积分或 None
621645
"""
622646
request_url = f"{api_base_url.rstrip('/')}/v1internal:loadCodeAssist"
623647
request_body = {
@@ -648,6 +672,7 @@ async def _try_load_code_assist(
648672
# 提取订阅等级 - 优先使用 paidTier(更准确反映实际权益)
649673
paid_tier = data.get("paidTier", {})
650674
current_tier = data.get("currentTier", {})
675+
available_credits = paid_tier.get("availableCredits", []) if isinstance(paid_tier, dict) else []
651676

652677
# paidTier.id 优先,然后是 currentTier.id
653678
subscription_tier = None
@@ -658,6 +683,15 @@ async def _try_load_code_assist(
658683
subscription_tier = current_tier.get("id")
659684
log.info(f"[loadCodeAssist] Found currentTier: {subscription_tier}")
660685

686+
# 提取积分数量(如果返回了 availableCredits)
687+
credit_amount = None
688+
if isinstance(available_credits, list) and available_credits:
689+
first_credit = available_credits[0]
690+
if isinstance(first_credit, dict):
691+
credit_amount = first_credit.get("creditAmount")
692+
if credit_amount is not None:
693+
log.info(f"[loadCodeAssist] Found creditAmount: {credit_amount}")
694+
661695
# 检查是否有 currentTier(表示用户已激活)
662696
if current_tier:
663697
log.info("[loadCodeAssist] User is already activated")
@@ -666,13 +700,13 @@ async def _try_load_code_assist(
666700
project_id = data.get("cloudaicompanionProject")
667701
if project_id:
668702
log.info(f"[loadCodeAssist] Successfully fetched project_id: {project_id}, tier: {subscription_tier}")
669-
return project_id, subscription_tier
703+
return project_id, subscription_tier, credit_amount
670704

671705
log.warning("[loadCodeAssist] No project_id in response")
672-
return None, subscription_tier
706+
return None, subscription_tier, credit_amount
673707
else:
674708
log.info("[loadCodeAssist] User not activated yet (no currentTier)")
675-
return None, None
709+
return None, None, credit_amount
676710
else:
677711
log.warning(f"[loadCodeAssist] Failed: HTTP {response.status_code}")
678712
log.warning(f"[loadCodeAssist] Response body: {response.text[:500]}")

src/panel/creds.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,12 +565,21 @@ async def verify_credential_project_common(filename: str, mode: str = "geminicli
565565
api_base_url = await get_code_assist_endpoint()
566566
user_agent = GEMINICLI_USER_AGENT
567567

568-
# 重新获取project id
569-
project_id, subscription_tier = await fetch_project_id_and_tier(
570-
access_token=credentials.access_token,
571-
user_agent=user_agent,
572-
api_base_url=api_base_url
573-
)
568+
# 重新获取project id(仅 antigravity 模式请求积分)
569+
if mode == "antigravity":
570+
project_id, subscription_tier, credit_amount = await fetch_project_id_and_tier(
571+
access_token=credentials.access_token,
572+
user_agent=user_agent,
573+
api_base_url=api_base_url,
574+
include_credits=True,
575+
)
576+
else:
577+
project_id, subscription_tier = await fetch_project_id_and_tier(
578+
access_token=credentials.access_token,
579+
user_agent=user_agent,
580+
api_base_url=api_base_url,
581+
)
582+
credit_amount = None
574583

575584
if project_id:
576585
credential_data["project_id"] = project_id
@@ -595,13 +604,18 @@ async def verify_credential_project_common(filename: str, mode: str = "geminicli
595604

596605
log.info(f"检验 {mode} 凭证成功: {filename} - Project ID: {project_id}, Tier: {subscription_tier} - 已解除禁用并清除错误码")
597606

598-
return JSONResponse(content={
607+
response_data = {
599608
"success": True,
600609
"filename": filename,
601610
"project_id": project_id,
602611
"subscription_tier": subscription_tier,
603612
"message": "检验成功!Project ID已更新,已解除禁用状态并清除错误码,403错误应该已恢复"
604-
})
613+
}
614+
615+
if mode == "antigravity" and credit_amount is not None:
616+
response_data["credit_amount"] = credit_amount
617+
618+
return JSONResponse(content=response_data)
605619
else:
606620
return JSONResponse(
607621
status_code=400,

src/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_geminicli_user_agent(model: str = "") -> str:
2424
# 静态常量
2525
GEMINICLI_USER_AGENT = get_geminicli_user_agent()
2626

27-
ANTIGRAVITY_USER_AGENT = "antigravity/2.15.8 (Windows; AMD64)"
27+
ANTIGRAVITY_USER_AGENT = "antigravity/1.22.2 windows/amd64"
2828

2929
# OAuth Configuration - 标准模式
3030
CLIENT_ID = "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com"

0 commit comments

Comments
 (0)