zai_rs/tool/file_parser_result/
response.rs1use serde::{Deserialize, Serialize};
7
8use super::request::FormatType;
9
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
12#[serde(rename_all = "lowercase")]
13pub enum ParserStatus {
14 Processing,
16 Succeeded,
18 Failed,
20}
21
22impl std::fmt::Display for ParserStatus {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 match self {
25 ParserStatus::Processing => write!(f, "processing"),
26 ParserStatus::Succeeded => write!(f, "succeeded"),
27 ParserStatus::Failed => write!(f, "failed"),
28 }
29 }
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct FileParserResultResponse {
35 pub status: ParserStatus,
37 pub message: String,
39 pub task_id: String,
41 pub content: Option<String>,
43 #[serde(rename = "parsing_result_url")]
45 pub parsing_result_url: Option<String>,
46}
47
48impl FileParserResultResponse {
49 pub fn is_success(&self) -> bool {
51 self.status == ParserStatus::Succeeded
52 }
53
54 pub fn is_processing(&self) -> bool {
56 self.status == ParserStatus::Processing
57 }
58
59 pub fn is_failed(&self) -> bool {
61 self.status == ParserStatus::Failed
62 }
63
64 pub fn task_id(&self) -> &str {
66 &self.task_id
67 }
68
69 pub fn content(&self) -> Option<&str> {
71 self.content.as_deref()
72 }
73
74 pub fn download_url(&self) -> Option<&str> {
76 self.parsing_result_url.as_deref()
77 }
78
79 pub fn get_result(&self, format_type: &FormatType) -> Option<&str> {
81 match format_type {
82 FormatType::Text => self.content(),
83 FormatType::DownloadLink => self.download_url(),
84 }
85 }
86}