Skip to content

Commit

Permalink
fix(file): Fixed idv3 tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTV12345 committed Dec 30, 2024
1 parent 933e92f commit 78974c1
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 88 deletions.
9 changes: 5 additions & 4 deletions src/adapters/api/controllers/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;

pub fn global_routes() -> Scope {
let base_path = ENVIRONMENT_SERVICE.sub_directory.clone().unwrap_or("/".to_string());
let base_path = ENVIRONMENT_SERVICE
.sub_directory
.clone()
.unwrap_or("/".to_string());
let openapi = ApiDoc::openapi();
let service = get_api_config();

Expand All @@ -38,9 +41,7 @@ pub fn global_routes() -> Scope {
}

pub fn get_gpodder_api() -> Scope {
if ENVIRONMENT_SERVICE
.gpodder_integration_enabled
{
if ENVIRONMENT_SERVICE.gpodder_integration_enabled {
web::scope("/api/2")
.service(login)
.service(get_authenticated_gpodder())
Expand Down
11 changes: 2 additions & 9 deletions src/adapters/api/models/podcast_episode_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ impl From<PodcastEpisode> for PodcastEpisodeDto {
}
fn map_url(url: &str, status: &str, remote_url: &str) -> String {
match url == DEFAULT_IMAGE_URL {
true => {

ENVIRONMENT_SERVICE.server_url.clone().to_owned() + DEFAULT_IMAGE_URL
}
true => ENVIRONMENT_SERVICE.server_url.clone().to_owned() + DEFAULT_IMAGE_URL,
false => {
if status == "D" {
ENVIRONMENT_SERVICE
.server_url
.clone()
.to_owned()
+ url
ENVIRONMENT_SERVICE.server_url.clone().to_owned() + url
} else {
remote_url.to_string()
}
Expand Down
6 changes: 2 additions & 4 deletions src/adapters/persistence/dbconfig/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ pub fn get_connection() -> r2d2::PooledConnection<ConnectionManager<DBType>> {
fn init_pool() -> DbPool {
let conn = establish_connection();
match conn {
DBType::Postgresql(_) => {
init_postgres_db_pool(&ENVIRONMENT_SERVICE.database_url)
.expect("Failed to connect to database")
}
DBType::Postgresql(_) => init_postgres_db_pool(&ENVIRONMENT_SERVICE.database_url)
.expect("Failed to connect to database"),
DBType::Sqlite(_) => init_sqlite_db_pool(&ENVIRONMENT_SERVICE.database_url)
.expect("Failed to connect to database"),
}
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/ws/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod ws_handler;
pub mod ws_handler;
1 change: 1 addition & 0 deletions src/adapters/ws/ws_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

5 changes: 1 addition & 4 deletions src/auth_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ where
}

fn handle_proxy_auth(&self, req: ServiceRequest) -> MyFuture<B, Error> {
let config = ENVIRONMENT_SERVICE
.reverse_proxy_config
.clone()
.unwrap();
let config = ENVIRONMENT_SERVICE.reverse_proxy_config.clone().unwrap();

let header_val = req.headers().get(config.header_name);

Expand Down
12 changes: 5 additions & 7 deletions src/constants/inner_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub const TELEGRAM_BOT_TOKEN: &str = "TELEGRAM_BOT_TOKEN";
pub const TELEGRAM_BOT_CHAT_ID: &str = "TELEGRAM_BOT_CHAT_ID";
pub const TELEGRAM_API_ENABLED: &str = "TELEGRAM_API_ENABLED";

use utoipa::ToSchema;
use crate::service::logging_service::init_logging;
use utoipa::ToSchema;

// User management roles
#[derive(Serialize, Deserialize, Debug, PartialEq, ToSchema)]
Expand Down Expand Up @@ -134,12 +134,10 @@ pub const DEFAULT_DEVICE: &str = "webview";

// static constants

pub static ENVIRONMENT_SERVICE: LazyLock<EnvironmentService> = LazyLock::new
(|| {
init_logging();
EnvironmentService::new()
});

pub static ENVIRONMENT_SERVICE: LazyLock<EnvironmentService> = LazyLock::new(|| {
init_logging();
EnvironmentService::new()
});

pub static DEFAULT_IMAGE_URL: &str = "ui/default.jpg";
pub static ITUNES: &str = "itunes";
Expand Down
6 changes: 1 addition & 5 deletions src/controllers/controller_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ pub fn unwrap_string(value: &Value) -> String {

pub fn unwrap_string_audio(value: &Value) -> String {
match value.to_string().is_empty() {
true => {

ENVIRONMENT_SERVICE.server_url.clone().to_owned() + DEFAULT_IMAGE_URL
}
true => ENVIRONMENT_SERVICE.server_url.clone().to_owned() + DEFAULT_IMAGE_URL,
false => value.to_string().replace('\"', ""),
}
}

pub fn get_default_image() -> String {

ENVIRONMENT_SERVICE.server_url.clone().to_owned() + DEFAULT_IMAGE_URL
}
29 changes: 5 additions & 24 deletions src/controllers/podcast_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ pub async fn find_podcast(
Ok(HttpResponse::Ok().json(res))
}
Ok(Podindex) => {
if !ENVIRONMENT_SERVICE
.get_config()
.podindex_configured
{
if !ENVIRONMENT_SERVICE.get_config().podindex_configured {
return Ok(HttpResponse::BadRequest().json("Podindex is not configured"));
}

Expand Down Expand Up @@ -331,11 +328,7 @@ pub async fn import_podcasts_from_opml(
thread::spawn(move || {
let rt = Runtime::new().unwrap();
let rng = rand::thread_rng();
rt.block_on(insert_outline(
outline.clone(),
moved_lobby,
rng.clone(),
));
rt.block_on(insert_outline(outline.clone(), moved_lobby, rng.clone()));
});
}
});
Expand All @@ -360,10 +353,7 @@ pub async fn add_podcast_from_podindex(
return Err(CustomError::Forbidden);
}

if !ENVIRONMENT_SERVICE
.get_config()
.podindex_configured
{
if !ENVIRONMENT_SERVICE.get_config().podindex_configured {
return Err(CustomError::BadRequest(
"Podindex is not configured".to_string(),
));
Expand Down Expand Up @@ -527,19 +517,10 @@ pub async fn update_active_podcast(
}

#[async_recursion(?Send)]
async fn insert_outline(
podcast: Outline,
lobby: Data<ChatServerHandle>,
mut rng: ThreadRng,
) {
async fn insert_outline(podcast: Outline, lobby: Data<ChatServerHandle>, mut rng: ThreadRng) {
if !podcast.outlines.is_empty() {
for outline_nested in podcast.clone().outlines {
insert_outline(
outline_nested,
lobby.clone(),
rng.clone(),
)
.await;
insert_outline(outline_nested, lobby.clone(), rng.clone()).await;
}
return;
}
Expand Down
7 changes: 5 additions & 2 deletions src/controllers/settings_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ fn add_podcasts(
outline.add_attribute("type", "rss");
match type_of {
Mode::Local => {
let mut local_url = format!("{}rss/{}", &*ENVIRONMENT_SERVICE.get_server_url(),
podcast.id);
let mut local_url = format!(
"{}rss/{}",
&*ENVIRONMENT_SERVICE.get_server_url(),
podcast.id
);

if let Some(req) = requester.as_ref() {
if let Some(api_key) = req.api_key.as_ref() {
Expand Down
7 changes: 2 additions & 5 deletions src/controllers/user_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ pub async fn update_user(
}
}

if old_username != &user_update.username && !ENVIRONMENT_SERVICE.oidc_configured
{
if old_username != &user_update.username && !ENVIRONMENT_SERVICE.oidc_configured {
// Check if this username is already taken
let new_username_res = User::find_by_username(&user_update.username);
if new_username_res.is_ok() {
Expand Down Expand Up @@ -269,9 +268,7 @@ pub async fn get_invite_link(
return HttpResponse::Forbidden().body("You are not authorized to perform this action");
}

match UserManagementService::get_invite_link(
invite_id.into_inner(),
) {
match UserManagementService::get_invite_link(invite_id.into_inner()) {
Ok(invite) => HttpResponse::Ok().json(invite),
Err(e) => HttpResponse::BadRequest().body(e.to_string()),
}
Expand Down
5 changes: 1 addition & 4 deletions src/gpodder/auth/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ pub async fn login(
}
}

fn handle_proxy_auth(
rq: HttpRequest,
username: String,
) -> Result<HttpResponse, CustomError> {
fn handle_proxy_auth(rq: HttpRequest, username: String) -> Result<HttpResponse, CustomError> {
let config = ENVIRONMENT_SERVICE.reverse_proxy_config.clone().unwrap();
let opt_authorization = rq.headers().get(config.header_name);
match opt_authorization {
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ pub static INDEX_HTML: OnceLock<Markup> = OnceLock::new();
async fn index() -> actix_web::Result<Markup> {
let html = INDEX_HTML.get_or_init(|| {
let dir = ENVIRONMENT_SERVICE.sub_directory.clone().unwrap() + "/ui/";
let manifest_json_location = ENVIRONMENT_SERVICE.sub_directory.clone().unwrap()
+"/manifest.json";
let found_files = std::fs::read_dir( "./static/assets/")
let manifest_json_location =
ENVIRONMENT_SERVICE.sub_directory.clone().unwrap() + "/manifest.json";
let found_files = std::fs::read_dir("./static/assets/")
.expect("Could not read directory")
.map(|x| x.unwrap().file_name().into_string().unwrap())
.collect::<Vec<String>>();
Expand Down
1 change: 0 additions & 1 deletion src/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ impl User {
return false;
}


if let Some(res) = ENVIRONMENT_SERVICE.api_key_admin.clone() {
if !res.is_empty() && res == api_key_to_find {
return true;
Expand Down
12 changes: 12 additions & 0 deletions src/service/download_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ impl DownloadService {
log::error!("Error updating metadata: {:?}", err);
}
}
FileFormat::Id3v2 => {
let result_of_update = Self::update_meta_data_mp3(paths, podcast_episode, podcast);
if let Some(err) = result_of_update.err() {
log::error!("Error updating metadata: {:?}", err);
}
}
FileFormat::WaveformAudio => {
let result_of_update = Self::update_meta_data_mp3(paths, podcast_episode, podcast);
if let Some(err) = result_of_update.err() {
log::error!("Error updating metadata: {:?}", err);
}
}
_ => {
log::error!("File format not supported: {:?}", detected_file);
return Err(CustomError::Conflict(
Expand Down
9 changes: 2 additions & 7 deletions src/service/rust_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,8 @@ impl PodcastService {
.unwrap()
.as_secs();
let mut headers = HeaderMap::new();
let non_hashed_string = ENVIRONMENT_SERVICE
.podindex_api_key
.clone()
.to_owned()
+ &*ENVIRONMENT_SERVICE
.podindex_api_secret
.clone()
let non_hashed_string = ENVIRONMENT_SERVICE.podindex_api_key.clone().to_owned()
+ &*ENVIRONMENT_SERVICE.podindex_api_secret.clone()
+ &seconds.to_string();
let mut hasher = Sha1::new();

Expand Down
5 changes: 1 addition & 4 deletions src/service/telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use crate::models::podcasts::Podcast;
use frankenstein::{Api, ParseMode, SendMessageParams, TelegramApi};

pub fn send_new_episode_notification(podcast_episode: PodcastEpisode, podcast: Podcast) {
let telegram_config = ENVIRONMENT_SERVICE
.telegram_api
.clone()
.unwrap();
let telegram_config = ENVIRONMENT_SERVICE.telegram_api.clone().unwrap();
let api = Api::new(&telegram_config.telegram_bot_token);

let episode_text = format!(
Expand Down
8 changes: 4 additions & 4 deletions src/service/user_management_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ impl UserManagementService {
}
}

pub fn get_invite_link(
invite_id: String,
) -> Result<String, CustomError> {
pub fn get_invite_link(invite_id: String) -> Result<String, CustomError> {
let invite = Invite::find_invite(invite_id)?;
match invite {
Some(invite) => Ok(ENVIRONMENT_SERVICE.server_url.to_string() + "ui/invite/" + &invite.id),
Some(invite) => {
Ok(ENVIRONMENT_SERVICE.server_url.to_string() + "ui/invite/" + &invite.id)
}
None => Err(CustomError::NotFound),
}
}
Expand Down

0 comments on commit 78974c1

Please sign in to comment.