From 16276c97e08fe7e8c50161f37dc58f700f130bda Mon Sep 17 00:00:00 2001 From: shockrah Date: Wed, 10 Feb 2021 23:18:24 -0800 Subject: [PATCH] Moving option parameters to the query string Large payloads will remain the body as those are typically required for post endpoints such as /message/send --- json-api/src/admin.rs | 4 ++-- json-api/src/auth.rs | 10 +++++----- json-api/src/channels.rs | 6 +++--- json-api/src/invites.rs | 4 ++-- json-api/src/main.rs | 4 ++-- json-api/src/messages.rs | 6 +++--- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/json-api/src/admin.rs b/json-api/src/admin.rs index 59b0459..1d3bc1b 100644 --- a/json-api/src/admin.rs +++ b/json-api/src/admin.rs @@ -17,7 +17,7 @@ use db::{ use crate::qs_param; -pub async fn new_admin(p: &Pool, response: &mut Response, params: HashMap<&str, &str>) { +pub async fn new_admin(p: &Pool, response: &mut Response, params: HashMap) { /* * @requires: owner level permission as regular admins can have conflict of interests * @user param: "target-id": Number @@ -37,7 +37,7 @@ pub async fn new_admin(p: &Pool, response: &mut Response, params: HashMap< } -pub async fn set_permissions(p: &Pool, response: &mut Response, params: HashMap<&str, &str>) { +pub async fn set_permissions(p: &Pool, response: &mut Response, params: HashMap) { // @requiresL: admin level permissions, admins can't touch other admins let target_uid = qs_param!(params, "id", u64); diff --git a/json-api/src/auth.rs b/json-api/src/auth.rs index 7171310..cdf10f4 100644 --- a/json-api/src/auth.rs +++ b/json-api/src/auth.rs @@ -129,13 +129,13 @@ async fn valid_jwt(p: &Pool, token: &str) -> AuthReason { } } -fn login_params_from_qs<'value>(params: &HashMap<&str, &'value str>) - -> Option<(db::UBigInt, &'value str)> { +fn login_params_from_qs(params: &HashMap) + -> Option<(db::UBigInt, &str)> { return match (params.get("id"), params.get("secret")) { // partially accpept if both keys are present (Some(id), Some(secret)) => { - let id_s: String = String::from(*id); + let id_s: String = String::from(id); match id_s.parse::() { // full accpet if id can parse + secret is present @@ -152,7 +152,7 @@ fn login_params_from_qs<'value>(params: &HashMap<&str, &'value str>) pub async fn wall_entry<'path, 'pool, 'params>( path: &'path str, pool: &'pool Pool, - params: &'params HashMap<&str, &str>) + params: &'params HashMap) -> AuthReason { // Dont need to auth if it's not required @@ -192,7 +192,7 @@ pub async fn wall_entry<'path, 'pool, 'params>( return AuthReason::NoKey; } -pub async fn login_get_jwt(p: &Pool, response: &mut hyper::Response, params: HashMap<&str, &str>) { +pub async fn login_get_jwt(p: &Pool, response: &mut hyper::Response, params: HashMap) { // Login data has already been validated at this point // Required data such as 'id' and 'secret' are there and validated use jsonwebtoken::{ diff --git a/json-api/src/channels.rs b/json-api/src/channels.rs index 9bb4607..6594e54 100644 --- a/json-api/src/channels.rs +++ b/json-api/src/channels.rs @@ -30,7 +30,7 @@ pub async fn list_channels(pool: &Pool, response: &mut Response) { }; } -pub async fn create_channel(pool: &Pool, response: &mut Response, params: HashMap<&str, &str>) { +pub async fn create_channel(pool: &Pool, response: &mut Response, params: HashMap) { /* * Create a channel base on a few parameters that may or may not be there * @responds with the data of the newly created channel @@ -48,7 +48,7 @@ pub async fn create_channel(pool: &Pool, response: &mut Response, params: let kind = match params.get("kind") { // 1 for vc 2 for text Some(value) => { - let v = *value; + let v = value; if let Ok(kval) = v.to_string().parse::() { Some(kval) } else { @@ -85,7 +85,7 @@ pub async fn create_channel(pool: &Pool, response: &mut Response, params: } } -pub async fn delete_channel(pool: &Pool, response: &mut Response, params: HashMap<&str, &str>) { +pub async fn delete_channel(pool: &Pool, response: &mut Response, params: HashMap) { /* * Deletes a channel from the database, only after making sure the user has * the required permissions to do so diff --git a/json-api/src/invites.rs b/json-api/src/invites.rs index d7f6a05..65d7e93 100644 --- a/json-api/src/invites.rs +++ b/json-api/src/invites.rs @@ -91,7 +91,7 @@ async fn use_invite(pool: &Pool, code: Option) -> Option{ } } -pub async fn join(pool: &Pool, response: &mut Response, params: HashMap<&str, &str>) { +pub async fn join(pool: &Pool, response: &mut Response, params: HashMap) { /* * Main dispatcher for dealing with an attempted join via a given invide code * @@ -130,7 +130,7 @@ async fn allowed_perm_invite(pool: &Pool, uid: u64) -> bool { _ => false }; } -pub async fn create(pool: &Pool, response: &mut Response, params: HashMap<&str, &str>) { +pub async fn create(pool: &Pool, response: &mut Response, params: HashMap) { /* * Creates a new invite * Parameters required asked of the user to provide diff --git a/json-api/src/main.rs b/json-api/src/main.rs index 634790f..cb3482b 100644 --- a/json-api/src/main.rs +++ b/json-api/src/main.rs @@ -52,7 +52,7 @@ async fn route_dispatcher( meth: &Method, path: &str, body: Body, - params: HashMap<&str, &str>) { + params: HashMap) { const GET: &Method = &Method::GET; const POST: &Method = &Method::POST; @@ -92,7 +92,7 @@ async fn main_responder(request: Request) -> Result, hyper: let method = parts.method; let path = parts.uri.path(); let qs = parts.uri.query(); - let params_opt: Option> = if let Some(query_string) = qs { + let params_opt: Option> = if let Some(query_string) = qs { Some(http::parse_query_string(query_string)) } else { None diff --git a/json-api/src/messages.rs b/json-api/src/messages.rs index eeb696a..58bd351 100644 --- a/json-api/src/messages.rs +++ b/json-api/src/messages.rs @@ -10,7 +10,7 @@ use crate::perms; use crate::qs_param; use db::messages::Message; -pub async fn get_by_time(pool: &Pool, response: &mut Response, params: HashMap<&str, &str>) { +pub async fn get_by_time(pool: &Pool, response: &mut Response, params: HashMap) { /* * Has a ton of required parameters just be warned * @channel: channel id we're looking at @@ -56,7 +56,7 @@ pub async fn get_by_time(pool: &Pool, response: &mut Response, params: Has } } -pub async fn send_message(pool: &Pool, response: &mut Response, body: Body, params: HashMap<&str, &str>) { +pub async fn send_message(pool: &Pool, response: &mut Response, body: Body, params: HashMap) { /* * Message content is sent in the message body * @channel_id: channel id that we're going to send a message to @@ -99,7 +99,7 @@ pub async fn send_message(pool: &Pool, response: &mut Response, body: Body } } -pub async fn from_id(pool: &Pool, response: &mut Response, params: HashMap<&str, &str>) { +pub async fn from_id(pool: &Pool, response: &mut Response, params: HashMap) { /* * @start-id: u64 * @limit: optional