mirror of
https://github.com/OMGeeky/google_youtube.git
synced 2025-12-26 16:17:24 +01:00
create the auth token folder if it does not exist
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "google_youtube"
|
name = "google_youtube"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|||||||
24
src/auth.rs
24
src/auth.rs
@@ -123,7 +123,7 @@ pub(crate) async fn get_authenticator(
|
|||||||
trace!("reading application secret");
|
trace!("reading application secret");
|
||||||
let app_secret = oauth2::read_application_secret(path_to_application_secret).await?;
|
let app_secret = oauth2::read_application_secret(path_to_application_secret).await?;
|
||||||
trace!("read application secret");
|
trace!("read application secret");
|
||||||
let method = oauth2::InstalledFlowReturnMethod::Interactive;
|
|
||||||
let config = load_config();
|
let config = load_config();
|
||||||
let mut vars: HashMap<String, String> = HashMap::new();
|
let mut vars: HashMap<String, String> = HashMap::new();
|
||||||
let user = match user {
|
let user = match user {
|
||||||
@@ -131,16 +131,30 @@ pub(crate) async fn get_authenticator(
|
|||||||
None => "unknown".to_string(),
|
None => "unknown".to_string(),
|
||||||
};
|
};
|
||||||
vars.insert("user".to_string(), user.clone());
|
vars.insert("user".to_string(), user.clone());
|
||||||
let persistent_path: String =
|
let persistent_path = strfmt(&config.path_authentications, &vars)
|
||||||
strfmt(&config.path_authentications, &vars).expect("Error formatting path");
|
.map_err(|e| anyhow!("Error formatting path: {}", e))?;
|
||||||
|
let persistent_path: &Path = Path::new(&persistent_path);
|
||||||
debug!(
|
debug!(
|
||||||
"Persistent auth path for user:{} => {}",
|
"Persistent auth path for user:{} => {}",
|
||||||
user, persistent_path
|
user,
|
||||||
|
persistent_path.display()
|
||||||
);
|
);
|
||||||
|
let persistent_path_parent = persistent_path
|
||||||
|
.parent()
|
||||||
|
.ok_or(anyhow!("could not get parent of path"))?;
|
||||||
|
if !persistent_path.exists() || persistent_path.is_dir() {
|
||||||
|
warn!(
|
||||||
|
"persistent path does not exist or is a dir: {}",
|
||||||
|
persistent_path.display()
|
||||||
|
);
|
||||||
|
let create_dir = std::fs::create_dir_all(persistent_path_parent);
|
||||||
|
warn!("result of create dir: {:?}", create_dir);
|
||||||
|
}
|
||||||
trace!("building authenticator");
|
trace!("building authenticator");
|
||||||
|
let method = oauth2::InstalledFlowReturnMethod::Interactive;
|
||||||
let auth = oauth2::InstalledFlowAuthenticator::builder(app_secret, method)
|
let auth = oauth2::InstalledFlowAuthenticator::builder(app_secret, method)
|
||||||
.flow_delegate(Box::new(CustomFlowDelegate { user }))
|
.flow_delegate(Box::new(CustomFlowDelegate { user }))
|
||||||
.persist_tokens_to_disk(persistent_path)
|
.persist_tokens_to_disk(persistent_path.to_path_buf())
|
||||||
.build()
|
.build()
|
||||||
.await
|
.await
|
||||||
//TODO: somehow get rid of this unwrap that is happening in the library
|
//TODO: somehow get rid of this unwrap that is happening in the library
|
||||||
|
|||||||
Reference in New Issue
Block a user