diff --git a/src/interfaces/api/handlers/batch_handler.rs b/src/interfaces/api/handlers/batch_handler.rs index 8edf7e81..93c3c40f 100644 --- a/src/interfaces/api/handlers/batch_handler.rs +++ b/src/interfaces/api/handlers/batch_handler.rs @@ -1,5 +1,5 @@ use axum::{ - extract::{Json, State}, + extract::{Json, Query, State}, http::StatusCode, response::{IntoResponse, Response}, }; @@ -12,6 +12,7 @@ use crate::application::dtos::folder_dto::FolderDto; use crate::application::services::batch_operations::{ BatchOperationService, BatchResult, BatchStats, }; +use crate::interfaces::api::deserializer; use crate::interfaces::api::handlers::ApiResult; use crate::interfaces::middleware::auth::AuthUser; @@ -646,6 +647,24 @@ pub struct BatchDownloadRequest { pub folder_ids: Vec, } +#[derive(Debug, Deserialize)] +pub struct BatchDownloadQuery { + #[serde(default, deserialize_with = "deserializer::deserialize_csv")] + pub file_ids: Vec, // will deserialize query string "1,2,3" into Vec + #[serde(default, deserialize_with = "deserializer::deserialize_csv")] + pub folder_ids: Vec, // will deserialize query string "1,2,3" into Vec +} + +// convert BatchDownloadQuery into BatchDownloadRequest +impl From for BatchDownloadRequest { + fn from(q: BatchDownloadQuery) -> Self { + Self { + file_ids: q.file_ids, + folder_ids: q.folder_ids, + } + } +} + /// Handler for moving multiple files and folders to trash in batch #[utoipa::path( post, @@ -832,6 +851,14 @@ pub async fn move_folders_batch( Ok((status_code, Json(response)).into_response()) } +// Hander as a workarround for drag & drop (does not support POST requests) +pub async fn download_batch_querystring( + State(state): State, + auth_user: AuthUser, + Query(params): Query, +) -> Result { + process_download_batch(state, auth_user, params.into()).await +} /// Handler for downloading multiple files and folders as a single ZIP. /// /// The ZIP is written to a temporary file and streamed to the client, @@ -847,10 +874,18 @@ pub async fn move_folders_batch( ), tag = "batch" )] -pub async fn download_batch( +pub async fn download_batch_post( State(state): State, auth_user: AuthUser, Json(request): Json, +) -> Result { + process_download_batch(state, auth_user, request).await +} + +async fn process_download_batch( + state: BatchHandlerState, + auth_user: AuthUser, + request: BatchDownloadRequest, ) -> Result { if request.file_ids.is_empty() && request.folder_ids.is_empty() { return Err((