Compare commits
3 Commits
b54b4a6cd7
...
2cbcd06c1a
Author | SHA1 | Date |
---|---|---|
blek | 2cbcd06c1a | |
blek | bea8e707a2 | |
blek | a6b669a007 |
|
@ -8,4 +8,5 @@ REDIS_PREFIX=bfile-
|
||||||
|
|
||||||
USERCONTENT_DIR=/opt/user_uploads
|
USERCONTENT_DIR=/opt/user_uploads
|
||||||
|
|
||||||
INSTANCE_URL=http://localhost
|
INSTANCE_URL=http://localhost
|
||||||
|
UPLOADS_PATH=file # can be only one alphanumeric word
|
||||||
|
|
|
@ -19,7 +19,8 @@ pub struct Env {
|
||||||
pub listen: SocketAddr,
|
pub listen: SocketAddr,
|
||||||
pub redis: Redis,
|
pub redis: Redis,
|
||||||
pub filedir: String,
|
pub filedir: String,
|
||||||
pub instanceurl: String
|
pub instanceurl: String,
|
||||||
|
pub uploadspath: String
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_var<T: Into<String>, O: From<String>>(name: T) -> Result<O, String> {
|
fn get_var<T: Into<String>, O: From<String>>(name: T) -> Result<O, String> {
|
||||||
|
@ -53,7 +54,8 @@ pub fn loadenv() -> Result<Env, Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
spath
|
spath
|
||||||
},
|
},
|
||||||
instanceurl: get_var("INSTANCE_URL")?
|
instanceurl: get_var("INSTANCE_URL")?,
|
||||||
|
uploadspath: get_var("UPLOADS_PATH")?
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
use warp::{reply::Reply, reject::Rejection, Filter};
|
||||||
|
|
||||||
|
use super::state::SharedState;
|
||||||
|
|
||||||
|
mod get_all;
|
||||||
|
|
||||||
|
pub fn api_root() -> Box<dyn Reply> {
|
||||||
|
Box::new(warp::reply::json(&String::from("{ error: \"You have called the API root of a blek! File instance. Refer to https://git.blek.codes/blek/bfile.git for documentation.\" }")))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_routes(state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
||||||
|
let api = warp::path!("api");
|
||||||
|
let api = api
|
||||||
|
.and(warp::path::end())
|
||||||
|
.map(api_root)
|
||||||
|
.or(get_all::get_all_f(state));
|
||||||
|
api
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
use warp::{reply::Reply, reject::Rejection, Filter};
|
||||||
|
|
||||||
|
use crate::web::state::SharedState;
|
||||||
|
|
||||||
|
pub async fn get_all(_state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
|
||||||
|
Ok(Box::new(warp::reply::json(&String::from("aaaaa"))))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_all_f(state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
|
||||||
|
warp::path!("get_all")
|
||||||
|
.map(move || state.clone())
|
||||||
|
.and_then(get_all)
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ mod pages;
|
||||||
mod forms;
|
mod forms;
|
||||||
mod state;
|
mod state;
|
||||||
mod rejection;
|
mod rejection;
|
||||||
|
mod api;
|
||||||
|
|
||||||
use state::SharedState;
|
use state::SharedState;
|
||||||
|
|
||||||
|
@ -20,7 +21,8 @@ pub fn routes(state: SharedState) -> impl Filter<Extract = impl Reply, Error = R
|
||||||
let staticpath = staticpath.to_str().unwrap().to_string() + "/static";
|
let staticpath = staticpath.to_str().unwrap().to_string() + "/static";
|
||||||
|
|
||||||
pages::get_routes(state.clone())
|
pages::get_routes(state.clone())
|
||||||
.or(forms::get_routes(state))
|
.or(forms::get_routes(state.clone()))
|
||||||
|
.or(api::get_routes(state))
|
||||||
.or(warp::fs::dir(staticpath.to_string()))
|
.or(warp::fs::dir(staticpath.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
pages.rs - All the HTML pages
|
pages.rs - All the HTML pages
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{collections::HashMap, convert::Infallible};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use warp::{reply::{Reply, Html}, Filter, reject::{Rejection, Reject}};
|
use warp::{reply::{Reply, Html}, Filter, reject::Rejection};
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
use crate::env::Env;
|
use crate::env::Env;
|
||||||
|
|
Loading…
Reference in New Issue