Skip to main content

systemprompt_models/paths/
storage.rs

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