admin_config/
upload_config.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct UploadConfig {
5    /// 允许的文件类型 (MIME types, 逗号分隔)
6    pub allowed_types: String,
7    /// 最大文件大小 (MB)
8    pub max_file_size: u64,
9    /// 上传目录
10    pub upload_dir: String,
11    /// 临时目录
12    pub temp_dir: String,
13}
14
15impl Default for UploadConfig {
16    fn default() -> Self {
17        Self {
18            allowed_types: "image/jpeg,image/png,image/gif,image/webp,application/pdf".to_string(),
19            max_file_size: 20,
20            upload_dir: "./uploads".to_string(),
21            temp_dir: "./temp".to_string(),
22        }
23    }
24}
25
26impl UploadConfig {
27    pub fn allowed_types_list(&self) -> Vec<String> {
28        self.allowed_types.split(',').map(|s| s.trim().to_string()).collect()
29    }
30
31    pub fn max_file_size_bytes(&self) -> u64 {
32        self.max_file_size * 1024 * 1024
33    }
34}