use crate::client::exports::{ExportFormat, ExportMetadata, ExportTarget};
use serde::Serialize;
#[derive(Debug)]
pub(crate) struct StagedExport(pub(crate) tempfile::NamedTempFile);
impl PartialEq for StagedExport {
fn eq(&self, other: &Self) -> bool {
self.0.path() == other.0.path()
}
}
impl Eq for StagedExport {}
#[derive(Debug, Eq, PartialEq, Serialize)]
pub struct ExportSuccess {
pub resource: ExportResource,
pub board_id: String,
pub list_id: Option<String>,
pub card_id: Option<String>,
pub attachment_id: Option<String>,
pub format: ExportFormat,
pub destination: String,
pub bytes_written: u64,
pub file_saved: bool,
pub http_status: u16,
pub content_type: Option<String>,
#[serde(skip)]
pub(crate) staged: Option<StagedExport>,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ExportResource {
Board,
Card,
Attachment,
}
impl ExportSuccess {
pub(crate) fn new(
target: ExportTarget,
format: ExportFormat,
destination: String,
response: ExportMetadata,
) -> Self {
let (resource, board_id, list_id, card_id, attachment_id) = match target {
ExportTarget::Board { board_id } => (ExportResource::Board, board_id, None, None, None),
ExportTarget::Card {
board_id,
list_id,
card_id,
} => (
ExportResource::Card,
board_id,
Some(list_id),
Some(card_id),
None,
),
ExportTarget::Attachment {
board_id,
attachment_id,
} => (
ExportResource::Attachment,
board_id,
None,
None,
Some(attachment_id),
),
};
Self {
resource,
board_id,
list_id,
card_id,
attachment_id,
format,
destination,
bytes_written: response.bytes_written,
file_saved: false,
http_status: response.http_status,
content_type: response.content_type,
staged: None,
}
}
}