zai_rs/tool/file_parser_result/
response.rs1use serde::{Deserialize, Serialize};
4
5use super::request::FormatType;
6
7#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
9#[serde(rename_all = "lowercase")]
10pub enum ParserStatus {
11 Processing,
13 Succeeded,
15 Failed,
17}
18
19impl std::fmt::Display for ParserStatus {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 match self {
22 ParserStatus::Processing => write!(f, "processing"),
23 ParserStatus::Succeeded => write!(f, "succeeded"),
24 ParserStatus::Failed => write!(f, "failed"),
25 }
26 }
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct FileParseResultResponse {
32 pub status: ParserStatus,
34 pub message: String,
36 pub task_id: String,
38 pub content: Option<String>,
40 #[serde(rename = "parsing_result_url")]
42 pub parsing_result_url: Option<String>,
43}
44
45impl FileParseResultResponse {
46 pub fn is_success(&self) -> bool {
48 self.status == ParserStatus::Succeeded
49 }
50
51 pub fn is_processing(&self) -> bool {
53 self.status == ParserStatus::Processing
54 }
55
56 pub fn is_failed(&self) -> bool {
58 self.status == ParserStatus::Failed
59 }
60
61 pub fn task_id(&self) -> &str {
63 &self.task_id
64 }
65
66 pub fn content(&self) -> Option<&str> {
68 self.content.as_deref()
69 }
70
71 pub fn download_url(&self) -> Option<&str> {
73 self.parsing_result_url.as_deref()
74 }
75
76 pub fn get_result(&self, format_type: &FormatType) -> Option<&str> {
78 match format_type {
79 FormatType::Text => self.content(),
80 FormatType::DownloadLink => self.download_url(),
81 }
82 }
83}