mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Revert "Use config file to store sessions"
This reverts commit 850aa7a9
This commit is contained in:
parent
8490263e84
commit
dd2033d323
8 changed files with 48 additions and 179 deletions
|
|
@ -1,59 +0,0 @@
|
|||
use anyhow::{bail, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[serde(tag = "method")]
|
||||
pub enum Auth {
|
||||
RefreshToken { token: String },
|
||||
EtpRt { token: String },
|
||||
Anonymous,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize, Serialize)]
|
||||
pub struct Config {
|
||||
pub auth: Option<Auth>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> Result<Option<Self>> {
|
||||
let path = Config::assert_config_file_path(true)?;
|
||||
|
||||
if let Some(p) = path {
|
||||
if p.exists() {
|
||||
let content = fs::read_to_string(p)?;
|
||||
return Ok(Some(toml::from_str(&content)?));
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub fn write(&self) -> Result<()> {
|
||||
let path = Config::assert_config_file_path(false)?.unwrap();
|
||||
Ok(fs::write(path, toml::to_string(self)?)?)
|
||||
}
|
||||
|
||||
pub fn config_file_path() -> Option<PathBuf> {
|
||||
dirs::config_dir().map(|config_dir| config_dir.join("crunchy-cli.conf"))
|
||||
}
|
||||
|
||||
fn assert_config_file_path(ignore_non_existing_config_dir: bool) -> Result<Option<PathBuf>> {
|
||||
let Some(path) = Config::config_file_path() else {
|
||||
if ignore_non_existing_config_dir {
|
||||
return Ok(None)
|
||||
}
|
||||
bail!("Cannot find config directory")
|
||||
};
|
||||
|
||||
if path.exists() && path.is_dir() {
|
||||
bail!(
|
||||
"Config path ({}) is a directory (must be a normal file)",
|
||||
path.to_string_lossy()
|
||||
)
|
||||
}
|
||||
|
||||
Ok(Some(path))
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
use crate::utils::config::Config;
|
||||
use crunchyroll_rs::Crunchyroll;
|
||||
|
||||
pub struct Context {
|
||||
pub crunchy: Crunchyroll,
|
||||
pub config: Config,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
pub mod clap;
|
||||
pub mod config;
|
||||
pub mod context;
|
||||
pub mod download;
|
||||
pub mod ffmpeg;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue