Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions src/adapters/api/controllers/routes.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use axum::middleware::from_fn;
use utoipa_axum::router::OpenApiRouter;
use utoipa_axum::routes;
use crate::commands::startup::get_api_config;
use crate::constants::inner_constants::ENVIRONMENT_SERVICE;
use crate::gpodder::auth::authentication::login;
use crate::gpodder::parametrization::{get_client_parametrization_router};
use crate::gpodder::device::device_controller::get_device_router;
use crate::gpodder::episodes::gpodder_episodes::get_gpodder_episodes_router;
use crate::gpodder::parametrization::get_client_parametrization_router;
use crate::gpodder::session_middleware::handle_cookie_session;
use crate::gpodder::subscription::subscriptions::get_subscription_router;
use axum::middleware::from_fn;
use utoipa_axum::router::OpenApiRouter;
use utoipa_axum::routes;

pub fn global_routes() -> OpenApiRouter {
let base_path = ENVIRONMENT_SERVICE
Expand All @@ -18,29 +18,27 @@ pub fn global_routes() -> OpenApiRouter {
let service = get_api_config();

let mut router = match base_path.is_empty() {
true=>{
true => OpenApiRouter::new()
.merge(get_client_parametrization_router())
.merge(service),
false => OpenApiRouter::new().nest(
&base_path,
OpenApiRouter::new()
.merge(get_client_parametrization_router())
.merge(service)
}
false=>{
OpenApiRouter::new()
.nest(&base_path, OpenApiRouter::new()
.merge(get_client_parametrization_router())
.merge(service))
}
.merge(get_client_parametrization_router())
.merge(service),
),
};

if ENVIRONMENT_SERVICE.gpodder_integration_enabled {
use crate::gpodder::auth::authentication::__path_login;
router = router
.routes(routes!(login))
.nest("/api/2",OpenApiRouter::new()
.merge(get_subscription_router())
.merge(get_device_router())
.merge(get_gpodder_episodes_router())
.layer(from_fn(handle_cookie_session))
router = router.routes(routes!(login)).nest(
"/api/2",
OpenApiRouter::new()
.merge(get_subscription_router())
.merge(get_device_router())
.merge(get_gpodder_episodes_router())
.layer(from_fn(handle_cookie_session)),
);
}
router
}
}
2 changes: 1 addition & 1 deletion src/adapters/api/models/device/device_response.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use utoipa::ToSchema;
use crate::domain::models::device::model::Device;
use utoipa::ToSchema;

#[derive(Serialize, Deserialize, Clone, ToSchema)]
pub struct DeviceResponse {
Expand Down
38 changes: 25 additions & 13 deletions src/adapters/file/file_handle_wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::adapters::file::file_handler::{FileHandler, FileHandlerType, FileRequest};
use crate::adapters::file::local_file_handler::LocalFileHandler;
use crate::adapters::file::s3_file_handler::S3Handler;
use crate::models::podcast_episode::PodcastEpisode;
use crate::models::podcasts::Podcast;
use crate::utils::error::CustomError;
use std::future::Future;
use std::pin::Pin;
use crate::models::podcast_episode::PodcastEpisode;
use crate::models::podcasts::Podcast;

pub struct FileHandleWrapper;

Expand Down Expand Up @@ -56,34 +56,43 @@ impl FileHandleWrapper {
if FileHandlerType::S3 == file_type {
if let Some(file_path) = &episode.file_image_path {
if let Err(e) = S3Handler::remove_file(file_path) {
log::error!("Error removing file: {} with reason {}",
file_path, e);
log::error!(
"Error removing file: {} with reason {}",
file_path,
e
);
}
}
if let Some(file_path) = &episode.file_episode_path {
if let Err(e) = S3Handler::remove_file(file_path) {
log::error!("Error removing file: {} with reason {e}",
file_path);
log::error!(
"Error removing file: {} with reason {e}",
file_path
);
}
}
}
}
});
Ok(())
},
}
FileHandlerType::S3 => {
let image_url = urlencoding::decode(&podcast.image_url).unwrap().to_string();
S3Handler::remove_file(&image_url)?;
PodcastEpisode::get_episodes_by_podcast_id(podcast.id)?.iter()
PodcastEpisode::get_episodes_by_podcast_id(podcast.id)?
.iter()
.for_each(|episode| {
// Remove the episode directory
if let Some(download_type) = &episode.download_location {
let file_type = FileHandlerType::from(download_type.as_str());
if FileHandlerType::S3 == file_type {
if let Some(file_path) = &episode.file_image_path {
if let Err(e) = S3Handler::remove_file(file_path) {
log::error!("Error removing file: {} with reason {}",
file_path, e);
log::error!(
"Error removing file: {} with reason {}",
file_path,
e
);
}
}
if let Some(file_path) = &episode.file_episode_path {
Expand All @@ -94,8 +103,11 @@ impl FileHandleWrapper {
} else {
if let Some(file_path) = &episode.file_image_path {
if let Err(e) = LocalFileHandler::remove_file(file_path) {
log::error!("Error removing file: {} with reason {}",
file_path, e);
log::error!(
"Error removing file: {} with reason {}",
file_path,
e
);
}
}
if let Some(file_path) = &episode.file_episode_path {
Expand All @@ -107,7 +119,7 @@ impl FileHandleWrapper {
}
});
Ok(())
},
}
}
}
pub fn remove_file(path: &str, download_location: &FileHandlerType) -> Result<(), CustomError> {
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/persistence/dbconfig/db.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::adapters::persistence::dbconfig::DBType;
use crate::commands::startup::DbPool;
use crate::constants::inner_constants::ENVIRONMENT_SERVICE;
use diesel::r2d2::ConnectionManager;
use diesel::Connection;
use r2d2::Pool;
use std::process::exit;
use std::sync::OnceLock;
use std::time::Duration;
use crate::commands::startup::DbPool;

#[derive(Debug)]
pub struct ConnectionOptions {
Expand Down
Loading