+ Clearer logging from the json api
* Renamed db helper function to be (debatably) more clear in its intentions That function and everything in that module is quickly become awful however + Adding some notes for later db-lib development
This commit is contained in:
@@ -45,6 +45,7 @@ pub struct Message {
|
||||
pub channel_id: UBigInt
|
||||
}
|
||||
|
||||
// Same EXCEPT for the fact that this has the name tacked on to it
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct UserMessage {
|
||||
pub id: UBigInt,
|
||||
|
||||
@@ -21,7 +21,29 @@ const MAX_MESSAGES: u64 = 1000;
|
||||
|
||||
|
||||
impl Message {
|
||||
fn send_verify_error(res: Result<QueryResult<Conn, BinaryProtocol>, SqlError> ) -> Result<Response<Self>, SqlError> {
|
||||
fn new(id: u64, time: i64, content: &str, content_type: &str, uid: u64, cid: u64) -> Self {
|
||||
// Here for convenience pretty straight forward, copying at the last second
|
||||
Message {
|
||||
id,
|
||||
time,
|
||||
content: content.into(),
|
||||
content_type: content_type.into(),
|
||||
author_id: uid,
|
||||
channel_id: cid
|
||||
}
|
||||
}
|
||||
|
||||
fn message_passthrough_no_err(res: Result<QueryResult<Conn, BinaryProtocol>, SqlError>, passthrough: Self)
|
||||
-> Result<Response<Self>, SqlError> {
|
||||
/* You shouldn't have cum here.webm
|
||||
* Basically sending messages with mysql is kinda painful so we
|
||||
* do some special error checking by hand to see if
|
||||
* a message was sent to an existing channel.
|
||||
* The whole point of this is to avoid sending back a 500 to user clients
|
||||
* which may cause confusing error handling in userland. This means we have
|
||||
* confusing error handling on the server side but one of the parties has to
|
||||
* do this stupid check so fuck it at least its mostly pointers anyway
|
||||
*/
|
||||
if let Err(e) = res {
|
||||
return match e {
|
||||
SqlError::Server(err) => {
|
||||
@@ -38,7 +60,7 @@ impl Message {
|
||||
}
|
||||
// all good response
|
||||
else {
|
||||
return Ok(Response::Empty);
|
||||
return Ok(Response::Row(passthrough));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,10 +92,18 @@ impl Message {
|
||||
"author" => uid,
|
||||
"channel" => cid
|
||||
}).await;
|
||||
Self::send_verify_error(res)
|
||||
let msg = Message::new(id, now, content, content_type, uid, cid);
|
||||
Self::message_passthrough_no_err(res, msg)
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
/*
|
||||
* Amazing hardcoded limit on binary content_length
|
||||
* TODO: make this not hardcoded
|
||||
* This really should be configurable by someone somewhere
|
||||
* The best way of doing this honestly it probably through some kind of lazy static
|
||||
* we can set an env var from the cli frontend for that lz_static to read
|
||||
*/
|
||||
if content.len() > 10_000_000 {
|
||||
Ok(Response::RestrictedInput("Large data not allowed".into()))
|
||||
} else {
|
||||
@@ -95,7 +125,8 @@ impl Message {
|
||||
"author" => uid,
|
||||
"channel" => cid
|
||||
}).await;
|
||||
if let Ok(ret) = Self::send_verify_error(res) {
|
||||
let msg = Message::new(id, now, content, content_type, uid, cid);
|
||||
if let Ok(ret) = Self::message_passthrough_no_err(res, msg) {
|
||||
// now save the data to disk
|
||||
match fs::File::create(content_ref).await {
|
||||
Ok(mut file) => {
|
||||
|
||||
Reference in New Issue
Block a user