gewe_http/video_account/
publish.rs

1use crate::client::GeweHttpClient;
2use gewe_core::{
3    GeweError, PublishFinderCdnRequest, PublishFinderCdnResponse, PublishFinderWebRequest,
4    PublishFinderWebResponse, SendFinderSnsRequest, UploadFinderVideoRequest,
5    UploadFinderVideoResponse,
6};
7use tracing::instrument;
8
9impl GeweHttpClient {
10    #[instrument(skip(self))]
11    pub async fn upload_finder_video(
12        &self,
13        req: UploadFinderVideoRequest<'_>,
14    ) -> Result<UploadFinderVideoResponse, GeweError> {
15        let env = self
16            .post_api::<_, UploadFinderVideoResponse>("gewe/v2/api/finder/uploadFinderVideo", &req)
17            .await?;
18        env.data.ok_or(GeweError::MissingData)
19    }
20
21    #[instrument(skip(self))]
22    pub async fn publish_finder_cdn(
23        &self,
24        req: PublishFinderCdnRequest<'_>,
25    ) -> Result<PublishFinderCdnResponse, GeweError> {
26        let env = self
27            .post_api::<_, PublishFinderCdnResponse>("gewe/v2/api/finder/publishFinderCdn", &req)
28            .await?;
29        env.data.ok_or(GeweError::MissingData)
30    }
31
32    #[instrument(skip(self))]
33    pub async fn publish_finder_web(
34        &self,
35        req: PublishFinderWebRequest<'_>,
36    ) -> Result<PublishFinderWebResponse, GeweError> {
37        let env = self
38            .post_api::<_, PublishFinderWebResponse>("gewe/v2/api/finder/publishFinderWeb", &req)
39            .await?;
40        env.data.ok_or(GeweError::MissingData)
41    }
42
43    #[instrument(skip(self))]
44    pub async fn send_finder_sns(&self, req: SendFinderSnsRequest<'_>) -> Result<(), GeweError> {
45        self.post_api::<_, serde_json::Value>("gewe/v2/api/sns/sendFinderSns", &req)
46            .await?;
47        Ok(())
48    }
49}
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54    use gewe_core::FinderVideoCdn;
55
56    #[test]
57    fn test_upload_finder_video_request() {
58        let req = UploadFinderVideoRequest {
59            app_id: "test_app",
60            video_url: "https://example.com/video.mp4",
61            cover_img_url: "https://example.com/cover.jpg",
62        };
63        let json = serde_json::to_string(&req).expect("Failed to serialize");
64        assert!(json.contains("appId"));
65        assert!(json.contains("videoUrl"));
66        assert!(json.contains("coverImgUrl"));
67    }
68
69    #[test]
70    fn test_publish_finder_cdn_request() {
71        let req = PublishFinderCdnRequest {
72            app_id: "test_app",
73            topic: vec!["topic1"],
74            my_user_name: "my_user",
75            my_role_type: 1,
76            description: "Video description",
77            video_cdn: FinderVideoCdn::default(),
78        };
79        let json = serde_json::to_string(&req).expect("Failed to serialize");
80        assert!(json.contains("appId"));
81        assert!(json.contains("description"));
82        assert!(json.contains("myUserName"));
83    }
84
85    #[test]
86    fn test_publish_finder_web_request() {
87        let req = PublishFinderWebRequest {
88            app_id: "test_app",
89            title: "Video Title",
90            video_url: "https://example.com/video.mp4",
91            thumb_url: "https://example.com/thumb.jpg",
92            description: "Web video",
93        };
94        let json = serde_json::to_string(&req).expect("Failed to serialize");
95        assert!(json.contains("appId"));
96        assert!(json.contains("videoUrl"));
97        assert!(json.contains("title"));
98    }
99}