Start moving to Rocket 0.5.0
This commit is contained in:
993
Cargo.lock
generated
993
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
12
Cargo.toml
@@ -32,17 +32,17 @@ serde_json = "1.0.57"
|
|||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
urlencoding = "1.1.1"
|
urlencoding = "1.1.1"
|
||||||
many-to-many = "0.1.2"
|
many-to-many = "0.1.2"
|
||||||
lettre = "0.10.0-alpha.1"
|
lettre = "0.10.0-alpha.4"
|
||||||
|
rocket-governor = "0.0.1-rc.9"
|
||||||
reqwest = { version = "0.10.8", features = ["json"] }
|
reqwest = { version = "0.10.8", features = ["json"] }
|
||||||
serde = { version = "1.0.115", features = ["derive"] }
|
serde = { version = "1.0.115", features = ["derive"] }
|
||||||
validator = { version = "0.11", features = ["derive"] }
|
validator = { version = "0.11", features = ["derive"] }
|
||||||
ctrlc = { version = "3.0", features = ["termination"] }
|
ctrlc = { version = "3.0", features = ["termination"] }
|
||||||
hive_pubsub = { version = "0.4.4", features = ["mongo"] }
|
|
||||||
async-std = { version = "1.8.0", features = ["tokio02", "attributes"] }
|
async-std = { version = "1.8.0", features = ["tokio02", "attributes"] }
|
||||||
async-tungstenite = { version = "0.10.0", features = ["async-std-runtime"] }
|
async-tungstenite = { version = "0.10.0", features = ["async-std-runtime"] }
|
||||||
|
rocket = { version = "0.5.0-rc.1", default-features = false, features = ["json"] }
|
||||||
rocket_cors = { git = "https://github.com/insertish/rocket_cors", branch = "master" }
|
rocket_cors = { git = "https://github.com/insertish/rocket_cors", branch = "master" }
|
||||||
mongodb = { version = "1.1.1", features = ["tokio-runtime"], default-features = false }
|
mongodb = { version = "1.2.2", features = ["tokio-runtime"], default-features = false }
|
||||||
rauth = { git = "https://gitlab.insrt.uk/insert/rauth", rev = "00d3c3dff51cf3242a7d4adda4c5184c97fa2a03" }
|
rauth = { git = "https://gitlab.insrt.uk/insert/rauth", rev = "51546e5a1ba0dfe3ec3bd0b060fa51fc3102c96f" }
|
||||||
rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket", rev = "031948c1daaa146128d8a435be116476f2adde00" }
|
|
||||||
rocket_prometheus = { git = "https://github.com/insertish/rocket_prometheus", rev = "3d825aedb42793246c306a81fe67c5b187948983" }
|
rocket_prometheus = { git = "https://github.com/insertish/rocket_prometheus", rev = "3d825aedb42793246c306a81fe67c5b187948983" }
|
||||||
rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "031948c1daaa146128d8a435be116476f2adde00", default-features = false }
|
hive_pubsub = { git = "https://gitlab.insrt.uk/insert/hive", rev = "a89826df2b30166220e68a6ed01a58b751456604", features = ["mongo"] }
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use mongodb::{
|
|||||||
bson::{doc, to_document, Document},
|
bson::{doc, to_document, Document},
|
||||||
options::FindOptions,
|
options::FindOptions,
|
||||||
};
|
};
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
@@ -139,7 +139,7 @@ impl Channel {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn publish_update(&self, data: JsonValue) -> Result<()> {
|
pub async fn publish_update(&self, data: Value) -> Result<()> {
|
||||||
let id = self.id().to_string();
|
let id = self.id().to_string();
|
||||||
ClientboundNotification::ChannelUpdate {
|
ClientboundNotification::ChannelUpdate {
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use mongodb::{
|
|||||||
bson::{doc, to_bson, DateTime},
|
bson::{doc, to_bson, DateTime},
|
||||||
options::FindOptions,
|
options::FindOptions,
|
||||||
};
|
};
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
use web_push::{
|
use web_push::{
|
||||||
@@ -323,7 +323,7 @@ impl Message {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn publish_update(self, data: JsonValue) -> Result<()> {
|
pub async fn publish_update(self, data: Value) -> Result<()> {
|
||||||
let channel = self.channel.clone();
|
let channel = self.channel.clone();
|
||||||
ClientboundNotification::MessageUpdate {
|
ClientboundNotification::MessageUpdate {
|
||||||
id: self.id.clone(),
|
id: self.id.clone(),
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use mongodb::bson::{Bson, doc};
|
|||||||
use mongodb::bson::from_document;
|
use mongodb::bson::from_document;
|
||||||
use mongodb::bson::to_document;
|
use mongodb::bson::to_document;
|
||||||
use mongodb::bson::Document;
|
use mongodb::bson::Document;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
@@ -120,7 +120,7 @@ impl Server {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn publish_update(&self, data: JsonValue) -> Result<()> {
|
pub async fn publish_update(&self, data: Value) -> Result<()> {
|
||||||
ClientboundNotification::ServerUpdate {
|
ClientboundNotification::ServerUpdate {
|
||||||
id: self.id.clone(),
|
id: self.id.clone(),
|
||||||
data,
|
data,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::database::*;
|
|||||||
use mongodb::bson::{doc, from_document};
|
use mongodb::bson::{doc, from_document};
|
||||||
use rauth::auth::Session;
|
use rauth::auth::Session;
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
|
use rocket::outcome::try_outcome;
|
||||||
use rocket::request::{self, FromRequest, Outcome, Request};
|
use rocket::request::{self, FromRequest, Outcome, Request};
|
||||||
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket_contrib;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate impl_ops;
|
extern crate impl_ops;
|
||||||
@@ -30,6 +28,7 @@ use rauth::{
|
|||||||
};
|
};
|
||||||
use rocket_cors::AllowedOrigins;
|
use rocket_cors::AllowedOrigins;
|
||||||
use rocket_prometheus::PrometheusMetrics;
|
use rocket_prometheus::PrometheusMetrics;
|
||||||
|
use rocket::catchers;
|
||||||
use util::variables::{
|
use util::variables::{
|
||||||
APP_URL, HCAPTCHA_KEY, INVITE_ONLY, PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD,
|
APP_URL, HCAPTCHA_KEY, INVITE_ONLY, PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD,
|
||||||
SMTP_USERNAME, USE_EMAIL, USE_HCAPTCHA, USE_PROMETHEUS,
|
SMTP_USERNAME, USE_EMAIL, USE_HCAPTCHA, USE_PROMETHEUS,
|
||||||
@@ -140,6 +139,7 @@ Reset your password here: {{url}}",
|
|||||||
.manage(auth)
|
.manage(auth)
|
||||||
.manage(cors.clone())
|
.manage(cors.clone())
|
||||||
.attach(cors)
|
.attach(cors)
|
||||||
|
.register("/", catchers![rocket_governor::rocket_governor_catcher])
|
||||||
.launch()
|
.launch()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use hive_pubsub::PubSub;
|
use hive_pubsub::PubSub;
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rauth::auth::Session;
|
use rauth::auth::Session;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::hive::{get_hive, subscribe_if_exists};
|
use super::hive::{get_hive, subscribe_if_exists};
|
||||||
@@ -73,7 +73,7 @@ pub enum ClientboundNotification {
|
|||||||
MessageUpdate {
|
MessageUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
channel: String,
|
channel: String,
|
||||||
data: JsonValue,
|
data: Value,
|
||||||
},
|
},
|
||||||
MessageDelete {
|
MessageDelete {
|
||||||
id: String,
|
id: String,
|
||||||
@@ -83,7 +83,7 @@ pub enum ClientboundNotification {
|
|||||||
ChannelCreate(Channel),
|
ChannelCreate(Channel),
|
||||||
ChannelUpdate {
|
ChannelUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
data: JsonValue,
|
data: Value,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
clear: Option<RemoveChannelField>,
|
clear: Option<RemoveChannelField>,
|
||||||
},
|
},
|
||||||
@@ -114,7 +114,7 @@ pub enum ClientboundNotification {
|
|||||||
|
|
||||||
ServerUpdate {
|
ServerUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
data: JsonValue,
|
data: Value,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
clear: Option<RemoveServerField>,
|
clear: Option<RemoveServerField>,
|
||||||
},
|
},
|
||||||
@@ -123,7 +123,7 @@ pub enum ClientboundNotification {
|
|||||||
},
|
},
|
||||||
ServerMemberUpdate {
|
ServerMemberUpdate {
|
||||||
id: MemberCompositeKey,
|
id: MemberCompositeKey,
|
||||||
data: JsonValue,
|
data: Value,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
clear: Option<RemoveMemberField>,
|
clear: Option<RemoveMemberField>,
|
||||||
},
|
},
|
||||||
@@ -138,7 +138,7 @@ pub enum ClientboundNotification {
|
|||||||
ServerRoleUpdate {
|
ServerRoleUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
role_id: String,
|
role_id: String,
|
||||||
data: JsonValue,
|
data: Value,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
clear: Option<RemoveRoleField>
|
clear: Option<RemoveRoleField>
|
||||||
},
|
},
|
||||||
@@ -149,7 +149,7 @@ pub enum ClientboundNotification {
|
|||||||
|
|
||||||
UserUpdate {
|
UserUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
data: JsonValue,
|
data: Value,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
clear: Option<RemoveUserField>,
|
clear: Option<RemoveUserField>,
|
||||||
},
|
},
|
||||||
@@ -160,7 +160,7 @@ pub enum ClientboundNotification {
|
|||||||
},
|
},
|
||||||
UserSettingsUpdate {
|
UserSettingsUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
update: JsonValue,
|
update: Value,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
|||||||
use crate::{database::*, notifications::events::RemoveChannelField};
|
use crate::{database::*, notifications::events::RemoveChannelField};
|
||||||
|
|
||||||
use mongodb::bson::{doc, to_document};
|
use mongodb::bson::{doc, to_document};
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/<target>")]
|
#[get("/<target>")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let target = target.fetch_channel().await?;
|
let target = target.fetch_channel().await?;
|
||||||
|
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
|||||||
use crate::util::variables::MAX_GROUP_SIZE;
|
use crate::util::variables::MAX_GROUP_SIZE;
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::{Json, JsonValue};
|
use rocket::serde::json::{Json, Value};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
@@ -23,7 +23,7 @@ pub struct Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/create", data = "<info>")]
|
#[post("/create", data = "<info>")]
|
||||||
pub async fn req(user: User, info: Json<Data>) -> Result<JsonValue> {
|
pub async fn req(user: User, info: Json<Data>) -> Result<Value> {
|
||||||
let info = info.into_inner();
|
let info = info.into_inner();
|
||||||
info.validate()
|
info.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref ALPHABET: [char; 54] = [
|
static ref ALPHABET: [char; 54] = [
|
||||||
@@ -14,7 +14,7 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/<target>/invites")]
|
#[post("/<target>/invites")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let target = target.fetch_channel().await?;
|
let target = target.fetch_channel().await?;
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
.with_channel(&target)
|
.with_channel(&target)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/<target>/members")]
|
#[get("/<target>/members")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let target = target.fetch_channel().await?;
|
let target = target.fetch_channel().await?;
|
||||||
|
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use mongodb::bson::{doc, Bson, DateTime, Document};
|
use mongodb::bson::{doc, Bson, DateTime, Document};
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/<target>/messages/<msg>")]
|
#[get("/<target>/messages/<msg>")]
|
||||||
pub async fn req(user: User, target: Ref, msg: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref, msg: Ref) -> Result<Value> {
|
||||||
let channel = target.fetch_channel().await?;
|
let channel = target.fetch_channel().await?;
|
||||||
channel.has_messaging()?;
|
channel.has_messaging()?;
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ use mongodb::{
|
|||||||
bson::{doc, from_document},
|
bson::{doc, from_document},
|
||||||
options::FindOptions,
|
options::FindOptions,
|
||||||
};
|
};
|
||||||
use rocket::request::Form;
|
use rocket::form::Form;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, FromFormValue)]
|
#[derive(Serialize, Deserialize, FromFormField)]
|
||||||
pub enum Sort {
|
pub enum Sort {
|
||||||
Latest,
|
Latest,
|
||||||
Oldest,
|
Oldest,
|
||||||
@@ -37,7 +37,7 @@ pub struct Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/<target>/messages?<options..>")]
|
#[get("/<target>/messages?<options..>")]
|
||||||
pub async fn req(user: User, target: Ref, options: Form<Options>) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref, options: Form<Options>) -> Result<Value> {
|
||||||
options
|
options
|
||||||
.validate()
|
.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use mongodb::bson::{doc, from_document};
|
use mongodb::bson::{doc, from_document};
|
||||||
use rocket_contrib::json::{Json, JsonValue};
|
use rocket::serde::json::{Json, Value};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
@@ -12,7 +12,7 @@ pub struct Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/<target>/messages/stale", data = "<data>")]
|
#[post("/<target>/messages/stale", data = "<data>")]
|
||||||
pub async fn req(user: User, target: Ref, data: Json<Options>) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref, data: Json<Options>) -> Result<Value> {
|
||||||
if data.ids.len() > 150 {
|
if data.ids.len() > 150 {
|
||||||
return Err(Error::TooManyIds);
|
return Err(Error::TooManyIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ use mongodb::{
|
|||||||
bson::{doc, from_document},
|
bson::{doc, from_document},
|
||||||
options::FindOptions,
|
options::FindOptions,
|
||||||
};
|
};
|
||||||
use rocket_contrib::json::{Json, JsonValue};
|
use rocket::serde::json::{Json, Value};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, FromFormValue)]
|
#[derive(Serialize, Deserialize, FromFormField)]
|
||||||
pub enum Sort {
|
pub enum Sort {
|
||||||
Relevance,
|
Relevance,
|
||||||
Latest,
|
Latest,
|
||||||
@@ -42,7 +42,7 @@ pub struct Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/<target>/search", data = "<options>")]
|
#[post("/<target>/search", data = "<options>")]
|
||||||
pub async fn req(user: User, target: Ref, options: Json<Options>) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref, options: Json<Options>) -> Result<Value> {
|
||||||
options
|
options
|
||||||
.validate()
|
.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use mongodb::{bson::doc, options::FindOneOptions};
|
use mongodb::{bson::doc, options::FindOneOptions};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rocket_contrib::json::{Json, JsonValue};
|
use rocket::serde::json::{Json, Value};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
@@ -33,7 +33,7 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/<target>/messages", data = "<message>")]
|
#[post("/<target>/messages", data = "<message>")]
|
||||||
pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<Value> {
|
||||||
let message = message.into_inner();
|
let message = message.into_inner();
|
||||||
message
|
message
|
||||||
.validate()
|
.validate()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use validator::Contains;
|
use validator::Contains;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use crate::database::*;
|
|||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
use crate::util::variables::{USE_VOSO, VOSO_MANAGE_TOKEN, VOSO_URL};
|
use crate::util::variables::{USE_VOSO, VOSO_MANAGE_TOKEN, VOSO_URL};
|
||||||
|
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
@@ -11,7 +11,7 @@ struct CreateUserResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/<target>/join_call")]
|
#[post("/<target>/join_call")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
if !*USE_VOSO {
|
if !*USE_VOSO {
|
||||||
return Err(Error::VosoUnavailable);
|
return Err(Error::VosoUnavailable);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::Result;
|
use crate::util::result::Result;
|
||||||
|
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Serialize, Debug, Clone)]
|
#[derive(Serialize, Debug, Clone)]
|
||||||
@@ -26,7 +26,7 @@ pub enum InviteResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/<target>")]
|
#[get("/<target>")]
|
||||||
pub async fn req(target: Ref) -> Result<JsonValue> {
|
pub async fn req(target: Ref) -> Result<Value> {
|
||||||
let target = target.fetch_invite().await?;
|
let target = target.fetch_invite().await?;
|
||||||
|
|
||||||
match target {
|
match target {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::Result;
|
use crate::util::result::Result;
|
||||||
|
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[post("/<target>")]
|
#[post("/<target>")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let target = target.fetch_invite().await?;
|
let target = target.fetch_invite().await?;
|
||||||
|
|
||||||
match target {
|
match target {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
pub use rocket::http::Status;
|
|
||||||
pub use rocket::response::Redirect;
|
pub use rocket::response::Redirect;
|
||||||
use rocket::Rocket;
|
pub use rocket::http::Status;
|
||||||
|
use rocket::{Phase, Rocket};
|
||||||
|
|
||||||
mod channels;
|
mod channels;
|
||||||
mod invites;
|
mod invites;
|
||||||
@@ -11,7 +11,7 @@ mod servers;
|
|||||||
mod sync;
|
mod sync;
|
||||||
mod users;
|
mod users;
|
||||||
|
|
||||||
pub fn mount(rocket: Rocket) -> Rocket {
|
pub fn mount<T: Phase>(rocket: Rocket<T>) -> Rocket<T> {
|
||||||
rocket
|
rocket
|
||||||
.mount("/", routes![root::root])
|
.mount("/", routes![root::root])
|
||||||
.mount("/onboard", onboard::routes())
|
.mount("/onboard", onboard::routes())
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::util::result::{Error, Result};
|
|||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rauth::auth::Session;
|
use rauth::auth::Session;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
|
|
||||||
use rauth::auth::Session;
|
use rauth::auth::Session;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/hello")]
|
#[get("/hello")]
|
||||||
pub async fn req(_session: Session, user: Option<User>) -> JsonValue {
|
pub async fn req(_session: Session, user: Option<User>) -> Value {
|
||||||
json!({
|
json!({
|
||||||
"onboarding": user.is_none()
|
"onboarding": user.is_none()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use mongodb::bson::{doc, to_document};
|
use mongodb::bson::{doc, to_document};
|
||||||
use rauth::auth::Session;
|
use rauth::auth::Session;
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
use crate::util::variables::{
|
use crate::util::{ratelimit::RateLimitGuard, variables::{
|
||||||
APP_URL, AUTUMN_URL, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, INVITE_ONLY, JANUARY_URL, USE_AUTUMN,
|
APP_URL, AUTUMN_URL, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, INVITE_ONLY, JANUARY_URL, USE_AUTUMN,
|
||||||
USE_EMAIL, USE_HCAPTCHA, USE_JANUARY, USE_VOSO, VAPID_PUBLIC_KEY, VOSO_URL, VOSO_WS_HOST,
|
USE_EMAIL, USE_HCAPTCHA, USE_JANUARY, USE_VOSO, VAPID_PUBLIC_KEY, VOSO_URL, VOSO_WS_HOST,
|
||||||
};
|
}};
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
use rocket_governor::RocketGovernor;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
pub async fn root() -> JsonValue {
|
pub async fn root(_limitguard: RocketGovernor<'_, RateLimitGuard>) -> Value {
|
||||||
json!({
|
json!({
|
||||||
"revolt": crate::version::VERSION,
|
"revolt": crate::version::VERSION,
|
||||||
"features": {
|
"features": {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use crate::database::*;
|
|||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::util::result::{Error, Result};
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use mongodb::options::FindOptions;
|
use mongodb::options::FindOptions;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
use mongodb::bson::{doc, from_document};
|
use mongodb::bson::{doc, from_document};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
@@ -15,7 +15,7 @@ struct BannedUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/<target>/bans")]
|
#[get("/<target>/bans")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let target = target.fetch_server().await?;
|
let target = target.fetch_server().await?;
|
||||||
|
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::database::*;
|
|||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::{Json, JsonValue};
|
use rocket::serde::json::{Json, Value};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
@@ -35,7 +35,7 @@ pub struct Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/<target>/channels", data = "<info>")]
|
#[post("/<target>/channels", data = "<info>")]
|
||||||
pub async fn req(user: User, target: Ref, info: Json<Data>) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref, info: Json<Data>) -> Result<Value> {
|
||||||
let info = info.into_inner();
|
let info = info.into_inner();
|
||||||
info.validate()
|
info.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use mongodb::bson::{doc, from_document};
|
use mongodb::bson::{doc, from_document};
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
@@ -15,7 +15,7 @@ pub struct ServerInvite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/<target>/invites")]
|
#[get("/<target>/invites")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let target = target.fetch_server().await?;
|
let target = target.fetch_server().await?;
|
||||||
|
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::util::result::{Error, Result};
|
|||||||
use crate::{database::*, notifications::events::RemoveMemberField};
|
use crate::{database::*, notifications::events::RemoveMemberField};
|
||||||
|
|
||||||
use mongodb::bson::{doc, to_document};
|
use mongodb::bson::{doc, to_document};
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ use crate::database::*;
|
|||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/<target>/members/<member>")]
|
#[get("/<target>/members/<member>")]
|
||||||
pub async fn req(user: User, target: Ref, member: String) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref, member: String) -> Result<Value> {
|
||||||
let target = target.fetch_server().await?;
|
let target = target.fetch_server().await?;
|
||||||
|
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use mongodb::bson::{doc, from_document, Document};
|
use mongodb::bson::{doc, from_document, Document};
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
// ! FIXME: this is a temporary route while permissions are being worked on.
|
// ! FIXME: this is a temporary route while permissions are being worked on.
|
||||||
|
|
||||||
#[get("/<target>/members")]
|
#[get("/<target>/members")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let target = target.fetch_server().await?;
|
let target = target.fetch_server().await?;
|
||||||
|
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use ulid::Ulid;
|
|||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use rocket_contrib::json::{Json, JsonValue};
|
use rocket::serde::json::{Json, Value};
|
||||||
|
|
||||||
#[derive(Validate, Serialize, Deserialize)]
|
#[derive(Validate, Serialize, Deserialize)]
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
@@ -15,7 +15,7 @@ pub struct Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/<target>/roles", data = "<data>")]
|
#[post("/<target>/roles", data = "<data>")]
|
||||||
pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<Value> {
|
||||||
let data = data.into_inner();
|
let data = data.into_inner();
|
||||||
data.validate()
|
data.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
|||||||
use crate::{database::*, notifications::events::RemoveRoleField};
|
use crate::{database::*, notifications::events::RemoveRoleField};
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::database::*;
|
|||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::{Json, JsonValue};
|
use rocket::serde::json::{Json, Value};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
@@ -21,7 +21,7 @@ pub struct Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/create", data = "<info>")]
|
#[post("/create", data = "<info>")]
|
||||||
pub async fn req(user: User, info: Json<Data>) -> Result<JsonValue> {
|
pub async fn req(user: User, info: Json<Data>) -> Result<Value> {
|
||||||
let info = info.into_inner();
|
let info = info.into_inner();
|
||||||
info.validate()
|
info.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
|||||||
use crate::{database::*, notifications::events::RemoveServerField};
|
use crate::{database::*, notifications::events::RemoveServerField};
|
||||||
|
|
||||||
use mongodb::bson::{doc, to_bson, to_document};
|
use mongodb::bson::{doc, to_bson, to_document};
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/<target>")]
|
#[get("/<target>")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let target = target.fetch_server().await?;
|
let target = target.fetch_server().await?;
|
||||||
|
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use mongodb::options::FindOneOptions;
|
use mongodb::options::FindOneOptions;
|
||||||
use rocket_contrib::json::{Json, JsonValue};
|
use rocket::serde::json::{Json, Value};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
@@ -12,7 +12,7 @@ pub struct Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/settings/fetch", data = "<options>")]
|
#[post("/settings/fetch", data = "<options>")]
|
||||||
pub async fn req(user: User, options: Json<Options>) -> Result<JsonValue> {
|
pub async fn req(user: User, options: Json<Options>) -> Result<Value> {
|
||||||
let options = options.into_inner();
|
let options = options.into_inner();
|
||||||
let mut projection = doc! {
|
let mut projection = doc! {
|
||||||
"_id": 0,
|
"_id": 0,
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ use crate::database::*;
|
|||||||
use crate::util::result::Result;
|
use crate::util::result::Result;
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/unreads")]
|
#[get("/unreads")]
|
||||||
pub async fn req(user: User) -> Result<JsonValue> {
|
pub async fn req(user: User) -> Result<Value> {
|
||||||
Ok(json!(User::fetch_unreads(&user.id).await?))
|
Ok(json!(User::fetch_unreads(&user.id).await?))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ use crate::util::result::{Error, Result};
|
|||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use mongodb::bson::{doc, to_bson};
|
use mongodb::bson::{doc, to_bson};
|
||||||
use mongodb::options::UpdateOptions;
|
use mongodb::options::UpdateOptions;
|
||||||
use rocket::request::Form;
|
use rocket::form::Form;
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ use crate::util::result::{Error, Result};
|
|||||||
use futures::try_join;
|
use futures::try_join;
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use mongodb::options::{Collation, FindOneOptions};
|
use mongodb::options::{Collation, FindOneOptions};
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[put("/<username>/friend")]
|
#[put("/<username>/friend")]
|
||||||
pub async fn req(user: User, username: String) -> Result<JsonValue> {
|
pub async fn req(user: User, username: String) -> Result<Value> {
|
||||||
let col = get_collection("users");
|
let col = get_collection("users");
|
||||||
let doc = col
|
let doc = col
|
||||||
.find_one(
|
.find_one(
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use futures::try_join;
|
use futures::try_join;
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[put("/<target>/block")]
|
#[put("/<target>/block")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let col = get_collection("users");
|
let col = get_collection("users");
|
||||||
|
|
||||||
let target = target.fetch_user().await?;
|
let target = target.fetch_user().await?;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use mongodb::bson::doc;
|
|||||||
use rauth::auth::{Auth, Session};
|
use rauth::auth::{Auth, Session};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rocket::State;
|
use rocket::State;
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ pub struct Data {
|
|||||||
|
|
||||||
#[patch("/<_ignore_id>/username", data = "<data>")]
|
#[patch("/<_ignore_id>/username", data = "<data>")]
|
||||||
pub async fn req(
|
pub async fn req(
|
||||||
auth: State<'_, Auth>,
|
auth: &State<Auth>,
|
||||||
session: Session,
|
session: Session,
|
||||||
user: User,
|
user: User,
|
||||||
data: Json<Data>,
|
data: Json<Data>,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
|||||||
use crate::{database::*, notifications::events::RemoveUserField};
|
use crate::{database::*, notifications::events::RemoveUserField};
|
||||||
|
|
||||||
use mongodb::bson::{doc, to_document};
|
use mongodb::bson::{doc, to_document};
|
||||||
use rocket_contrib::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/dms")]
|
#[get("/dms")]
|
||||||
pub async fn req(user: User) -> Result<JsonValue> {
|
pub async fn req(user: User) -> Result<Value> {
|
||||||
let mut cursor = get_collection("channels")
|
let mut cursor = get_collection("channels")
|
||||||
.find(
|
.find(
|
||||||
doc! {
|
doc! {
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ use crate::database::*;
|
|||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/<target>/profile")]
|
#[get("/<target>/profile")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let target = target.fetch_user().await?;
|
let target = target.fetch_user().await?;
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
.with_user(&target)
|
.with_user(&target)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::Result;
|
use crate::util::result::Result;
|
||||||
|
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/<target>/relationship")]
|
#[get("/<target>/relationship")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
Ok(json!({ "status": get_relationship(&user, &target.id) }))
|
Ok(json!({ "status": get_relationship(&user, &target.id) }))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::Result;
|
use crate::util::result::Result;
|
||||||
|
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/relationships")]
|
#[get("/relationships")]
|
||||||
pub async fn req(user: User) -> Result<JsonValue> {
|
pub async fn req(user: User) -> Result<Value> {
|
||||||
Ok(if let Some(vec) = user.relations {
|
Ok(if let Some(vec) = user.relations {
|
||||||
json!(vec)
|
json!(vec)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/<target>")]
|
#[get("/<target>")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let target = target.fetch_user().await?;
|
let target = target.fetch_user().await?;
|
||||||
|
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ use crate::util::result::{Error, Result};
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use mongodb::bson::{doc, Document};
|
use mongodb::bson::{doc, Document};
|
||||||
use mongodb::options::FindOptions;
|
use mongodb::options::FindOptions;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/<target>/mutual")]
|
#[get("/<target>/mutual")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let users = get_collection("users")
|
let users = get_collection("users")
|
||||||
.find(
|
.find(
|
||||||
doc! {
|
doc! {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use rocket::{Request, Response};
|
use rocket::{Request, Response};
|
||||||
use rocket::response::{self, NamedFile, Responder};
|
use rocket::response::{self, Responder};
|
||||||
|
use rocket::fs::NamedFile;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::database::Ref;
|
use crate::database::Ref;
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ use crate::database::*;
|
|||||||
use crate::util::result::{Error, Result};
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
|
|
||||||
#[get("/<target>/dm")]
|
#[get("/<target>/dm")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let query = if user.id == target.id {
|
let query = if user.id == target.id {
|
||||||
doc! {
|
doc! {
|
||||||
"channel_type": "SavedMessages",
|
"channel_type": "SavedMessages",
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use futures::try_join;
|
use futures::try_join;
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[delete("/<target>/friend")]
|
#[delete("/<target>/friend")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let col = get_collection("users");
|
let col = get_collection("users");
|
||||||
|
|
||||||
let target = target.fetch_user().await?;
|
let target = target.fetch_user().await?;
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
use futures::try_join;
|
use futures::try_join;
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rocket_contrib::json::JsonValue;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[delete("/<target>/block")]
|
#[delete("/<target>/block")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let col = get_collection("users");
|
let col = get_collection("users");
|
||||||
let target = target.fetch_user().await?;
|
let target = target.fetch_user().await?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod result;
|
pub mod result;
|
||||||
pub mod variables;
|
pub mod variables;
|
||||||
|
pub mod ratelimit;
|
||||||
|
|||||||
9
src/util/ratelimit.rs
Normal file
9
src/util/ratelimit.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
use rocket_governor::{Method, Quota, RocketGovernable, RocketGovernor};
|
||||||
|
|
||||||
|
pub struct RateLimitGuard;
|
||||||
|
|
||||||
|
impl<'r> RocketGovernable<'r> for RateLimitGuard {
|
||||||
|
fn quota(_method: Method, _route_name: &str) -> Quota {
|
||||||
|
Quota::per_second(Self::nonzero(1u32))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user