From 73f69cec48a3306ae3f11b1d1d6e68c69e4d4b08 Mon Sep 17 00:00:00 2001 From: shockrah Date: Mon, 13 Jul 2020 20:35:04 -0700 Subject: [PATCH] channels list route passing proper input pass --- server/src/auth.rs | 4 ++-- server/src/channels.rs | 5 ++++- server/src/main.rs | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/server/src/auth.rs b/server/src/auth.rs index 5888049..1f7db1a 100644 --- a/server/src/auth.rs +++ b/server/src/auth.rs @@ -24,8 +24,8 @@ pub async fn wall_entry(path: &str, pool: &Pool, params: &serde_json::Value) -> let key_str = key.as_str(); let conn = pool.get_conn().await?; // (id, name, secret) - type row_type = Option<(UBigInt, VarChar)>; - let db_result: Result<(_, row_type), mysql_async::error::Error> = conn + type RowType = Option<(UBigInt, VarChar)>; + let db_result: Result<(_, RowType), mysql_async::error::Error> = conn .first_exec(r"SELECT id, name FROM members WHERE secret = :secret ", mysql_async::params!{ "secret" => key_str}) .await; diff --git a/server/src/channels.rs b/server/src/channels.rs index ec55b24..d61ad85 100644 --- a/server/src/channels.rs +++ b/server/src/channels.rs @@ -9,6 +9,8 @@ use mysql_async::prelude::{params, Queryable}; use serde_json::Value; +use crate::db_types::{UBigInt, VarChar, Integer}; + pub enum ChannelType { Voice, Text, @@ -104,7 +106,8 @@ impl Channel { async fn get_channels_vec(conn: Conn) -> Result, Error> { let rows_db = conn.prep_exec(r"SELECT * FROM channels", ()).await?; let (_, rows) = rows_db.map_and_drop(|row| { - let (id, name, desc, kind): (u64, String, String, i32) = mysql_async::from_row(row); + let (id, name, desc, kind): (UBigInt, VarChar, VarChar, Integer) = mysql_async::from_row(row); + println!("{}, {}, {}, {}", id, name, desc, kind); Channel::from_tup((id, name, desc, kind)) }).await?; diff --git a/server/src/main.rs b/server/src/main.rs index 475af63..5072576 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -33,6 +33,7 @@ mod db_types; async fn route_dispatcher(pool: &Pool, resp: &mut Response, 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; + println!("{}: {}", meth, path); match (meth, path) { (&Method::GET, routes::INVITE_JOIN) => { if let Err(_) = invites::route_join_invite_code(pool, resp, params).await { @@ -44,7 +45,7 @@ async fn route_dispatcher(pool: &Pool, resp: &mut Response, meth: &Method, *resp.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; } }, - (&Method::GET, routes::CHANNELS_LIST) => channels::list_channels(pool, resp).await, + (&Method::POST, routes::CHANNELS_LIST) => channels::list_channels(pool, resp).await, (&Method::POST, routes::CHANNELS_CREATE) => channels::create_channel(pool, resp, params).await, (&Method::POST, routes::MESSAGE_SEND) => messages::send_message(pool, resp, params).await, @@ -75,12 +76,11 @@ async fn main_responder(request: Request) -> Result, 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 { let pool = Pool::new(&env::var("DATABASE_URL").unwrap()); - // some more information in the response would be great right about here if let Ok(auth_result) = auth::wall_entry(path, &pool, ¶ms).await { // Deal with permissions errors at this point match auth_result {