From c4af29c5e0610f30d985dddb15d605a5cd579fd8 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Tue, 4 Jun 2024 21:51:48 +0200 Subject: [PATCH] move data mod out of youtube mod --- src/client.rs | 15 ++++++--------- src/client/{youtube => }/data.rs | 6 +++--- src/client/youtube.rs | 15 ++++----------- 3 files changed, 13 insertions(+), 23 deletions(-) rename src/client/{youtube => }/data.rs (98%) diff --git a/src/client.rs b/src/client.rs index d2cd033..d10b72f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,7 +1,8 @@ -use crate::client::youtube::data::VideoData; -use crate::client::youtube::data::{create_youtube_description, create_youtube_title}; +use crate::client::data::VideoData; +use crate::client::data::{create_youtube_description, create_youtube_title}; use crate::prelude::*; use crate::CONF; +use data::Location; use google_youtube3::api::enums::{PlaylistStatusPrivacyStatusEnum, VideoStatusPrivacyStatusEnum}; use google_youtube3::api::Scope; use lazy_static::lazy_static; @@ -15,8 +16,8 @@ use twba_local_db::re_exports::sea_orm::{ ActiveModelTrait, ActiveValue, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, Order, QueryFilter, QueryOrder, QuerySelect, }; -use youtube::data::Location; +pub(crate) mod data; mod youtube; lazy_static! { @@ -277,14 +278,10 @@ impl UploaderClient { let users = twba_local_db::get_watched_users(&db).await?; for user in users { let user_id = user.id.to_string(); - let client = youtube::YoutubeClient::new(&YOUTUBE_DEFAULT_SCOPES, Some(user)).await?; + let client = + youtube::YoutubeClient::new(&YOUTUBE_DEFAULT_SCOPES, Some(user.youtube_id)).await?; clients.insert(user_id, client); } - if clients.is_empty() { - //insert default user/client - let client = youtube::YoutubeClient::new(&YOUTUBE_DEFAULT_SCOPES, None).await?; - clients.insert("unknown".into(), client); - } Ok(Self { db, diff --git a/src/client/youtube/data.rs b/src/client/data.rs similarity index 98% rename from src/client/youtube/data.rs rename to src/client/data.rs index 992af30..47acbb5 100644 --- a/src/client/youtube/data.rs +++ b/src/client/data.rs @@ -1,4 +1,4 @@ -use crate::client::youtube::data::substitutions::*; +use crate::client::data::substitutions::*; use crate::prelude::*; use crate::CONF; use chrono::{DateTime, Datelike, ParseResult, Utc}; @@ -196,8 +196,8 @@ fn parse_date(date: &str) -> ParseResult> { #[cfg(test)] mod test { - use crate::client::youtube::data::create_youtube_title; - use crate::client::youtube::data::Location; + use crate::client::data::create_youtube_title; + use crate::client::data::Location; use crate::prelude::twba_local_db::prelude::{Status, UsersModel, VideosModel}; #[test] diff --git a/src/client/youtube.rs b/src/client/youtube.rs index 8378015..3c06b41 100644 --- a/src/client/youtube.rs +++ b/src/client/youtube.rs @@ -1,4 +1,4 @@ -use crate::client::youtube::data::VideoData; +use crate::client::data::VideoData; use crate::prelude::*; use google_youtube3::api::{ Playlist, PlaylistSnippet, PlaylistStatus, Scope, VideoSnippet, VideoStatus, @@ -14,10 +14,8 @@ use std::fmt::{Debug, Formatter}; use std::path::{Path, PathBuf}; use tokio::fs; use tracing::instrument; -use twba_local_db::prelude::UsersModel; mod auth; -pub(crate) mod data; mod flow_delegate; pub struct YoutubeClient { @@ -150,8 +148,8 @@ impl Debug for YoutubeClient { } impl YoutubeClient { - #[tracing::instrument(skip(user), fields(user.id = user.as_ref().map(|x| x.id),user.twitch_id = user.as_ref().map(|x| &x.twitch_id)))] - pub async fn new(scopes: &Vec, user: Option) -> Result { + #[tracing::instrument] + pub async fn new(scopes: &Vec, user: Option) -> Result { let hyper_client = Self::create_hyper_client()?; let application_secret_path = PathBuf::from( &shellexpand::full(&crate::CONF.google.youtube.client_secret_path) @@ -159,12 +157,7 @@ impl YoutubeClient { .to_string(), ); - let auth = auth::get_auth( - &application_secret_path, - scopes, - user.as_ref().map(|x| &x.youtube_id), - ) - .await?; + let auth = auth::get_auth(&application_secret_path, scopes, user).await?; let client = google_youtube3::YouTube::new(hyper_client, auth); Ok(Self { client }) }