Support domain when clearing cookies
This commit is contained in:
parent
1f1795f111
commit
708d66b256
2 changed files with 29 additions and 6 deletions
|
|
@ -26,7 +26,6 @@ mod vault;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use cookie::CookieJar;
|
|
||||||
use cove_config::doc::Document;
|
use cove_config::doc::Document;
|
||||||
use cove_config::Config;
|
use cove_config::Config;
|
||||||
use directories::{BaseDirs, ProjectDirs};
|
use directories::{BaseDirs, ProjectDirs};
|
||||||
|
|
@ -47,7 +46,11 @@ enum Command {
|
||||||
/// Compact and clean up vault.
|
/// Compact and clean up vault.
|
||||||
Gc,
|
Gc,
|
||||||
/// Clear euphoria session cookies.
|
/// Clear euphoria session cookies.
|
||||||
ClearCookies,
|
ClearCookies {
|
||||||
|
/// Clear cookies for a specific domain only.
|
||||||
|
#[arg(long, short)]
|
||||||
|
domain: Option<String>,
|
||||||
|
},
|
||||||
/// Print config documentation as markdown.
|
/// Print config documentation as markdown.
|
||||||
HelpConfig,
|
HelpConfig,
|
||||||
}
|
}
|
||||||
|
|
@ -154,7 +157,7 @@ async fn main() -> anyhow::Result<()> {
|
||||||
Command::Run => run(logger, logger_rx, config, &dirs).await?,
|
Command::Run => run(logger, logger_rx, config, &dirs).await?,
|
||||||
Command::Export(args) => export(config, &dirs, args).await?,
|
Command::Export(args) => export(config, &dirs, args).await?,
|
||||||
Command::Gc => gc(config, &dirs).await?,
|
Command::Gc => gc(config, &dirs).await?,
|
||||||
Command::ClearCookies => clear_cookies(config, &dirs).await?,
|
Command::ClearCookies { domain } => clear_cookies(config, &dirs, domain).await?,
|
||||||
Command::HelpConfig => help_config(),
|
Command::HelpConfig => help_config(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -214,11 +217,15 @@ async fn gc(config: &'static Config, dirs: &ProjectDirs) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn clear_cookies(config: &'static Config, dirs: &ProjectDirs) -> anyhow::Result<()> {
|
async fn clear_cookies(
|
||||||
|
config: &'static Config,
|
||||||
|
dirs: &ProjectDirs,
|
||||||
|
domain: Option<String>,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
let vault = open_vault(config, dirs)?;
|
let vault = open_vault(config, dirs)?;
|
||||||
|
|
||||||
eprintln!("Clearing cookies");
|
eprintln!("Clearing cookies");
|
||||||
vault.euph().set_cookies(CookieJar::new()).await?;
|
vault.euph().clear_cookies(domain).await?;
|
||||||
|
|
||||||
vault.close().await;
|
vault.close().await;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,7 @@ macro_rules! euph_vault_actions {
|
||||||
euph_vault_actions! {
|
euph_vault_actions! {
|
||||||
GetCookies : cookies(domain: String) -> CookieJar;
|
GetCookies : cookies(domain: String) -> CookieJar;
|
||||||
SetCookies : set_cookies(domain: String, cookies: CookieJar) -> ();
|
SetCookies : set_cookies(domain: String, cookies: CookieJar) -> ();
|
||||||
|
ClearCookies : clear_cookies(domain: Option<String>) -> ();
|
||||||
GetRooms : rooms() -> Vec<RoomIdentifier>;
|
GetRooms : rooms() -> Vec<RoomIdentifier>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,7 +167,7 @@ impl Action for SetCookies {
|
||||||
",
|
",
|
||||||
)?;
|
)?;
|
||||||
for cookie in self.cookies.iter() {
|
for cookie in self.cookies.iter() {
|
||||||
insert_cookie.execute([self.domain, format!("{cookie}")])?;
|
insert_cookie.execute(params![self.domain, format!("{cookie}")])?;
|
||||||
}
|
}
|
||||||
drop(insert_cookie);
|
drop(insert_cookie);
|
||||||
|
|
||||||
|
|
@ -175,6 +176,21 @@ impl Action for SetCookies {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Action for ClearCookies {
|
||||||
|
type Output = ();
|
||||||
|
type Error = rusqlite::Error;
|
||||||
|
|
||||||
|
fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
|
||||||
|
if let Some(domain) = self.domain {
|
||||||
|
conn.execute("DELETE FROM euph_cookies WHERE domain = ?", [domain])?;
|
||||||
|
} else {
|
||||||
|
conn.execute_batch("DELETE FROM euph_cookies")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Action for GetRooms {
|
impl Action for GetRooms {
|
||||||
type Output = Vec<RoomIdentifier>;
|
type Output = Vec<RoomIdentifier>;
|
||||||
type Error = rusqlite::Error;
|
type Error = rusqlite::Error;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue