cloudreve_api/api/v4/models/
share.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Serialize, Deserialize, Clone)]
7pub struct ShareLink {
8 pub id: String,
9 pub name: String,
10 pub visited: i64,
11 #[serde(default)]
12 pub downloaded: i64,
13 #[serde(default)]
14 pub price: i64,
15 pub unlocked: bool,
16 pub source_type: ShareSourceType,
17 pub owner: super::auth::NewUser,
18 pub created_at: String,
19 pub expired: bool,
20 pub url: String,
21 #[serde(default)]
22 pub permission_setting: Option<super::file::PermissionSetting>,
23 #[serde(rename = "is_private")]
24 pub is_private: Option<bool>,
25 pub password: Option<String>,
26 pub source_uri: Option<String>,
27 pub share_view: Option<bool>,
28 pub show_readme: Option<bool>,
29 pub password_protected: Option<bool>,
30 pub expires: Option<String>,
31 pub expired_at: Option<String>,
32 #[serde(default)]
33 pub download_count: u64,
34}
35
36#[derive(Debug, Serialize, Clone, PartialEq)]
38pub enum ShareSourceType {
39 File = 0,
40 Folder = 1,
41}
42
43impl<'de> Deserialize<'de> for ShareSourceType {
44 fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
45 where
46 D: serde::Deserializer<'de>,
47 {
48 use serde::de::Error;
49 use serde_json::Value;
50
51 let value = Value::deserialize(deserializer)?;
52 match value {
53 Value::Number(n) => {
54 if let Some(i) = n.as_i64() {
55 match i {
56 0 => Ok(ShareSourceType::File),
57 1 => Ok(ShareSourceType::Folder),
58 _ => Err(Error::custom(format!(
59 "Invalid ShareSourceType value: {}",
60 i
61 ))),
62 }
63 } else {
64 Err(Error::custom(format!(
65 "Invalid ShareSourceType number: {}",
66 n
67 )))
68 }
69 }
70 Value::String(s) => match s.as_str() {
71 "0" => Ok(ShareSourceType::File),
72 "1" => Ok(ShareSourceType::Folder),
73 _ => Err(Error::custom(format!(
74 "Invalid ShareSourceType value: {}",
75 s
76 ))),
77 },
78 _ => Err(Error::custom(format!(
79 "Invalid ShareSourceType type: {:?}",
80 value
81 ))),
82 }
83 }
84}
85
86#[derive(Debug, Serialize)]
88pub struct CreateShareLinkRequest {
89 pub permissions: super::file::PermissionSetting,
90 pub uri: String,
91 pub is_private: Option<bool>,
92 pub share_view: Option<bool>,
93 pub expire: Option<u32>,
94 pub price: Option<i32>,
95 pub password: Option<String>,
96 pub show_readme: Option<bool>,
97}
98
99#[derive(Debug, Serialize)]
101pub struct EditShareLinkRequest {
102 pub permissions: super::file::PermissionSetting,
103 pub uri: String,
104 pub share_view: Option<bool>,
105 pub expire: Option<u32>,
106 pub price: Option<i32>,
107 pub show_readme: Option<bool>,
108}
109
110#[derive(Debug, Serialize)]
112pub struct AbuseReportRequest<'a> {
113 pub reason: &'a str,
114}