fix some errors

This commit is contained in:
OMGeeky
2024-04-20 16:18:51 +02:00
parent 0808d1d439
commit d43965a241
7 changed files with 21 additions and 9 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
/target
/.idea
/tmp

View File

@@ -190,7 +190,7 @@ impl UploaderClient {
fn get_client_for_video(&self, video: &VideosModel) -> Result<&youtube::YoutubeClient> {
let c = self
.youtube_client
.get(&video.id.to_string())
.get(&video.user_id.to_string())
.context("could not get youtube client for video")?;
Ok(c)
}

View File

@@ -168,10 +168,14 @@ impl YoutubeClient {
#[tracing::instrument]
pub async fn new(scopes: &Vec<Scope>, user: Option<UsersModel>) -> Result<Self> {
let hyper_client = Self::create_hyper_client();
let application_secret_path = &crate::CONF.google.youtube.client_secret_path;
let application_secret_path = PathBuf::from(
&shellexpand::full(&crate::CONF.google.youtube.client_secret_path)
.map_err(|e| UploaderError::ExpandPath(e.into()))?
.to_string(),
);
let auth = auth::get_auth(
application_secret_path,
&application_secret_path,
scopes,
user.as_ref().map(|x| &x.youtube_id),
)

View File

@@ -11,10 +11,11 @@ use tracing::instrument;
use yup_oauth2::authenticator::Authenticator;
#[instrument]
pub(super) async fn get_auth<USER: EasyString>(
application_secret_path: &String,
application_secret_path: &impl EasyPath,
scopes: &Vec<Scope>,
user: Option<USER>,
) -> Result<Authenticator<HttpsConnector<HttpConnector>>> {
let application_secret_path = application_secret_path.as_ref();
trace!(
"getting auth for user: {:?} with scopes: {:?} and secret_path: {:?}",
user,

View File

@@ -1,5 +1,8 @@
#[derive(Debug, thiserror::Error)]
pub enum UploaderError {
#[error("Path could not be expanded")]
ExpandPath(#[source] anyhow::Error),
#[error("Could not load config")]
LoadConfig(#[source] anyhow::Error),

View File

@@ -14,13 +14,11 @@ lazy_static! {
.file(
std::env::var("TWBA_CONFIG")
.map(|v| {
dbg!(&v);
info!("using {} as primary config source after env", v);
info!("using '{}' as primary config source after env", v);
v
})
.unwrap_or_else(|x| {
dbg!(x);
error!("could not get config location from env");
warn!("could not get config location from env");
"./settings.toml".to_string()
})
)
@@ -51,6 +49,8 @@ async fn run() -> Result<()> {
trace!("run");
let x = &CONF.google;
debug!("{:?}", x);
let conf = &CONF.clone();
dbg!(conf);
trace!("creating db-connection with db url: {}", &CONF.db_url);
let db = twba_local_db::open_database(Some(&CONF.db_url)).await?;

View File

@@ -1,5 +1,6 @@
pub use crate::errors::UploaderError;
use std::fmt::Debug;
use std::path::Path;
pub(crate) use std::result::Result as StdResult;
pub type Result<T> = StdResult<T, UploaderError>;
@@ -7,5 +8,7 @@ pub type Result<T> = StdResult<T, UploaderError>;
pub(crate) use tracing::{debug, error, info, trace, warn};
pub trait EasyString: Into<String> + Clone + Debug + Send + Sync {}
impl<T> EasyString for T where T: Into<String> + Clone + Debug + Send + Sync {}
pub trait EasyPath: AsRef<Path> + Debug + Send + Sync {}
impl<T> EasyPath for T where T: AsRef<Path> + Debug + Send + Sync {}