Refactor IPC and DTO structures; remove unused code and streamline message handling

- Removed unused structs and methods from `response.rs`, `usage.rs`, and `client.rs`.
- Simplified `Connection` handling in `conn.rs` to only support Unix sockets.
- Updated `IpcServer` to exclusively use Unix sockets and removed TCP handling.
- Cleaned up `editlog.rs` by removing loading and recent entry methods.
- Refactored `memory.rs` to eliminate unused functions related to lesson promotion and retrospective creation.
- Enhanced `search.rs` to support multiple search providers and improved error handling.
- Updated chat view logic to simplify message display and improve user experience.
- Removed deprecated modules and constants from various files to streamline the codebase.
This commit is contained in:
asepharyana
2026-07-11 23:45:13 +07:00
parent 93d1bbb7c1
commit fcef85a327
51 changed files with 1431 additions and 1246 deletions
-4
View File
@@ -13,10 +13,6 @@ impl LoopbackServer {
Ok(LoopbackServer { listener, port })
}
pub fn port(&self) -> u16 {
self.port
}
pub fn redirect_uri(&self) -> String {
format!("http://127.0.0.1:{}/callback", self.port)
}
-55
View File
@@ -10,15 +10,6 @@ pub struct OAuthToken {
}
impl OAuthToken {
pub fn is_expired(&self) -> bool {
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
now >= self.expires_at
}
pub fn remaining_secs(&self) -> i64 {
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
self.expires_at as i64 - now as i64
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -92,52 +83,6 @@ impl OAuthManager {
Ok(())
}
pub fn refresh_token(&mut self) -> Result<(), String> {
let refresh_token = self.token.as_ref()
.and_then(|t| t.refresh_token.clone())
.ok_or("no refresh token available")?;
let mut params = std::collections::HashMap::new();
params.insert("grant_type", "refresh_token");
params.insert("refresh_token", &refresh_token);
params.insert("client_id", &self.config.client_id);
let resp = self.client
.post(&self.config.token_url)
.form(&params)
.send()
.map_err(|e| format!("refresh failed: {}", e))?;
let status = resp.status();
let body: serde_json::Value = resp.json().map_err(|e| format!("parse failed: {}", e))?;
if !status.is_success() {
return Err(format!("refresh endpoint returned {}: {}", status, body));
}
let access_token = body["access_token"].as_str().ok_or("missing access_token")?.to_string();
let expires_in = body["expires_in"].as_u64().unwrap_or(3600);
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
self.token = Some(OAuthToken {
access_token,
refresh_token: body["refresh_token"].as_str().map(|s| s.to_string()).or(self.token.as_ref().and_then(|t| t.refresh_token.clone())),
expires_at: now + expires_in,
token_type: body["token_type"].as_str().unwrap_or("Bearer").to_string(),
});
Ok(())
}
pub fn ensure_token(&mut self) -> Result<(), String> {
if let Some(ref token) = self.token {
if token.remaining_secs() < 60 {
return self.refresh_token();
}
}
Ok(())
}
pub fn build_auth_url(&self, redirect_uri: &str, state: &str, code_challenge: &str) -> String {
let mut url = url::Url::parse(&self.config.auth_url).unwrap_or_else(|_| url::Url::parse("https://example.com").unwrap());
url.query_pairs_mut()