systemprompt_models/paths/
mod.rs1mod build;
2pub mod constants;
3mod error;
4mod storage;
5mod system;
6mod web;
7
8pub use build::BuildPaths;
9pub use constants::{cloud_container, dir_names, file_names};
10pub use error::PathError;
11pub use storage::StoragePaths;
12pub use system::SystemPaths;
13pub use web::WebPaths;
14
15use std::path::Path;
16use std::sync::OnceLock;
17
18use crate::profile::PathsConfig;
19use systemprompt_extension::AssetPaths;
20
21static APP_PATHS: OnceLock<AppPaths> = OnceLock::new();
22
23#[derive(Debug, Clone)]
24pub struct AppPaths {
25 system: SystemPaths,
26 web: WebPaths,
27 build: BuildPaths,
28 storage: StoragePaths,
29}
30
31impl AppPaths {
32 pub fn init(profile_paths: &PathsConfig) -> Result<(), PathError> {
33 if APP_PATHS.get().is_some() {
34 return Ok(());
35 }
36 let paths = Self::from_profile(profile_paths)?;
37 APP_PATHS
38 .set(paths)
39 .map_err(|_| PathError::AlreadyInitialized)?;
40 Ok(())
41 }
42
43 pub fn get() -> Result<&'static Self, PathError> {
44 APP_PATHS.get().ok_or(PathError::NotInitialized)
45 }
46
47 fn from_profile(paths: &PathsConfig) -> Result<Self, PathError> {
48 Ok(Self {
49 system: SystemPaths::from_profile(paths)?,
50 web: WebPaths::from_profile(paths),
51 build: BuildPaths::from_profile(paths),
52 storage: StoragePaths::from_profile(paths)?,
53 })
54 }
55
56 pub const fn system(&self) -> &SystemPaths {
57 &self.system
58 }
59
60 pub const fn web(&self) -> &WebPaths {
61 &self.web
62 }
63
64 pub const fn build(&self) -> &BuildPaths {
65 &self.build
66 }
67
68 pub const fn storage(&self) -> &StoragePaths {
69 &self.storage
70 }
71}
72
73impl AssetPaths for AppPaths {
74 fn storage_files(&self) -> &Path {
75 self.storage.files()
76 }
77
78 fn web_dist(&self) -> &Path {
79 self.web.dist()
80 }
81}