初步集成消息通道,支持Telegram + Lark机器人
This commit is contained in:
@@ -5,6 +5,10 @@ fn token_key(account_id: &str) -> String {
|
||||
format!("github-token:{}", account_id)
|
||||
}
|
||||
|
||||
fn channel_token_key(channel_id: i32) -> String {
|
||||
format!("chat-channel:{}", channel_id)
|
||||
}
|
||||
|
||||
// ── Tauri mode: OS keyring ──
|
||||
|
||||
#[cfg(feature = "tauri-runtime")]
|
||||
@@ -87,3 +91,51 @@ pub fn delete_token(account_id: &str) -> Result<(), String> {
|
||||
tokens.remove(&token_key(account_id));
|
||||
write_tokens(&tokens)
|
||||
}
|
||||
|
||||
// ── Chat channel token helpers ──
|
||||
// Reuse the same storage mechanism (keyring or file) with a different key prefix.
|
||||
|
||||
#[cfg(feature = "tauri-runtime")]
|
||||
pub fn set_channel_token(channel_id: i32, token: &str) -> Result<(), String> {
|
||||
let entry = keyring::Entry::new(SERVICE_NAME, &channel_token_key(channel_id))
|
||||
.map_err(|e| format!("keyring init error: {e}"))?;
|
||||
entry
|
||||
.set_password(token)
|
||||
.map_err(|e| format!("keyring set error: {e}"))
|
||||
}
|
||||
|
||||
#[cfg(feature = "tauri-runtime")]
|
||||
pub fn get_channel_token(channel_id: i32) -> Option<String> {
|
||||
let entry = keyring::Entry::new(SERVICE_NAME, &channel_token_key(channel_id)).ok()?;
|
||||
entry.get_password().ok()
|
||||
}
|
||||
|
||||
#[cfg(feature = "tauri-runtime")]
|
||||
pub fn delete_channel_token(channel_id: i32) -> Result<(), String> {
|
||||
let entry = keyring::Entry::new(SERVICE_NAME, &channel_token_key(channel_id))
|
||||
.map_err(|e| format!("keyring init error: {e}"))?;
|
||||
match entry.delete_credential() {
|
||||
Ok(()) => Ok(()),
|
||||
Err(keyring::Error::NoEntry) => Ok(()),
|
||||
Err(e) => Err(format!("keyring delete error: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "tauri-runtime"))]
|
||||
pub fn set_channel_token(channel_id: i32, token: &str) -> Result<(), String> {
|
||||
let mut tokens = read_tokens();
|
||||
tokens.insert(channel_token_key(channel_id), token.to_string());
|
||||
write_tokens(&tokens)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "tauri-runtime"))]
|
||||
pub fn get_channel_token(channel_id: i32) -> Option<String> {
|
||||
read_tokens().get(&channel_token_key(channel_id)).cloned()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "tauri-runtime"))]
|
||||
pub fn delete_channel_token(channel_id: i32) -> Result<(), String> {
|
||||
let mut tokens = read_tokens();
|
||||
tokens.remove(&channel_token_key(channel_id));
|
||||
write_tokens(&tokens)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user