Skip to main content

cloudreve_api/api/v4/models/
response.rs

1//! Response types for Cloudreve API v4
2
3use serde::Deserialize;
4
5/// Upload session response
6#[derive(Debug, Deserialize)]
7pub struct UploadSessionResponse {
8    pub session_id: String,
9    #[serde(default)]
10    pub upload_id: Option<String>,
11    pub chunk_size: u64,
12    pub expires: u64,
13    #[serde(default)]
14    pub upload_urls: Option<Vec<String>>,
15    #[serde(default)]
16    pub credential: Option<String>,
17    #[serde(default)]
18    pub complete_url: Option<String>,
19    pub storage_policy: super::storage::StoragePolicy,
20    #[serde(default)]
21    pub mime_type: Option<String>,
22    #[serde(default)]
23    pub upload_policy: Option<String>,
24}
25
26impl UploadSessionResponse {
27    /// Calculate total number of chunks based on file size and chunk size
28    pub fn total_chunks(&self, file_size: u64) -> u32 {
29        if self.chunk_size == 0 {
30            return 1;
31        }
32        file_size.div_ceil(self.chunk_size) as u32
33    }
34}
35
36/// Download URL response
37#[derive(Debug, Deserialize)]
38pub struct DownloadUrlResponse {
39    pub urls: Vec<DownloadUrlItem>,
40    pub expires: String,
41}
42
43/// Download URL item
44#[derive(Debug, Deserialize)]
45pub struct DownloadUrlItem {
46    pub url: String,
47    #[serde(default)]
48    pub stream_saver_display_name: Option<String>,
49}
50
51/// Archive list response
52#[derive(Debug, Deserialize)]
53pub struct ArchiveListResponse {
54    pub files: Vec<ArchiveFileItem>,
55}
56
57/// Archive file item
58#[derive(Debug, Deserialize)]
59pub struct ArchiveFileItem {
60    pub name: String,
61    pub size: u64,
62    pub r#type: String,
63    pub path: String,
64}
65
66/// Viewer session response
67#[derive(Debug, Deserialize)]
68pub struct ViewerSessionResponse {
69    pub session_id: String,
70}