determine blobstore path and mount blob file server
This commit is contained in:
parent
a37288225a
commit
9013ccb3d6
|
@ -35,7 +35,9 @@ travis-ci = { repository = "peachcloud/peach-web", branch = "master" }
|
||||||
maintenance = { status = "actively-developed" }
|
maintenance = { status = "actively-developed" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
dirs = "4.0.0"
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
|
#golgi = "0.1.0"
|
||||||
golgi = { path = "../../../playground/rust/golgi" }
|
golgi = { path = "../../../playground/rust/golgi" }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
|
@ -9,21 +9,25 @@ use serde_yaml::Error as YamlError;
|
||||||
/// Custom error type encapsulating all possible errors for the web application.
|
/// Custom error type encapsulating all possible errors for the web application.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum PeachWebError {
|
pub enum PeachWebError {
|
||||||
Golgi(GolgiError),
|
|
||||||
Json(JsonError),
|
|
||||||
Yaml(YamlError),
|
|
||||||
FailedToRegisterDynDomain(String),
|
FailedToRegisterDynDomain(String),
|
||||||
|
Golgi(GolgiError),
|
||||||
|
HomeDir,
|
||||||
|
Json(JsonError),
|
||||||
|
OsString,
|
||||||
PeachLib { source: PeachError, msg: String },
|
PeachLib { source: PeachError, msg: String },
|
||||||
|
Yaml(YamlError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for PeachWebError {
|
impl std::error::Error for PeachWebError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
match *self {
|
match *self {
|
||||||
PeachWebError::Golgi(ref source) => Some(source),
|
|
||||||
PeachWebError::Json(ref source) => Some(source),
|
|
||||||
PeachWebError::Yaml(ref source) => Some(source),
|
|
||||||
PeachWebError::FailedToRegisterDynDomain(_) => None,
|
PeachWebError::FailedToRegisterDynDomain(_) => None,
|
||||||
|
PeachWebError::Golgi(ref source) => Some(source),
|
||||||
|
PeachWebError::HomeDir => None,
|
||||||
|
PeachWebError::Json(ref source) => Some(source),
|
||||||
|
PeachWebError::OsString => None,
|
||||||
PeachWebError::PeachLib { ref source, .. } => Some(source),
|
PeachWebError::PeachLib { ref source, .. } => Some(source),
|
||||||
|
PeachWebError::Yaml(ref source) => Some(source),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,13 +35,21 @@ impl std::error::Error for PeachWebError {
|
||||||
impl std::fmt::Display for PeachWebError {
|
impl std::fmt::Display for PeachWebError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
PeachWebError::Golgi(ref source) => write!(f, "Golgi error: {}", source),
|
|
||||||
PeachWebError::Json(ref source) => write!(f, "Serde JSON error: {}", source),
|
|
||||||
PeachWebError::Yaml(ref source) => write!(f, "Serde YAML error: {}", source),
|
|
||||||
PeachWebError::FailedToRegisterDynDomain(ref msg) => {
|
PeachWebError::FailedToRegisterDynDomain(ref msg) => {
|
||||||
write!(f, "DYN DNS error: {}", msg)
|
write!(f, "DYN DNS error: {}", msg)
|
||||||
}
|
}
|
||||||
|
PeachWebError::Golgi(ref source) => write!(f, "Golgi error: {}", source),
|
||||||
|
PeachWebError::HomeDir => write!(
|
||||||
|
f,
|
||||||
|
"Filesystem error: failed to determine home directory path"
|
||||||
|
),
|
||||||
|
PeachWebError::Json(ref source) => write!(f, "Serde JSON error: {}", source),
|
||||||
|
PeachWebError::OsString => write!(
|
||||||
|
f,
|
||||||
|
"Filesystem error: failed to convert OsString to String for go-ssb directory path"
|
||||||
|
),
|
||||||
PeachWebError::PeachLib { ref source, .. } => write!(f, "{}", source),
|
PeachWebError::PeachLib { ref source, .. } => write!(f, "{}", source),
|
||||||
|
PeachWebError::Yaml(ref source) => write!(f, "Serde YAML error: {}", source),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,12 +66,6 @@ impl From<JsonError> for PeachWebError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<YamlError> for PeachWebError {
|
|
||||||
fn from(err: YamlError) -> PeachWebError {
|
|
||||||
PeachWebError::Yaml(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<PeachError> for PeachWebError {
|
impl From<PeachError> for PeachWebError {
|
||||||
fn from(err: PeachError) -> PeachWebError {
|
fn from(err: PeachError) -> PeachWebError {
|
||||||
PeachWebError::PeachLib {
|
PeachWebError::PeachLib {
|
||||||
|
@ -68,3 +74,9 @@ impl From<PeachError> for PeachWebError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<YamlError> for PeachWebError {
|
||||||
|
fn from(err: YamlError) -> PeachWebError {
|
||||||
|
PeachWebError::Yaml(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
use rocket::{catchers, fs::FileServer, routes, Build, Rocket};
|
use rocket::{catchers, fs::FileServer, routes, Build, Rocket};
|
||||||
use rocket_dyn_templates::Template;
|
use rocket_dyn_templates::Template;
|
||||||
|
|
||||||
use crate::routes::{
|
use crate::{
|
||||||
authentication::*,
|
routes::{
|
||||||
catchers::*,
|
authentication::*,
|
||||||
index::*,
|
catchers::*,
|
||||||
scuttlebutt::*,
|
index::*,
|
||||||
settings::{admin::*, dns::*, menu::*, network::*, scuttlebutt::*, theme::*},
|
scuttlebutt::*,
|
||||||
status::{device::*, network::*, scuttlebutt::*},
|
settings::{admin::*, dns::*, menu::*, network::*, scuttlebutt::*, theme::*},
|
||||||
|
status::{device::*, network::*, scuttlebutt::*},
|
||||||
|
},
|
||||||
|
utils,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Create a Rocket instance and mount PeachPub routes, fileserver and
|
/// Create a Rocket instance and mount PeachPub routes, fileserver and
|
||||||
|
@ -15,6 +18,10 @@ use crate::routes::{
|
||||||
/// settings and status routes related to networking and the device (memory,
|
/// settings and status routes related to networking and the device (memory,
|
||||||
/// hard disk, CPU etc.).
|
/// hard disk, CPU etc.).
|
||||||
pub fn mount_peachpub_routes(rocket: Rocket<Build>) -> Rocket<Build> {
|
pub fn mount_peachpub_routes(rocket: Rocket<Build>) -> Rocket<Build> {
|
||||||
|
// set the `.ssb-go` path in order to mount the blob fileserver
|
||||||
|
let ssb_path = utils::get_go_ssb_path().expect("define ssb-go dir path");
|
||||||
|
let blobstore = format!("{}/blobs/sha256", ssb_path);
|
||||||
|
|
||||||
rocket
|
rocket
|
||||||
.mount(
|
.mount(
|
||||||
"/",
|
"/",
|
||||||
|
@ -81,6 +88,7 @@ pub fn mount_peachpub_routes(rocket: Rocket<Build>) -> Rocket<Build> {
|
||||||
)
|
)
|
||||||
.mount("/status", routes![scuttlebutt_status])
|
.mount("/status", routes![scuttlebutt_status])
|
||||||
.mount("/", FileServer::from("static"))
|
.mount("/", FileServer::from("static"))
|
||||||
|
.mount("/blob", FileServer::from(blobstore).rank(-1))
|
||||||
.register("/", catchers![not_found, internal_error, forbidden])
|
.register("/", catchers![not_found, internal_error, forbidden])
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,36 @@
|
||||||
pub mod monitor;
|
pub mod monitor;
|
||||||
|
|
||||||
|
use dirs;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
use peach_lib::sbot::SbotConfig;
|
||||||
use rocket::response::{Redirect, Responder};
|
use rocket::response::{Redirect, Responder};
|
||||||
use rocket::serde::Serialize;
|
use rocket::serde::Serialize;
|
||||||
use rocket_dyn_templates::Template;
|
use rocket_dyn_templates::Template;
|
||||||
|
|
||||||
use crate::THEME;
|
use crate::{error::PeachWebError, THEME};
|
||||||
|
|
||||||
|
// FILEPATH FUNCTIONS
|
||||||
|
|
||||||
|
// return the path of the ssb-go directory
|
||||||
|
pub fn get_go_ssb_path() -> Result<String, PeachWebError> {
|
||||||
|
let go_ssb_path = match SbotConfig::read() {
|
||||||
|
Ok(conf) => conf.repo,
|
||||||
|
// return the default path if unable to read `config.toml`
|
||||||
|
Err(_) => {
|
||||||
|
// determine the home directory
|
||||||
|
let mut home_path = dirs::home_dir().ok_or_else(|| PeachWebError::HomeDir)?;
|
||||||
|
// add the go-ssb subdirectory
|
||||||
|
home_path.push(".ssb-go");
|
||||||
|
// convert the PathBuf to a String
|
||||||
|
home_path
|
||||||
|
.into_os_string()
|
||||||
|
.into_string()
|
||||||
|
.map_err(|_| PeachWebError::OsString)?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(go_ssb_path)
|
||||||
|
}
|
||||||
|
|
||||||
// THEME FUNCTIONS
|
// THEME FUNCTIONS
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue