Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: If8fe8b38c1d9c4fecd40ff71f88d2ae06a6a6964
42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use axum::{Json, extract::State};
|
|
use serde::Deserialize;
|
|
|
|
use crate::{error::ApiError, state::AppState};
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct ExportRequest {
|
|
pub format: String,
|
|
pub destination: PathBuf,
|
|
}
|
|
|
|
pub async fn trigger_export(
|
|
State(state): State<AppState>,
|
|
) -> Result<Json<serde_json::Value>, ApiError> {
|
|
// Default export to JSON in data dir
|
|
let dest =
|
|
pinakes_core::config::Config::default_data_dir().join("export.json");
|
|
let kind = pinakes_core::jobs::JobKind::Export {
|
|
format: pinakes_core::jobs::ExportFormat::Json,
|
|
destination: dest,
|
|
};
|
|
let job_id = state.job_queue.submit(kind).await;
|
|
Ok(Json(serde_json::json!({ "job_id": job_id.to_string() })))
|
|
}
|
|
|
|
pub async fn trigger_export_with_options(
|
|
State(state): State<AppState>,
|
|
Json(req): Json<ExportRequest>,
|
|
) -> Result<Json<serde_json::Value>, ApiError> {
|
|
let format = match req.format.as_str() {
|
|
"csv" => pinakes_core::jobs::ExportFormat::Csv,
|
|
_ => pinakes_core::jobs::ExportFormat::Json,
|
|
};
|
|
let kind = pinakes_core::jobs::JobKind::Export {
|
|
format,
|
|
destination: req.destination,
|
|
};
|
|
let job_id = state.job_queue.submit(kind).await;
|
|
Ok(Json(serde_json::json!({ "job_id": job_id.to_string() })))
|
|
}
|