Add documentation & fix indentation
This commit is contained in:
parent
24d10de0e3
commit
cf62f82735
|
@ -167,7 +167,8 @@ pub async fn store_file(
|
|||
}
|
||||
};
|
||||
// Write to file
|
||||
// room_id is guaranteed to be present at this point
|
||||
// room_id is guaranteed to be present at this point because we checked the auth
|
||||
// token (the auth token will have been rejected if room_id is missing).
|
||||
let room_id = room_id.unwrap();
|
||||
match std::fs::create_dir_all(format!("files/{}_files", &room_id)) {
|
||||
Ok(_) => (),
|
||||
|
@ -218,7 +219,8 @@ pub async fn get_file(
|
|||
}
|
||||
// Try to read the file
|
||||
let mut bytes = vec![];
|
||||
// room_id is guaranteed to be present at this point
|
||||
// room_id is guaranteed to be present at this point because we checked the auth
|
||||
// token (the auth token will have been rejected if room_id is missing).
|
||||
let raw_path = format!("files/{}_files/{}", room_id.unwrap(), id);
|
||||
let path = Path::new(&raw_path);
|
||||
let mut file = match File::open(path).await {
|
||||
|
|
|
@ -12,21 +12,16 @@ use log4rs::{
|
|||
pub fn init(log_file: Option<String>) {
|
||||
let console_level = LevelFilter::Debug;
|
||||
let file_level = LevelFilter::Info;
|
||||
|
||||
let stdout_appender = {
|
||||
let encoder = Box::new(PatternEncoder::new("{h({l})} {d} - {m}{n}"));
|
||||
let stdout = ConsoleAppender::builder().encoder(encoder).build();
|
||||
let filter = Box::new(ThresholdFilter::new(console_level));
|
||||
Appender::builder().filter(filter).build("stdout", Box::new(stdout))
|
||||
};
|
||||
|
||||
let mut root = Root::builder().appender("stdout");
|
||||
|
||||
// Increase SOGS logging level to debug
|
||||
let sogs = Logger::builder().build("session_open_group_server", LevelFilter::Debug);
|
||||
|
||||
let mut config_builder = log4rs::Config::builder().logger(sogs).appender(stdout_appender);
|
||||
|
||||
if let Some(log_file) = log_file {
|
||||
// Rotate log files every ~50MB keeping 1 archived
|
||||
let size_trigger = compound::trigger::size::SizeTrigger::new(50_000_000);
|
||||
|
@ -34,22 +29,16 @@ pub fn init(log_file: Option<String>) {
|
|||
.build(&format!("{}-archive.{{}}", &log_file), 1)
|
||||
.unwrap();
|
||||
let roll_policy = compound::CompoundPolicy::new(Box::new(size_trigger), Box::new(roller));
|
||||
|
||||
// Print to the file at info level
|
||||
let file_appender =
|
||||
RollingFileAppender::builder().build(&log_file, Box::new(roll_policy)).unwrap();
|
||||
let filter = Box::new(ThresholdFilter::new(file_level));
|
||||
let file_appender =
|
||||
Appender::builder().filter(filter).build("file", Box::new(file_appender));
|
||||
|
||||
config_builder = config_builder.appender(file_appender);
|
||||
|
||||
root = root.appender("file");
|
||||
}
|
||||
|
||||
let root = root.build(file_level);
|
||||
|
||||
let config = config_builder.build(root).unwrap();
|
||||
|
||||
let _ = log4rs::init_config(config).expect("Couldn't initialize log configuration.");
|
||||
}
|
||||
|
|
|
@ -118,9 +118,8 @@ async fn handle_get_request(
|
|||
.await
|
||||
.map(|json| warp::reply::json(&json).into_response());
|
||||
}
|
||||
// Check that the auth token is present
|
||||
// Handle routes that require authorization
|
||||
let auth_token = auth_token.ok_or(warp::reject::custom(Error::NoAuthToken))?;
|
||||
// Switch on the path
|
||||
match path {
|
||||
"messages" => {
|
||||
reject_if_file_server_mode(path)?;
|
||||
|
@ -175,6 +174,8 @@ async fn handle_post_request(
|
|||
room_id: Option<String>, rpc_call: RpcCall, path: &str, auth_token: Option<String>,
|
||||
) -> Result<Response, Rejection> {
|
||||
// Handle routes that don't require authorization first
|
||||
// The compact poll endpoint expects the auth token to be in the request body; not
|
||||
// in the headers.
|
||||
if path == "compact_poll" {
|
||||
reject_if_file_server_mode(path)?;
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
@ -209,9 +210,8 @@ async fn handle_post_request(
|
|||
};
|
||||
return handlers::store_file(room_id, &json.file, auth_token, &pool).await;
|
||||
}
|
||||
// Check that the auth token is present
|
||||
// Handle routes that require authorization
|
||||
let auth_token = auth_token.ok_or(warp::reject::custom(Error::NoAuthToken))?;
|
||||
// Switch on the path
|
||||
if path.starts_with("rooms") {
|
||||
reject_if_file_server_mode(path)?;
|
||||
let components: Vec<&str> = path.split("/").collect(); // Split on subsequent slashes
|
||||
|
|
Loading…
Reference in New Issue