Skip to content

Commit d67276a

Browse files
committed
去除工作区相关,因为无法获取到用户工作区
1 parent e920915 commit d67276a

14 files changed

Lines changed: 251 additions & 501 deletions

File tree

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## 更新日志
2+
- v1.4.1
3+
1. 去除工作区相关,因为无法获取到用户工作区
24
- v1.4.0
35
1. 支持自己选择codex路径
46
2. 优化opencode 授权

src-tauri/src/auth.rs

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ pub(crate) fn read_current_auth_status() -> Result<CurrentAuthStatus, String> {
4545
return Ok(CurrentAuthStatus {
4646
available: false,
4747
account_id: None,
48-
workspace_name: None,
4948
email: None,
5049
plan_type: None,
5150
auth_mode: None,
@@ -80,9 +79,6 @@ pub(crate) fn read_current_auth_status() -> Result<CurrentAuthStatus, String> {
8079
let extracted = extract_auth(&value).ok();
8180
let principal_id = extracted.as_ref().map(|auth| auth.principal_id.clone());
8281
let account_id = extracted.as_ref().map(|auth| auth.account_id.clone());
83-
let workspace_name = extracted
84-
.as_ref()
85-
.and_then(|auth| auth.workspace_name.clone());
8682
let email = extracted.as_ref().and_then(|auth| auth.email.clone());
8783
let plan_type = extracted.as_ref().and_then(|auth| auth.plan_type.clone());
8884

@@ -98,7 +94,6 @@ pub(crate) fn read_current_auth_status() -> Result<CurrentAuthStatus, String> {
9894
Ok(CurrentAuthStatus {
9995
available: true,
10096
account_id,
101-
workspace_name,
10297
email,
10398
plan_type,
10499
auth_mode,
@@ -226,7 +221,6 @@ pub(crate) fn extract_auth(auth_json: &Value) -> Result<ExtractedAuth, String> {
226221
.get("account_id")
227222
.and_then(Value::as_str)
228223
.map(ToString::to_string);
229-
let mut organizations: Vec<Value> = Vec::new();
230224
let mut email = None;
231225
let mut plan_type = None;
232226
let mut principal_id = None;
@@ -240,11 +234,6 @@ pub(crate) fn extract_auth(auth_json: &Value) -> Result<ExtractedAuth, String> {
240234
let auth_claim = claims
241235
.get("https://api.openai.com/auth")
242236
.and_then(Value::as_object);
243-
organizations = auth_claim
244-
.and_then(|value| value.get("organizations"))
245-
.and_then(Value::as_array)
246-
.cloned()
247-
.unwrap_or_default();
248237
if account_id.is_none() {
249238
account_id = auth_claim
250239
.and_then(|value| value.get("chatgpt_account_id"))
@@ -279,76 +268,16 @@ pub(crate) fn extract_auth(auth_json: &Value) -> Result<ExtractedAuth, String> {
279268
let account_id =
280269
account_id.ok_or_else(|| "无法从 auth.json 识别 chatgpt_account_id".to_string())?;
281270
let principal_id = principal_id.unwrap_or_else(|| account_id.clone());
282-
let workspace_name = resolve_workspace_name_from_organizations(&organizations, &account_id);
283271

284272
Ok(ExtractedAuth {
285273
principal_id,
286274
account_id,
287-
workspace_name,
288275
access_token,
289276
email,
290277
plan_type,
291278
})
292279
}
293280

294-
fn resolve_workspace_name_from_organizations(
295-
organizations: &[Value],
296-
account_id: &str,
297-
) -> Option<String> {
298-
#[derive(Clone)]
299-
struct OrganizationCandidate {
300-
id: Option<String>,
301-
title: String,
302-
is_default: bool,
303-
}
304-
305-
let candidates: Vec<OrganizationCandidate> = organizations
306-
.iter()
307-
.filter_map(|item| {
308-
let object = item.as_object()?;
309-
let title = object
310-
.get("title")
311-
.and_then(Value::as_str)
312-
.map(str::trim)
313-
.filter(|value| !value.is_empty())?
314-
.to_string();
315-
316-
Some(OrganizationCandidate {
317-
id: object
318-
.get("id")
319-
.and_then(Value::as_str)
320-
.map(ToString::to_string),
321-
title,
322-
is_default: object
323-
.get("is_default")
324-
.and_then(Value::as_bool)
325-
.unwrap_or(false),
326-
})
327-
})
328-
.collect();
329-
330-
if let Some(exact) = candidates
331-
.iter()
332-
.find(|candidate| candidate.id.as_deref() == Some(account_id))
333-
{
334-
return Some(exact.title.clone());
335-
}
336-
337-
if candidates.len() == 1 {
338-
return Some(candidates[0].title.clone());
339-
}
340-
341-
let default_candidates: Vec<&OrganizationCandidate> = candidates
342-
.iter()
343-
.filter(|candidate| candidate.is_default)
344-
.collect();
345-
if default_candidates.len() == 1 {
346-
return Some(default_candidates[0].title.clone());
347-
}
348-
349-
None
350-
}
351-
352281
pub(crate) fn current_auth_account_key() -> Option<String> {
353282
read_current_codex_auth()
354283
.ok()
@@ -589,61 +518,3 @@ fn extract_client_id_from_claims(claims: &Value) -> Option<String> {
589518
_ => None,
590519
}
591520
}
592-
593-
#[cfg(test)]
594-
mod tests {
595-
use super::resolve_workspace_name_from_organizations;
596-
use serde_json::json;
597-
use serde_json::Value;
598-
599-
fn organizations(items: Value) -> Vec<Value> {
600-
items.as_array().cloned().unwrap_or_default()
601-
}
602-
603-
#[test]
604-
fn workspace_name_prefers_exact_id_match() {
605-
let organizations = organizations(json!([
606-
{ "id": "org-1", "title": "Default Workspace", "is_default": true },
607-
{ "id": "acct-2", "title": "Target Workspace", "is_default": false }
608-
]));
609-
610-
let resolved = resolve_workspace_name_from_organizations(&organizations, "acct-2");
611-
612-
assert_eq!(resolved.as_deref(), Some("Target Workspace"));
613-
}
614-
615-
#[test]
616-
fn workspace_name_uses_single_organization_title() {
617-
let organizations = organizations(
618-
json!([{ "id": "org-1", "title": "Only Workspace", "is_default": false }]),
619-
);
620-
621-
let resolved = resolve_workspace_name_from_organizations(&organizations, "acct-unknown");
622-
623-
assert_eq!(resolved.as_deref(), Some("Only Workspace"));
624-
}
625-
626-
#[test]
627-
fn workspace_name_uses_unique_default_as_fallback() {
628-
let organizations = organizations(json!([
629-
{ "id": "org-1", "title": "Default Workspace", "is_default": true },
630-
{ "id": "org-2", "title": "Secondary Workspace", "is_default": false }
631-
]));
632-
633-
let resolved = resolve_workspace_name_from_organizations(&organizations, "acct-unknown");
634-
635-
assert_eq!(resolved.as_deref(), Some("Default Workspace"));
636-
}
637-
638-
#[test]
639-
fn workspace_name_returns_none_when_ambiguous() {
640-
let organizations = organizations(json!([
641-
{ "id": "org-1", "title": "Workspace A", "is_default": false },
642-
{ "id": "org-2", "title": "Workspace B", "is_default": false }
643-
]));
644-
645-
let resolved = resolve_workspace_name_from_organizations(&organizations, "acct-unknown");
646-
647-
assert_eq!(resolved, None);
648-
}
649-
}

src-tauri/src/models.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ pub(crate) struct AccountSummary {
6161
pub(crate) email: Option<String>,
6262
pub(crate) account_key: String,
6363
pub(crate) account_id: String,
64-
pub(crate) workspace_name: Option<String>,
6564
pub(crate) plan_type: Option<String>,
6665
pub(crate) added_at: i64,
6766
pub(crate) updated_at: i64,
@@ -115,7 +114,6 @@ pub(crate) struct SwitchAccountResult {
115114
pub(crate) struct CurrentAuthStatus {
116115
pub(crate) available: bool,
117116
pub(crate) account_id: Option<String>,
118-
pub(crate) workspace_name: Option<String>,
119117
pub(crate) email: Option<String>,
120118
pub(crate) plan_type: Option<String>,
121119
pub(crate) auth_mode: Option<String>,
@@ -128,7 +126,6 @@ pub(crate) struct CurrentAuthStatus {
128126
pub(crate) struct ExtractedAuth {
129127
pub(crate) principal_id: String,
130128
pub(crate) account_id: String,
131-
pub(crate) workspace_name: Option<String>,
132129
pub(crate) access_token: String,
133130
pub(crate) email: Option<String>,
134131
pub(crate) plan_type: Option<String>,
@@ -392,12 +389,6 @@ impl StoredAccount {
392389
})
393390
}
394391

395-
pub(crate) fn workspace_name(&self) -> Option<String> {
396-
extract_auth(&self.auth_json)
397-
.ok()
398-
.and_then(|auth| auth.workspace_name)
399-
}
400-
401392
pub(crate) fn variant_key(&self) -> String {
402393
account_variant_key(
403394
&self.principal_key(),
@@ -426,7 +417,6 @@ impl StoredAccount {
426417
email: self.email.clone(),
427418
account_key,
428419
account_id: self.account_id.clone(),
429-
workspace_name: self.workspace_name(),
430420
plan_type: self.plan_type.clone(),
431421
added_at: self.added_at,
432422
updated_at: self.updated_at,

0 commit comments

Comments
 (0)