removing unused enum members

This commit is contained in:
shockrah 2020-07-13 19:42:13 -07:00
parent d013afe054
commit 1810e5ebc8
2 changed files with 21 additions and 6 deletions

View File

@ -1,13 +1,12 @@
use mysql_async::Pool;
use mysql_async::prelude::{params, Queryable};
use crate::db_types::{UBigInt, Integer, VarChar};
use crate::db_types::{UBigInt, VarChar};
use crate::routes;
pub enum AuthReason {
Good, //passed regular check
OpenAuth, // route does not require auth
LimitPassed,
NoKey,
}

View File

@ -26,13 +26,13 @@ mod invites;
mod channels;
mod members;
mod messages;
mod badges;
mod http_params;
mod perms;
mod db_types;
async fn route_dispatcher(pool: &Pool, resp: &mut Response<Body>, meth: &Method, path: &str, params: serde_json::Value) {
// At some point we should have some way of hiding this obnoxious complexity
use routes::resolve_dynamic_route;
match (meth, path) {
(&Method::GET, routes::INVITE_JOIN) => {
if let Err(_) = invites::route_join_invite_code(pool, resp, params).await {
@ -48,7 +48,23 @@ async fn route_dispatcher(pool: &Pool, resp: &mut Response<Body>, meth: &Method,
(&Method::POST, routes::CHANNELS_CREATE) => channels::create_channel(pool, resp, params).await,
(&Method::POST, routes::MESSAGE_SEND) => messages::send_message(pool, resp, params).await,
_ => *resp.status_mut() = StatusCode::NOT_FOUND
_ => {
// We attempt dynamic routes as fallback for a few reasons
// 1. theres less of these than there are the static routes
// 2. because of the above and that this is wholly more expensive than static routse
// we can justify putting in tons of branches since we're likely to:
// far jump here, lose cache, and still be be network bound
// Computatinoal bounds are really of no concern with this api since
// we're not doing any heavy calculations at any point
if let Some(route) = resolve_dynamic_route(path) {
*resp.status_mut() = StatusCode::OK;
println!("Static part: {}", route.base);
println!("Dynamic part: {}", route.dynamic);
}
else {
*resp.status_mut() = StatusCode::NOT_FOUND
}
}
}
}
@ -59,6 +75,7 @@ async fn main_responder(request: Request<Body>) -> Result<Response<Body>, hyper:
let (parts, mut body) = request.into_parts();
let method = parts.method;
let path = parts.uri.path();
// TODO: allow this to fail on occasion, like for the invite system
let params_res = http_params::parse_params(&mut body).await;
if let Ok(params) = params_res {
@ -68,7 +85,6 @@ async fn main_responder(request: Request<Body>) -> Result<Response<Body>, hyper:
// Deal with permissions errors at this point
match auth_result {
OpenAuth | Good => route_dispatcher(&pool, &mut response, &method, path, params).await,
LimitPassed => *response.status_mut() = StatusCode::UNAUTHORIZED,
NoKey => *response.status_mut() = StatusCode::UNAUTHORIZED,
}
}