mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Actually remove session file if login remove flag is set
This commit is contained in:
parent
d8d1f8a443
commit
3c648f4192
3 changed files with 16 additions and 12 deletions
|
|
@ -15,6 +15,7 @@ mod download;
|
||||||
mod login;
|
mod login;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
use crate::login::session_file_path;
|
||||||
pub use archive::Archive;
|
pub use archive::Archive;
|
||||||
use crunchyroll_rs::error::CrunchyrollError;
|
use crunchyroll_rs::error::CrunchyrollError;
|
||||||
pub use download::Download;
|
pub use download::Download;
|
||||||
|
|
@ -142,7 +143,16 @@ pub async fn cli_entrypoint() {
|
||||||
match &mut cli.command {
|
match &mut cli.command {
|
||||||
Command::Archive(archive) => pre_check_executor(archive).await,
|
Command::Archive(archive) => pre_check_executor(archive).await,
|
||||||
Command::Download(download) => pre_check_executor(download).await,
|
Command::Download(download) => pre_check_executor(download).await,
|
||||||
Command::Login(login) => pre_check_executor(login).await,
|
Command::Login(login) => {
|
||||||
|
if login.remove {
|
||||||
|
if let Some(session_file) = session_file_path() {
|
||||||
|
let _ = fs::remove_file(session_file);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
pre_check_executor(login).await
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let ctx = match create_ctx(&cli).await {
|
let ctx = match create_ctx(&cli).await {
|
||||||
|
|
@ -187,13 +197,7 @@ pub async fn cli_entrypoint() {
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Command::Archive(archive) => execute_executor(archive, ctx).await,
|
Command::Archive(archive) => execute_executor(archive, ctx).await,
|
||||||
Command::Download(download) => execute_executor(download, ctx).await,
|
Command::Download(download) => execute_executor(download, ctx).await,
|
||||||
Command::Login(login) => {
|
Command::Login(login) => execute_executor(login, ctx).await,
|
||||||
if login.remove {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
execute_executor(login, ctx).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -285,7 +289,7 @@ async fn crunchyroll_session(cli: &Cli) -> Result<Crunchyroll> {
|
||||||
|
|
||||||
let progress_handler = progress!("Logging in");
|
let progress_handler = progress!("Logging in");
|
||||||
if login_methods_count == 0 {
|
if login_methods_count == 0 {
|
||||||
if let Some(login_file_path) = login::login_file_path() {
|
if let Some(login_file_path) = login::session_file_path() {
|
||||||
if login_file_path.exists() {
|
if login_file_path.exists() {
|
||||||
let session = fs::read_to_string(login_file_path)?;
|
let session = fs::read_to_string(login_file_path)?;
|
||||||
if let Some((token_type, token)) = session.split_once(':') {
|
if let Some((token_type, token)) = session.split_once(':') {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ pub struct Login {
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Execute for Login {
|
impl Execute for Login {
|
||||||
async fn execute(self, ctx: Context) -> Result<()> {
|
async fn execute(self, ctx: Context) -> Result<()> {
|
||||||
if let Some(login_file_path) = login_file_path() {
|
if let Some(login_file_path) = session_file_path() {
|
||||||
fs::create_dir_all(login_file_path.parent().unwrap())?;
|
fs::create_dir_all(login_file_path.parent().unwrap())?;
|
||||||
|
|
||||||
match ctx.crunchy.session_token().await {
|
match ctx.crunchy.session_token().await {
|
||||||
|
|
@ -36,6 +36,6 @@ impl Execute for Login {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn login_file_path() -> Option<PathBuf> {
|
pub fn session_file_path() -> Option<PathBuf> {
|
||||||
dirs::config_dir().map(|config_dir| config_dir.join("crunchy-cli").join("session"))
|
dirs::config_dir().map(|config_dir| config_dir.join("crunchy-cli").join("session"))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
mod command;
|
mod command;
|
||||||
|
|
||||||
pub use command::login_file_path;
|
pub use command::session_file_path;
|
||||||
pub use command::Login;
|
pub use command::Login;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue