Run cargo fmt.

This commit is contained in:
Paul Makles
2021-01-18 20:26:26 +00:00
parent bd789b6825
commit a1a921bbcb
19 changed files with 141 additions and 142 deletions

View File

@@ -25,13 +25,16 @@ pub async fn req(user: User, target: Ref) -> Result<()> {
"active": false
}
},
None
None,
)
.await
.map_err(|_| Error::DatabaseError { operation: "update_one", with: "channel" })?;
.map_err(|_| Error::DatabaseError {
operation: "update_one",
with: "channel",
})?;
Ok(())
},
_ => unimplemented!()
}
_ => unimplemented!(),
}
}

View File

@@ -2,11 +2,14 @@ use crate::database::*;
use crate::util::result::{Error, Result};
use futures::StreamExt;
use validator::Validate;
use mongodb::{
bson::{doc, from_document},
options::FindOptions,
};
use rocket::request::Form;
use serde::{Serialize, Deserialize};
use rocket_contrib::json::JsonValue;
use mongodb::{bson::{doc, from_document}, options::FindOptions};
use serde::{Deserialize, Serialize};
use validator::Validate;
#[derive(Validate, Serialize, Deserialize, FromForm)]
pub struct Options {
@@ -20,7 +23,8 @@ pub struct Options {
#[get("/<target>/messages?<options..>")]
pub async fn req(user: User, target: Ref, options: Form<Options>) -> Result<JsonValue> {
options.validate()
options
.validate()
.map_err(|error| Error::FailedValidation { error })?;
let target = target.fetch_channel().await?;
@@ -51,14 +55,19 @@ pub async fn req(user: User, target: Ref, options: Form<Options>) -> Result<Json
.build(),
)
.await
.map_err(|_| Error::DatabaseError { operation: "find", with: "messages" })?;
.map_err(|_| Error::DatabaseError {
operation: "find",
with: "messages",
})?;
let mut messages = vec![];
while let Some(result) = cursor.next().await {
if let Ok(doc) = result {
messages.push(
from_document::<Message>(doc)
.map_err(|_| Error::DatabaseError { operation: "from_document", with: "message" })?
from_document::<Message>(doc).map_err(|_| Error::DatabaseError {
operation: "from_document",
with: "message",
})?,
);
}
}

View File

@@ -1,11 +1,11 @@
use crate::database::*;
use crate::util::result::{Error, Result};
use serde::{Serialize, Deserialize};
use rocket_contrib::json::Json;
use validator::Validate;
use mongodb::bson::doc;
use rocket_contrib::json::Json;
use serde::{Deserialize, Serialize};
use ulid::Ulid;
use validator::Validate;
#[derive(Validate, Serialize, Deserialize)]
pub struct Data {
@@ -18,7 +18,8 @@ pub struct Data {
#[post("/<target>/messages", data = "<message>")]
pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<()> {
message.validate()
message
.validate()
.map_err(|error| Error::FailedValidation { error })?;
let target = target.fetch_channel().await?;
@@ -33,11 +34,15 @@ pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<()> {
doc! {
"nonce": &message.nonce
},
None
None,
)
.await
.map_err(|_| Error::DatabaseError { operation: "find_one", with: "message" })?
.is_some() {
.map_err(|_| Error::DatabaseError {
operation: "find_one",
with: "message",
})?
.is_some()
{
Err(Error::AlreadySentMessage)?
}

View File

@@ -1,9 +1,9 @@
use rocket::Route;
mod fetch_channel;
mod delete_channel;
mod message_send;
mod fetch_channel;
mod message_fetch;
mod message_send;
pub fn routes() -> Vec<Route> {
routes![

View File

@@ -31,10 +31,7 @@ pub async fn req(user: User, username: String) -> Result<JsonValue> {
with: "user",
})?;
match get_relationship(
&user,
&target_id,
) {
match get_relationship(&user, &target_id) {
RelationshipStatus::User => return Err(Error::NoEffect),
RelationshipStatus::Friend => return Err(Error::AlreadyFriends),
RelationshipStatus::Outgoing => return Err(Error::AlreadySentRequest),

View File

@@ -1,5 +1,5 @@
use crate::{database::*, notifications::websocket::is_online};
use crate::util::result::{Error, Result};
use crate::{database::*, notifications::websocket::is_online};
use rocket_contrib::json::JsonValue;

View File

@@ -6,38 +6,24 @@ use crate::database::Ref;
#[get("/<target>/avatar")]
pub async fn req(target: Ref) -> Option<NamedFile> {
match target.id.chars().nth(25).unwrap() {
'0' |
'1' |
'2' |
'3' |
'4' |
'5' |
'6' |
'7' => NamedFile::open(Path::new("assets/user_red.png")).await.ok(),
'8' |
'9' |
'A' |
'C' |
'B' |
'D' |
'E' |
'F' => NamedFile::open(Path::new("assets/user_green.png")).await.ok(),
'G' |
'H' |
'J' |
'K' |
'M' |
'N' |
'P' |
'Q' => NamedFile::open(Path::new("assets/user_blue.png")).await.ok(),
'R' |
'S' |
'T' |
'V' |
'W' |
'X' |
'Y' |
'Z' => NamedFile::open(Path::new("assets/user_yellow.png")).await.ok(),
_ => unreachable!()
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' => {
NamedFile::open(Path::new("assets/user_red.png")).await.ok()
}
'8' | '9' | 'A' | 'C' | 'B' | 'D' | 'E' | 'F' => {
NamedFile::open(Path::new("assets/user_green.png"))
.await
.ok()
}
'G' | 'H' | 'J' | 'K' | 'M' | 'N' | 'P' | 'Q' => {
NamedFile::open(Path::new("assets/user_blue.png"))
.await
.ok()
}
'R' | 'S' | 'T' | 'V' | 'W' | 'X' | 'Y' | 'Z' => {
NamedFile::open(Path::new("assets/user_yellow.png"))
.await
.ok()
}
_ => unreachable!(),
}
}