Run cargo fmt, add root preflight.
This commit is contained in:
@@ -4,9 +4,9 @@ use crate::email;
|
||||
use crate::util::gen_token;
|
||||
|
||||
use bcrypt::{hash, verify};
|
||||
use mongodb::bson::{doc, from_bson, Bson};
|
||||
use chrono::prelude::*;
|
||||
use database::user::User;
|
||||
use mongodb::bson::{doc, from_bson, Bson};
|
||||
use rocket_contrib::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ulid::Ulid;
|
||||
@@ -140,9 +140,7 @@ pub fn verify_email(code: String) -> Response {
|
||||
|
||||
email::send_welcome_email(target.to_string(), user.username);
|
||||
|
||||
Response::Redirect(
|
||||
super::Redirect::to("https://app.revolt.chat"),
|
||||
)
|
||||
Response::Redirect(super::Redirect::to("https://app.revolt.chat"))
|
||||
}
|
||||
} else {
|
||||
Response::BadRequest(json!({ "error": "Invalid code." }))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::Response;
|
||||
use crate::database::{
|
||||
self, get_relationship, get_relationship_internal, message::Message, Permission,
|
||||
PermissionCalculator, Relationship, channel::Channel
|
||||
self, channel::Channel, get_relationship, get_relationship_internal, message::Message,
|
||||
Permission, PermissionCalculator, Relationship,
|
||||
};
|
||||
use crate::guards::auth::UserRef;
|
||||
use crate::notifications::{
|
||||
@@ -10,8 +10,8 @@ use crate::notifications::{
|
||||
};
|
||||
use crate::util::vec_to_set;
|
||||
|
||||
use mongodb::bson::{doc, from_bson, Bson};
|
||||
use chrono::prelude::*;
|
||||
use mongodb::bson::{doc, from_bson, Bson};
|
||||
use mongodb::options::FindOptions;
|
||||
use num_enum::TryFromPrimitive;
|
||||
use rocket::request::Form;
|
||||
@@ -145,15 +145,15 @@ pub fn channel(user: UserRef, target: Channel) -> Option<Response> {
|
||||
"description": 1,
|
||||
"owner": 1,
|
||||
}) {*/
|
||||
Some(Response::Success(json!({
|
||||
"id": target.id,
|
||||
"type": target.channel_type,
|
||||
"last_message": target.last_message,
|
||||
"recipients": target.recipients,
|
||||
"name": target.name,
|
||||
"owner": target.owner,
|
||||
"description": target.description,
|
||||
})))
|
||||
Some(Response::Success(json!({
|
||||
"id": target.id,
|
||||
"type": target.channel_type,
|
||||
"last_message": target.last_message,
|
||||
"recipients": target.recipients,
|
||||
"name": target.name,
|
||||
"owner": target.owner,
|
||||
"description": target.description,
|
||||
})))
|
||||
/*} else {
|
||||
None
|
||||
}*/
|
||||
@@ -163,13 +163,13 @@ pub fn channel(user: UserRef, target: Channel) -> Option<Response> {
|
||||
"name": 1,
|
||||
"description": 1,
|
||||
}) {*/
|
||||
Some(Response::Success(json!({
|
||||
"id": target.id,
|
||||
"type": target.channel_type,
|
||||
"guild": target.guild,
|
||||
"name": target.name,
|
||||
"description": target.description,
|
||||
})))
|
||||
Some(Response::Success(json!({
|
||||
"id": target.id,
|
||||
"type": target.channel_type,
|
||||
"guild": target.guild,
|
||||
"name": target.name,
|
||||
"description": target.description,
|
||||
})))
|
||||
/*} else {
|
||||
None
|
||||
}*/
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use super::channel::ChannelType;
|
||||
use super::Response;
|
||||
use crate::database::{self, channel::Channel, channel::fetch_channel, Permission, PermissionCalculator};
|
||||
use crate::database::guild::{get_invite, get_member, Guild};
|
||||
use crate::database::{
|
||||
self, channel::fetch_channel, channel::Channel, Permission, PermissionCalculator,
|
||||
};
|
||||
use crate::guards::auth::UserRef;
|
||||
use crate::notifications::{
|
||||
self,
|
||||
@@ -106,9 +108,7 @@ pub fn guild(user: UserRef, target: Guild) -> Option<Response> {
|
||||
let mut channels = vec![];
|
||||
for item in results {
|
||||
if let Ok(entry) = item {
|
||||
if let Ok(channel) =
|
||||
from_bson(Bson::Document(entry)) as Result<Channel, _>
|
||||
{
|
||||
if let Ok(channel) = from_bson(Bson::Document(entry)) as Result<Channel, _> {
|
||||
channels.push(json!({
|
||||
"id": channel.id,
|
||||
"name": channel.name,
|
||||
@@ -265,11 +265,7 @@ pub struct CreateChannel {
|
||||
|
||||
/// create a new channel
|
||||
#[post("/<target>/channels", data = "<info>")]
|
||||
pub fn create_channel(
|
||||
user: UserRef,
|
||||
target: Guild,
|
||||
info: Json<CreateChannel>,
|
||||
) -> Option<Response> {
|
||||
pub fn create_channel(user: UserRef, target: Guild, info: Json<CreateChannel>) -> Option<Response> {
|
||||
let (permissions, _) = with_permissions!(user, target);
|
||||
|
||||
if !permissions.get_manage_channels() {
|
||||
@@ -451,8 +447,8 @@ pub fn fetch_invite(user: UserRef, code: String) -> Response {
|
||||
} else {
|
||||
Response::NotFound(json!({ "error": "Channel does not exist." }))
|
||||
}
|
||||
},
|
||||
Err(err) => Response::InternalServerError(json!({ "error": err }))
|
||||
}
|
||||
Err(err) => Response::InternalServerError(json!({ "error": err })),
|
||||
}
|
||||
} else {
|
||||
Response::NotFound(json!({ "error": "Failed to fetch invite or code is invalid." }))
|
||||
|
||||
@@ -63,7 +63,7 @@ impl<'a> rocket::response::Responder<'a> for Permission {
|
||||
|
||||
pub fn mount(rocket: Rocket) -> Rocket {
|
||||
rocket
|
||||
.mount("/", routes![root::root, root::teapot])
|
||||
.mount("/", routes![root::root, root::root_preflight, root::teapot])
|
||||
.mount(
|
||||
"/account",
|
||||
routes![
|
||||
|
||||
@@ -10,6 +10,11 @@ pub fn root() -> Response {
|
||||
}))
|
||||
}
|
||||
|
||||
#[options("/")]
|
||||
pub fn root_preflight() -> Response {
|
||||
Response::Result(super::Status::Ok)
|
||||
}
|
||||
|
||||
/// I'm a teapot.
|
||||
#[delete("/")]
|
||||
pub fn teapot() -> Response {
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::notifications::{
|
||||
use crate::routes::channel;
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use mongodb::options::{Collation, FindOptions, FindOneOptions};
|
||||
use mongodb::options::{Collation, FindOneOptions, FindOptions};
|
||||
use rocket_contrib::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ulid::Ulid;
|
||||
@@ -61,13 +61,8 @@ pub fn query(user: UserRef, query: Json<UserQuery>) -> Response {
|
||||
if let Ok(result) = col.find_one(
|
||||
doc! { "username": query.username.clone() },
|
||||
FindOneOptions::builder()
|
||||
.collation(
|
||||
Collation::builder()
|
||||
.locale("en")
|
||||
.strength(2)
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
.collation(Collation::builder().locale("en").strength(2).build())
|
||||
.build(),
|
||||
) {
|
||||
if let Some(doc) = result {
|
||||
let id = doc.get_str("_id").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user