Fix room ID type
This commit is contained in:
parent
58366100a5
commit
b36a80dcc2
10
src/rpc.rs
10
src/rpc.rs
|
@ -30,7 +30,7 @@ pub async fn handle_rpc_call(rpc_call: RpcCall) -> Result<Response, Rejection> {
|
|||
return Err(warp::reject::custom(Error::InvalidRpcCall))
|
||||
}
|
||||
};
|
||||
let pool = storage::pool_by_room_id(room_id)?;
|
||||
let pool = storage::pool_by_room_id(&room_id)?;
|
||||
// Check that the endpoint is a valid URI
|
||||
let uri = match rpc_call.endpoint.parse::<http::Uri>() {
|
||||
Ok(uri) => uri,
|
||||
|
@ -223,11 +223,7 @@ fn get_auth_token(rpc_call: &RpcCall) -> Option<String> {
|
|||
return rpc_call.headers.get("Authorization").map(|s| s.to_string());
|
||||
}
|
||||
|
||||
fn get_room_id(rpc_call: &RpcCall) -> Option<isize> {
|
||||
fn get_room_id(rpc_call: &RpcCall) -> Option<String> {
|
||||
if rpc_call.headers.is_empty() { return None; }
|
||||
let header = rpc_call.headers.get("Room")?;
|
||||
match header.parse() {
|
||||
Ok(room_id) => return Some(room_id),
|
||||
Err(_) => return None
|
||||
};
|
||||
return rpc_call.headers.get("Room").map(|s| s.to_string());
|
||||
}
|
|
@ -57,13 +57,13 @@ lazy_static::lazy_static! {
|
|||
static ref POOLS: Mutex<HashMap<String, DatabaseConnectionPool>> = Mutex::new(HashMap::new());
|
||||
}
|
||||
|
||||
pub fn pool_by_room_id(room_id: isize) -> Result<DatabaseConnectionPool, Error> {
|
||||
pub fn pool_by_room_id(room_id: &str) -> Result<DatabaseConnectionPool, Error> {
|
||||
// Get a database connection
|
||||
let conn = MAIN_POOL.get().map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
// Query the database
|
||||
let raw_query = format!("SELECT name FROM {} WHERE id = (?1)", MAIN_TABLE);
|
||||
let mut query = conn.prepare(&raw_query).map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
let rows = match query.query_map(params![ &room_id ], |row| {
|
||||
let rows = match query.query_map(params![ room_id ], |row| {
|
||||
Ok(row.get(0)?)
|
||||
}) {
|
||||
Ok(rows) => rows,
|
||||
|
|
Loading…
Reference in New Issue