1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use serde::{Deserialize, Serialize};
use crate::request::Seconds;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PolicyResp {
    pub access_id: String,
    pub host: String,
    pub policy: String,
    pub signature: String,
    pub success_action_status: u8,
}

unsafe impl Send for PolicyResp {}

unsafe impl Sync for PolicyResp {}

/// Policy构建器
/// # 使用例子
/// ```rust
///
#[derive(Debug, Clone)]
pub struct PolicyBuilder {
    pub expire: Seconds,
    pub upload_dir: String,
    pub content_type: String,
    pub max_upload_size: i64,
}

unsafe impl Send for PolicyBuilder {}

unsafe impl Sync for PolicyBuilder {}

impl Default for PolicyBuilder {
    fn default() -> Self {
        Self::new()
    }
}

impl PolicyBuilder {
    pub fn new() -> Self {
        Self {
            expire: 60,//60秒
            upload_dir: "".to_string(),
            content_type: "text/plain".to_string(),//文本.txt
            max_upload_size: 100 * 1024 * 1024,//100m
        }
    }
    pub fn with_expire(mut self, expire: Seconds) -> Self {
        self.expire = expire;
        self
    }
    pub fn with_upload_dir<S: AsRef<str>>(mut self, upload_dir: S) -> Self {
        self.upload_dir = upload_dir.as_ref().to_string();
        self
    }
    pub fn with_content_type<S: AsRef<str>>(mut self, content_type: S) -> Self {
        self.content_type = content_type.as_ref().to_string();
        self
    }
    pub fn with_max_upload_size(mut self, max_upload_size: i64) -> Self {
        self.max_upload_size = max_upload_size;
        self
    }
}