Music with a live player, Last.fm, video downloads, games, AI chat, moderation, logging, a web dashboard and a Game Boy Activity. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
38 lines
1 KiB
Rust
38 lines
1 KiB
Rust
//! Where things live on disk (same layout as the Python bot):
|
|
//! assets/ files that ship with the bot
|
|
//! data/ everything the bot writes at runtime
|
|
use std::path::PathBuf;
|
|
use std::sync::OnceLock;
|
|
|
|
fn root() -> &'static PathBuf {
|
|
static ROOT: OnceLock<PathBuf> = OnceLock::new();
|
|
ROOT.get_or_init(|| {
|
|
if let Ok(p) = std::env::var("DEZIO_ROOT") {
|
|
return PathBuf::from(p);
|
|
}
|
|
std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."))
|
|
})
|
|
}
|
|
|
|
/// A path under data/ (parent folders are created on demand).
|
|
pub fn data(parts: &[&str]) -> PathBuf {
|
|
let mut p = root().join("data");
|
|
p.extend(parts);
|
|
if let Some(parent) = p.parent() {
|
|
let _ = std::fs::create_dir_all(parent);
|
|
}
|
|
p
|
|
}
|
|
|
|
pub fn asset(parts: &[&str]) -> PathBuf {
|
|
let mut p = root().join("assets");
|
|
p.extend(parts);
|
|
p
|
|
}
|
|
|
|
/// A path under web/ (the dashboard's pages and the Game Boy Activity).
|
|
pub fn web(parts: &[&str]) -> PathBuf {
|
|
let mut p = root().join("web");
|
|
p.extend(parts);
|
|
p
|
|
}
|