Backend REST API changes:
* Fixed weird match with get_online_members + Now using special(smoll) Public Member struct for public member data fetches as. They're size on networks should be pretty small so we can package a ton of them in a single request DOCS changes: - Removing references to unix timestamps in seconds - Removing references to joindate * Exact content-type values now specified
This commit is contained in:
parent
03c41b6833
commit
975acfd606
@ -29,7 +29,7 @@ Example
|
|||||||
> POST /invite/create?id=123&jwt=
|
> POST /invite/create?id=123&jwt=
|
||||||
|
|
||||||
< {
|
< {
|
||||||
< "id": <unix-timestamp>,
|
< "id": <unix-timestamp ms>,
|
||||||
< "uses": 3,
|
< "uses": 3,
|
||||||
< "expires": true
|
< "expires": true
|
||||||
< }
|
< }
|
||||||
@ -59,7 +59,6 @@ Example
|
|||||||
* status: 0
|
* status: 0
|
||||||
* permissions: 51
|
* permissions: 51
|
||||||
* name: Anonymous
|
* name: Anonymous
|
||||||
* joindate: Current Unix time since epoch
|
|
||||||
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
@ -70,7 +69,6 @@ Example
|
|||||||
< "id": 123,
|
< "id": 123,
|
||||||
< "secret": "super secret",
|
< "secret": "super secret",
|
||||||
< "name": "Anonymous",
|
< "name": "Anonymous",
|
||||||
< "joindate": 134256,
|
|
||||||
< "status": 0,
|
< "status": 0,
|
||||||
< "permissions": 51
|
< "permissions": 51
|
||||||
< }
|
< }
|
||||||
|
@ -40,7 +40,6 @@ Example
|
|||||||
< {
|
< {
|
||||||
< "name": "nickname-here",
|
< "name": "nickname-here",
|
||||||
< "id": 123,
|
< "id": 123,
|
||||||
< "joindate": <unix-timestamp>,
|
|
||||||
< "permissions": <64-bit-mask>
|
< "permissions": <64-bit-mask>
|
||||||
< }
|
< }
|
||||||
```
|
```
|
||||||
@ -65,7 +64,6 @@ Example
|
|||||||
< {
|
< {
|
||||||
< "name": "nickname-here",
|
< "name": "nickname-here",
|
||||||
< "id": 0, // always 0
|
< "id": 0, // always 0
|
||||||
< "joindate": <unix-timestamp>,
|
|
||||||
< "status": 1|2
|
< "status": 1|2
|
||||||
< "permissions": <64-bit-mask>
|
< "permissions": <64-bit-mask>
|
||||||
< }
|
< }
|
||||||
|
@ -16,15 +16,15 @@ weight: 15
|
|||||||
* jwt: String
|
* jwt: String
|
||||||
|
|
||||||
* channel_id: u64
|
* channel_id: u64
|
||||||
* type: String
|
* Required headers:
|
||||||
|
Note that for any content that it is required that non-`text/plain` content be base64 encoded
|
||||||
Valid values:
|
* content-type: String
|
||||||
|
* text/plain
|
||||||
* text
|
* image/jpg | image/jpeg
|
||||||
* jpeg
|
* image/png
|
||||||
* png
|
* application/webm
|
||||||
* webm
|
* application/mp4
|
||||||
* mp4
|
* application/mp3
|
||||||
|
|
||||||
* Required body:
|
* Required body:
|
||||||
* Content itself should always go in the body
|
* Content itself should always go in the body
|
||||||
@ -41,9 +41,9 @@ weight: 15
|
|||||||
|
|
||||||
* channel_id: u64
|
* channel_id: u64
|
||||||
* start_time: i64
|
* start_time: i64
|
||||||
* Unix timestamp (seconds)
|
* Unix timestamp (milli-seconds)
|
||||||
* end_time: i64
|
* end_time: i64
|
||||||
* Unix timestamp (seconds)
|
* Unix timestamp (milli-seconds)
|
||||||
|
|
||||||
* limit: Optional<u64>
|
* limit: Optional<u64>
|
||||||
* Maximum = 1000
|
* Maximum = 1000
|
||||||
|
@ -12,7 +12,6 @@ Name | Type
|
|||||||
:------:|:-----:
|
:------:|:-----:
|
||||||
id | `u64`
|
id | `u64`
|
||||||
secret | `String`
|
secret | `String`
|
||||||
joindate| `i64`
|
|
||||||
status | `i32`
|
status | `i32`
|
||||||
permissions| `u64`
|
permissions| `u64`
|
||||||
|
|
||||||
@ -30,7 +29,6 @@ This data is retrieved after a sucessful `/login` hit.
|
|||||||
:-----:|:-----:
|
:-----:|:-----:
|
||||||
id | `u64`
|
id | `u64`
|
||||||
name | `String`
|
name | `String`
|
||||||
joindate| `i64`
|
|
||||||
status | `i32`
|
status | `i32`
|
||||||
permissions| `u64`
|
permissions| `u64`
|
||||||
|
|
||||||
|
@ -82,3 +82,11 @@ pub struct Member {
|
|||||||
pub permissions: UBigInt,
|
pub permissions: UBigInt,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct PublicMember {
|
||||||
|
pub id: UBigInt,
|
||||||
|
pub name: VarChar,
|
||||||
|
pub status: Integer,
|
||||||
|
pub permissions: UBigInt,
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ use mysql_async::error::Error as SqlError;
|
|||||||
|
|
||||||
use crate::{Response, no_conn, sql_err};
|
use crate::{Response, no_conn, sql_err};
|
||||||
use crate::{UBigInt, Integer, VarChar};
|
use crate::{UBigInt, Integer, VarChar};
|
||||||
use crate::Member;
|
use crate::{PublicMember, Member};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -152,3 +152,32 @@ impl Member {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PublicMember {
|
||||||
|
pub async fn get_online(p: &Pool, status: Integer) -> Result<Response<Self>, SqlError> {
|
||||||
|
let valid_status = status == STATUS_ONLINE ||
|
||||||
|
status == STATUS_AWAY ||
|
||||||
|
status == STATUS_OFFLINE ||
|
||||||
|
status == STATUS_DO_NOT_DISTURB;
|
||||||
|
|
||||||
|
if !valid_status {
|
||||||
|
return Ok(Response::RestrictedInput(format!("Invalid status value")));
|
||||||
|
} else {
|
||||||
|
let conn = p.get_conn().await?;
|
||||||
|
let q = "SELECT id, name, permissions FROM members
|
||||||
|
WHERE status = :status LIMIT 1000";
|
||||||
|
|
||||||
|
let result = conn.prep_exec(q, params!{"status" => status}).await?;
|
||||||
|
let (_, data): (_, Vec<PublicMember>) = result.map_and_drop(|row| {
|
||||||
|
let (id, name, permissions): (UBigInt, VarChar, UBigInt) =
|
||||||
|
mysql_async::from_row(row);
|
||||||
|
|
||||||
|
PublicMember { id, name, permissions, status }
|
||||||
|
}).await?;
|
||||||
|
|
||||||
|
return Ok(Response::Set(data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ use mysql_async::Pool;
|
|||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use db::member::STATUS_ONLINE;
|
use db::member::STATUS_ONLINE;
|
||||||
use db::Member;
|
use db::{PublicMember, Member};
|
||||||
use db::Response::*;
|
use db::Response::*;
|
||||||
|
|
||||||
use crate::http::set_json_body;
|
use crate::http::set_json_body;
|
||||||
@ -12,19 +12,22 @@ use crate::qs_param;
|
|||||||
|
|
||||||
|
|
||||||
pub async fn get_online_members(p: &Pool, response: &mut Response<Body>) {
|
pub async fn get_online_members(p: &Pool, response: &mut Response<Body>) {
|
||||||
// TODO: at some point we should provide a way of not querying literally every user in
|
// Lists out the available online members at the time
|
||||||
// existance
|
// Member structs are wildly small so for most cases this query really isn't that expensive
|
||||||
// TODO: loggin at some point or something idklol
|
match PublicMember::get_online(p, STATUS_ONLINE).await {
|
||||||
return match Member::filter(p, STATUS_ONLINE).await {
|
Ok(dbresponse) => {
|
||||||
Set(users) => {
|
match dbresponse {
|
||||||
set_json_body(response, json!(users));
|
Set(users) => set_json_body(response, json!(users)),
|
||||||
|
Other(e) => {
|
||||||
|
eprintln!("{}", e);
|
||||||
|
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
|
},
|
||||||
|
// Unreachable code but required for rustc to be happy
|
||||||
|
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
||||||
|
};
|
||||||
},
|
},
|
||||||
db::Response::Other(e) => {
|
Err(e) => eprintln!("Sql error: {}", e)
|
||||||
eprintln!("{}", e);
|
};
|
||||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
|
||||||
},
|
|
||||||
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_self(p: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
pub async fn get_self(p: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
||||||
@ -117,3 +120,4 @@ mod tests {
|
|||||||
println!("Response: {:?}", resp);
|
println!("Response: {:?}", resp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user