systemprompt_files/config/
validator.rs1use anyhow::Result;
2use systemprompt_traits::validation_report::{
3 ValidationError, ValidationReport, ValidationWarning,
4};
5use systemprompt_traits::{ConfigProvider, DomainConfig, DomainConfigError};
6
7use super::types::FilesConfigYaml;
8use super::FilesConfig;
9
10const MAX_RECOMMENDED_FILE_SIZE: u64 = 2 * 1024 * 1024 * 1024;
11const MIN_VIDEO_FILE_SIZE: u64 = 100 * 1024 * 1024;
12
13#[derive(Debug, Default)]
14pub struct FilesConfigValidator {
15 config: Option<FilesConfigYaml>,
16}
17
18impl FilesConfigValidator {
19 pub fn new() -> Self {
20 Self::default()
21 }
22}
23
24impl DomainConfig for FilesConfigValidator {
25 fn domain_id(&self) -> &'static str {
26 "files"
27 }
28
29 fn priority(&self) -> u32 {
30 10
31 }
32
33 fn load(&mut self, _config: &dyn ConfigProvider) -> Result<(), DomainConfigError> {
34 let yaml_config = FilesConfig::load_yaml_config()
35 .map_err(|e| DomainConfigError::LoadError(e.to_string()))?;
36 self.config = Some(yaml_config);
37 Ok(())
38 }
39
40 fn validate(&self) -> Result<ValidationReport, DomainConfigError> {
41 let mut report = ValidationReport::new("files");
42
43 let config = self
44 .config
45 .as_ref()
46 .ok_or_else(|| DomainConfigError::ValidationError("Not loaded".into()))?;
47
48 if !config.url_prefix.starts_with('/') {
49 report.add_error(ValidationError::new(
50 "files.urlPrefix",
51 "URL prefix must start with '/'",
52 ));
53 }
54
55 if config.upload.max_file_size_bytes > MAX_RECOMMENDED_FILE_SIZE {
56 report.add_warning(
57 ValidationWarning::new(
58 "files.upload.maxFileSizeBytes",
59 "Max file size > 2GB may cause memory issues",
60 )
61 .with_suggestion("Consider using a smaller max file size for better performance"),
62 );
63 }
64
65 if config.upload.allowed_types.video
66 && config.upload.max_file_size_bytes < MIN_VIDEO_FILE_SIZE
67 {
68 report.add_warning(
69 ValidationWarning::new(
70 "files.upload.allowedTypes.video",
71 "Video uploads enabled but max file size < 100MB",
72 )
73 .with_suggestion("Increase maxFileSizeBytes to at least 100MB for video uploads"),
74 );
75 }
76
77 Ok(report)
78 }
79}