channels list route passing proper input pass
This commit is contained in:
parent
0a0967d196
commit
73f69cec48
@ -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;
|
||||
|
||||
|
@ -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<Vec<Channel>, 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?;
|
||||
|
||||
|
@ -33,6 +33,7 @@ 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;
|
||||
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<Body>, 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<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 {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user