Skip to main content

systemprompt_models/paths/
storage.rs

1use std::path::{Path, PathBuf};
2
3use super::PathError;
4use crate::profile::PathsConfig;
5
6#[derive(Debug, Clone)]
7pub struct StoragePaths {
8    root: PathBuf,
9    files: PathBuf,
10    exports: PathBuf,
11    css: PathBuf,
12    js: PathBuf,
13    fonts: PathBuf,
14    images: PathBuf,
15    generated_images: PathBuf,
16    logos: PathBuf,
17    audio: PathBuf,
18    video: PathBuf,
19    documents: PathBuf,
20    uploads: PathBuf,
21}
22
23impl StoragePaths {
24    pub fn from_profile(paths: &PathsConfig) -> Result<Self, PathError> {
25        let root = paths
26            .storage
27            .as_ref()
28            .ok_or(PathError::NotConfigured { field: "storage" })?;
29
30        let root = PathBuf::from(root);
31        let files = root.join("files");
32
33        Ok(Self {
34            exports: root.join("exports"),
35            css: files.join("css"),
36            js: files.join("js"),
37            fonts: files.join("fonts"),
38            images: files.join("images"),
39            generated_images: files.join("images/generated"),
40            logos: files.join("images/logos"),
41            audio: files.join("audio"),
42            video: files.join("video"),
43            documents: files.join("documents"),
44            uploads: files.join("uploads"),
45            files,
46            root,
47        })
48    }
49
50    pub fn root(&self) -> &Path {
51        &self.root
52    }
53
54    pub fn files(&self) -> &Path {
55        &self.files
56    }
57
58    pub fn exports(&self) -> &Path {
59        &self.exports
60    }
61
62    pub fn css(&self) -> &Path {
63        &self.css
64    }
65
66    pub fn js(&self) -> &Path {
67        &self.js
68    }
69
70    pub fn fonts(&self) -> &Path {
71        &self.fonts
72    }
73
74    pub fn images(&self) -> &Path {
75        &self.images
76    }
77
78    pub fn generated_images(&self) -> &Path {
79        &self.generated_images
80    }
81
82    pub fn logos(&self) -> &Path {
83        &self.logos
84    }
85
86    pub fn audio(&self) -> &Path {
87        &self.audio
88    }
89
90    pub fn video(&self) -> &Path {
91        &self.video
92    }
93
94    pub fn documents(&self) -> &Path {
95        &self.documents
96    }
97
98    pub fn uploads(&self) -> &Path {
99        &self.uploads
100    }
101}