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
This commit is contained in:
shockrah 2021-02-10 23:18:24 -08:00
parent 286a77d9ac
commit 16276c97e0
6 changed files with 17 additions and 17 deletions

View File

@ -17,7 +17,7 @@ use db::{
use crate::qs_param;
pub async fn new_admin(p: &Pool, response: &mut Response<Body>, params: HashMap<&str, &str>) {
pub async fn new_admin(p: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
/*
* @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<Body>, params: HashMap<
}
pub async fn set_permissions(p: &Pool, response: &mut Response<Body>, params: HashMap<&str, &str>) {
pub async fn set_permissions(p: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
// @requiresL: admin level permissions, admins can't touch other admins
let target_uid = qs_param!(params, "id", u64);

View File

@ -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<String, String>)
-> 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::<db::UBigInt>() {
// 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<String, String>)
-> 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<hyper::Body>, params: HashMap<&str, &str>) {
pub async fn login_get_jwt(p: &Pool, response: &mut hyper::Response<hyper::Body>, params: HashMap<String, String>) {
// Login data has already been validated at this point
// Required data such as 'id' and 'secret' are there and validated
use jsonwebtoken::{

View File

@ -30,7 +30,7 @@ pub async fn list_channels(pool: &Pool, response: &mut Response<Body>) {
};
}
pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params: HashMap<&str, &str>) {
pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
/*
* 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<Body>, 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::<i32>() {
Some(kval)
} else {
@ -85,7 +85,7 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
}
}
pub async fn delete_channel(pool: &Pool, response: &mut Response<Body>, params: HashMap<&str, &str>) {
pub async fn delete_channel(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
/*
* Deletes a channel from the database, only after making sure the user has
* the required permissions to do so

View File

@ -91,7 +91,7 @@ async fn use_invite(pool: &Pool, code: Option<BigInt>) -> Option<Member>{
}
}
pub async fn join(pool: &Pool, response: &mut Response<Body>, params: HashMap<&str, &str>) {
pub async fn join(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
/*
* 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<Body>, params: HashMap<&str, &str>) {
pub async fn create(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
/*
* Creates a new invite
* Parameters required asked of the user to provide

View File

@ -52,7 +52,7 @@ async fn route_dispatcher(
meth: &Method,
path: &str,
body: Body,
params: HashMap<&str, &str>) {
params: HashMap<String, String>) {
const GET: &Method = &Method::GET;
const POST: &Method = &Method::POST;
@ -92,7 +92,7 @@ async fn main_responder(request: Request<Body>) -> Result<Response<Body>, hyper:
let method = parts.method;
let path = parts.uri.path();
let qs = parts.uri.query();
let params_opt: Option<HashMap<&str, &str>> = if let Some(query_string) = qs {
let params_opt: Option<HashMap<String, String>> = if let Some(query_string) = qs {
Some(http::parse_query_string(query_string))
} else {
None

View File

@ -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<Body>, params: HashMap<&str, &str>) {
pub async fn get_by_time(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
/*
* 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<Body>, params: Has
}
}
pub async fn send_message(pool: &Pool, response: &mut Response<Body>, body: Body, params: HashMap<&str, &str>) {
pub async fn send_message(pool: &Pool, response: &mut Response<Body>, body: Body, params: HashMap<String, String>) {
/*
* 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: Body
}
}
pub async fn from_id(pool: &Pool, response: &mut Response<Body>, params: HashMap<&str, &str>) {
pub async fn from_id(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
/*
* @start-id: u64
* @limit: optional<u64>