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"
|
||||
urlencoding = "1.1.1"
|
||||
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"] }
|
||||
serde = { version = "1.0.115", features = ["derive"] }
|
||||
validator = { version = "0.11", features = ["derive"] }
|
||||
ctrlc = { version = "3.0", features = ["termination"] }
|
||||
hive_pubsub = { version = "0.4.4", features = ["mongo"] }
|
||||
async-std = { version = "1.8.0", features = ["tokio02", "attributes"] }
|
||||
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" }
|
||||
mongodb = { version = "1.1.1", features = ["tokio-runtime"], default-features = false }
|
||||
rauth = { git = "https://gitlab.insrt.uk/insert/rauth", rev = "00d3c3dff51cf3242a7d4adda4c5184c97fa2a03" }
|
||||
rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket", rev = "031948c1daaa146128d8a435be116476f2adde00" }
|
||||
mongodb = { version = "1.2.2", features = ["tokio-runtime"], default-features = false }
|
||||
rauth = { git = "https://gitlab.insrt.uk/insert/rauth", rev = "51546e5a1ba0dfe3ec3bd0b060fa51fc3102c96f" }
|
||||
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},
|
||||
options::FindOptions,
|
||||
};
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -139,7 +139,7 @@ impl Channel {
|
||||
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();
|
||||
ClientboundNotification::ChannelUpdate {
|
||||
id: id.clone(),
|
||||
|
||||
@@ -11,7 +11,7 @@ use mongodb::{
|
||||
bson::{doc, to_bson, DateTime},
|
||||
options::FindOptions,
|
||||
};
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ulid::Ulid;
|
||||
use web_push::{
|
||||
@@ -323,7 +323,7 @@ impl Message {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn publish_update(self, data: JsonValue) -> Result<()> {
|
||||
pub async fn publish_update(self, data: Value) -> Result<()> {
|
||||
let channel = self.channel.clone();
|
||||
ClientboundNotification::MessageUpdate {
|
||||
id: self.id.clone(),
|
||||
|
||||
@@ -8,7 +8,7 @@ use mongodb::bson::{Bson, doc};
|
||||
use mongodb::bson::from_document;
|
||||
use mongodb::bson::to_document;
|
||||
use mongodb::bson::Document;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -120,7 +120,7 @@ impl Server {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn publish_update(&self, data: JsonValue) -> Result<()> {
|
||||
pub async fn publish_update(&self, data: Value) -> Result<()> {
|
||||
ClientboundNotification::ServerUpdate {
|
||||
id: self.id.clone(),
|
||||
data,
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::database::*;
|
||||
use mongodb::bson::{doc, from_document};
|
||||
use rauth::auth::Session;
|
||||
use rocket::http::Status;
|
||||
use rocket::outcome::try_outcome;
|
||||
use rocket::request::{self, FromRequest, Outcome, Request};
|
||||
|
||||
#[rocket::async_trait]
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
#[macro_use]
|
||||
extern crate rocket_contrib;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use]
|
||||
extern crate impl_ops;
|
||||
@@ -30,6 +28,7 @@ use rauth::{
|
||||
};
|
||||
use rocket_cors::AllowedOrigins;
|
||||
use rocket_prometheus::PrometheusMetrics;
|
||||
use rocket::catchers;
|
||||
use util::variables::{
|
||||
APP_URL, HCAPTCHA_KEY, INVITE_ONLY, PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD,
|
||||
SMTP_USERNAME, USE_EMAIL, USE_HCAPTCHA, USE_PROMETHEUS,
|
||||
@@ -140,6 +139,7 @@ Reset your password here: {{url}}",
|
||||
.manage(auth)
|
||||
.manage(cors.clone())
|
||||
.attach(cors)
|
||||
.register("/", catchers![rocket_governor::rocket_governor_catcher])
|
||||
.launch()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use hive_pubsub::PubSub;
|
||||
use mongodb::bson::doc;
|
||||
use rauth::auth::Session;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::hive::{get_hive, subscribe_if_exists};
|
||||
@@ -73,7 +73,7 @@ pub enum ClientboundNotification {
|
||||
MessageUpdate {
|
||||
id: String,
|
||||
channel: String,
|
||||
data: JsonValue,
|
||||
data: Value,
|
||||
},
|
||||
MessageDelete {
|
||||
id: String,
|
||||
@@ -83,7 +83,7 @@ pub enum ClientboundNotification {
|
||||
ChannelCreate(Channel),
|
||||
ChannelUpdate {
|
||||
id: String,
|
||||
data: JsonValue,
|
||||
data: Value,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
clear: Option<RemoveChannelField>,
|
||||
},
|
||||
@@ -114,7 +114,7 @@ pub enum ClientboundNotification {
|
||||
|
||||
ServerUpdate {
|
||||
id: String,
|
||||
data: JsonValue,
|
||||
data: Value,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
clear: Option<RemoveServerField>,
|
||||
},
|
||||
@@ -123,7 +123,7 @@ pub enum ClientboundNotification {
|
||||
},
|
||||
ServerMemberUpdate {
|
||||
id: MemberCompositeKey,
|
||||
data: JsonValue,
|
||||
data: Value,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
clear: Option<RemoveMemberField>,
|
||||
},
|
||||
@@ -138,7 +138,7 @@ pub enum ClientboundNotification {
|
||||
ServerRoleUpdate {
|
||||
id: String,
|
||||
role_id: String,
|
||||
data: JsonValue,
|
||||
data: Value,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
clear: Option<RemoveRoleField>
|
||||
},
|
||||
@@ -149,7 +149,7 @@ pub enum ClientboundNotification {
|
||||
|
||||
UserUpdate {
|
||||
id: String,
|
||||
data: JsonValue,
|
||||
data: Value,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
clear: Option<RemoveUserField>,
|
||||
},
|
||||
@@ -160,7 +160,7 @@ pub enum ClientboundNotification {
|
||||
},
|
||||
UserSettingsUpdate {
|
||||
id: String,
|
||||
update: JsonValue,
|
||||
update: Value,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
||||
use crate::{database::*, notifications::events::RemoveChannelField};
|
||||
|
||||
use mongodb::bson::{doc, to_document};
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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 perm = permissions::PermissionCalculator::new(&user)
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
||||
use crate::util::variables::MAX_GROUP_SIZE;
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::{Json, JsonValue};
|
||||
use rocket::serde::json::{Json, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashSet;
|
||||
use std::iter::FromIterator;
|
||||
@@ -23,7 +23,7 @@ pub struct Data {
|
||||
}
|
||||
|
||||
#[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();
|
||||
info.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use nanoid::nanoid;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
lazy_static! {
|
||||
static ref ALPHABET: [char; 54] = [
|
||||
@@ -14,7 +14,7 @@ lazy_static! {
|
||||
}
|
||||
|
||||
#[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 perm = permissions::PermissionCalculator::new(&user)
|
||||
.with_channel(&target)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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 perm = permissions::PermissionCalculator::new(&user)
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use chrono::Utc;
|
||||
use mongodb::bson::{doc, Bson, DateTime, Document};
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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?;
|
||||
channel.has_messaging()?;
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@ use mongodb::{
|
||||
bson::{doc, from_document},
|
||||
options::FindOptions,
|
||||
};
|
||||
use rocket::request::Form;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::form::Form;
|
||||
use rocket::serde::json::Value;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Serialize, Deserialize, FromFormValue)]
|
||||
#[derive(Serialize, Deserialize, FromFormField)]
|
||||
pub enum Sort {
|
||||
Latest,
|
||||
Oldest,
|
||||
@@ -37,7 +37,7 @@ pub struct 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
|
||||
.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use futures::StreamExt;
|
||||
use mongodb::bson::{doc, from_document};
|
||||
use rocket_contrib::json::{Json, JsonValue};
|
||||
use rocket::serde::json::{Json, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -12,7 +12,7 @@ pub struct Options {
|
||||
}
|
||||
|
||||
#[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 {
|
||||
return Err(Error::TooManyIds);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ use mongodb::{
|
||||
bson::{doc, from_document},
|
||||
options::FindOptions,
|
||||
};
|
||||
use rocket_contrib::json::{Json, JsonValue};
|
||||
use rocket::serde::json::{Json, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Serialize, Deserialize, FromFormValue)]
|
||||
#[derive(Serialize, Deserialize, FromFormField)]
|
||||
pub enum Sort {
|
||||
Relevance,
|
||||
Latest,
|
||||
@@ -42,7 +42,7 @@ pub struct 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
|
||||
.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::{bson::doc, options::FindOneOptions};
|
||||
use regex::Regex;
|
||||
use rocket_contrib::json::{Json, JsonValue};
|
||||
use rocket::serde::json::{Json, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ulid::Ulid;
|
||||
use validator::Validate;
|
||||
@@ -33,7 +33,7 @@ lazy_static! {
|
||||
}
|
||||
|
||||
#[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();
|
||||
message
|
||||
.validate()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use validator::Contains;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::database::*;
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
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};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -11,7 +11,7 @@ struct CreateUserResponse {
|
||||
}
|
||||
|
||||
#[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 {
|
||||
return Err(Error::VosoUnavailable);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::Result;
|
||||
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Debug, Clone)]
|
||||
@@ -26,7 +26,7 @@ pub enum InviteResponse {
|
||||
}
|
||||
|
||||
#[get("/<target>")]
|
||||
pub async fn req(target: Ref) -> Result<JsonValue> {
|
||||
pub async fn req(target: Ref) -> Result<Value> {
|
||||
let target = target.fetch_invite().await?;
|
||||
|
||||
match target {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::Result;
|
||||
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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?;
|
||||
|
||||
match target {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pub use rocket::http::Status;
|
||||
pub use rocket::response::Redirect;
|
||||
use rocket::Rocket;
|
||||
pub use rocket::http::Status;
|
||||
use rocket::{Phase, Rocket};
|
||||
|
||||
mod channels;
|
||||
mod invites;
|
||||
@@ -11,7 +11,7 @@ mod servers;
|
||||
mod sync;
|
||||
mod users;
|
||||
|
||||
pub fn mount(rocket: Rocket) -> Rocket {
|
||||
pub fn mount<T: Phase>(rocket: Rocket<T>) -> Rocket<T> {
|
||||
rocket
|
||||
.mount("/", routes![root::root])
|
||||
.mount("/onboard", onboard::routes())
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::util::result::{Error, Result};
|
||||
use mongodb::bson::doc;
|
||||
use rauth::auth::Session;
|
||||
use regex::Regex;
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::database::*;
|
||||
|
||||
use rauth::auth::Session;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[get("/hello")]
|
||||
pub async fn req(_session: Session, user: Option<User>) -> JsonValue {
|
||||
pub async fn req(_session: Session, user: Option<User>) -> Value {
|
||||
json!({
|
||||
"onboarding": user.is_none()
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::{doc, to_document};
|
||||
use rauth::auth::Session;
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[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,
|
||||
USE_EMAIL, USE_HCAPTCHA, USE_JANUARY, USE_VOSO, VAPID_PUBLIC_KEY, VOSO_URL, VOSO_WS_HOST,
|
||||
};
|
||||
}};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
use rocket_governor::RocketGovernor;
|
||||
|
||||
#[get("/")]
|
||||
pub async fn root() -> JsonValue {
|
||||
pub async fn root(_limitguard: RocketGovernor<'_, RateLimitGuard>) -> Value {
|
||||
json!({
|
||||
"revolt": crate::version::VERSION,
|
||||
"features": {
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::util::result::{Error, Result};
|
||||
use futures::StreamExt;
|
||||
use mongodb::options::FindOptions;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
use mongodb::bson::{doc, from_document};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -15,7 +15,7 @@ struct BannedUser {
|
||||
}
|
||||
|
||||
#[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 perm = permissions::PermissionCalculator::new(&user)
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::{Json, JsonValue};
|
||||
use rocket::serde::json::{Json, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ulid::Ulid;
|
||||
use validator::Validate;
|
||||
@@ -35,7 +35,7 @@ pub struct Data {
|
||||
}
|
||||
|
||||
#[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();
|
||||
info.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use futures::StreamExt;
|
||||
use mongodb::bson::{doc, from_document};
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -15,7 +15,7 @@ pub struct ServerInvite {
|
||||
}
|
||||
|
||||
#[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 perm = permissions::PermissionCalculator::new(&user)
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::util::result::{Error, Result};
|
||||
use crate::{database::*, notifications::events::RemoveMemberField};
|
||||
|
||||
use mongodb::bson::{doc, to_document};
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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 perm = permissions::PermissionCalculator::new(&user)
|
||||
|
||||
@@ -3,12 +3,12 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use futures::StreamExt;
|
||||
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.
|
||||
|
||||
#[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 perm = permissions::PermissionCalculator::new(&user)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::database::*;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::database::*;
|
||||
|
||||
@@ -6,7 +6,7 @@ use ulid::Ulid;
|
||||
use mongodb::bson::doc;
|
||||
use validator::Validate;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use rocket_contrib::json::{Json, JsonValue};
|
||||
use rocket::serde::json::{Json, Value};
|
||||
|
||||
#[derive(Validate, Serialize, Deserialize)]
|
||||
pub struct Data {
|
||||
@@ -15,7 +15,7 @@ pub struct 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();
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
||||
use crate::{database::*, notifications::events::RemoveRoleField};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::{Json, JsonValue};
|
||||
use rocket::serde::json::{Json, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ulid::Ulid;
|
||||
use validator::Validate;
|
||||
@@ -21,7 +21,7 @@ pub struct Data {
|
||||
}
|
||||
|
||||
#[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();
|
||||
info.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
||||
use crate::{database::*, notifications::events::RemoveServerField};
|
||||
|
||||
use mongodb::bson::{doc, to_bson, to_document};
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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 perm = permissions::PermissionCalculator::new(&user)
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use mongodb::options::FindOneOptions;
|
||||
use rocket_contrib::json::{Json, JsonValue};
|
||||
use rocket::serde::json::{Json, Value};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -12,7 +12,7 @@ pub struct 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 mut projection = doc! {
|
||||
"_id": 0,
|
||||
|
||||
@@ -2,9 +2,9 @@ use crate::database::*;
|
||||
use crate::util::result::Result;
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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?))
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ use crate::util::result::{Error, Result};
|
||||
use chrono::prelude::*;
|
||||
use mongodb::bson::{doc, to_bson};
|
||||
use mongodb::options::UpdateOptions;
|
||||
use rocket::request::Form;
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::form::Form;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ use crate::util::result::{Error, Result};
|
||||
use futures::try_join;
|
||||
use mongodb::bson::doc;
|
||||
use mongodb::options::{Collation, FindOneOptions};
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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 doc = col
|
||||
.find_one(
|
||||
|
||||
@@ -4,10 +4,10 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use futures::try_join;
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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 target = target.fetch_user().await?;
|
||||
|
||||
@@ -6,7 +6,7 @@ use mongodb::bson::doc;
|
||||
use rauth::auth::{Auth, Session};
|
||||
use regex::Regex;
|
||||
use rocket::State;
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
@@ -25,7 +25,7 @@ pub struct Data {
|
||||
|
||||
#[patch("/<_ignore_id>/username", data = "<data>")]
|
||||
pub async fn req(
|
||||
auth: State<'_, Auth>,
|
||||
auth: &State<Auth>,
|
||||
session: Session,
|
||||
user: User,
|
||||
data: Json<Data>,
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::util::result::{Error, Result};
|
||||
use crate::{database::*, notifications::events::RemoveUserField};
|
||||
|
||||
use mongodb::bson::{doc, to_document};
|
||||
use rocket_contrib::json::Json;
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use futures::StreamExt;
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[get("/dms")]
|
||||
pub async fn req(user: User) -> Result<JsonValue> {
|
||||
pub async fn req(user: User) -> Result<Value> {
|
||||
let mut cursor = get_collection("channels")
|
||||
.find(
|
||||
doc! {
|
||||
|
||||
@@ -2,10 +2,10 @@ use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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 perm = permissions::PermissionCalculator::new(&user)
|
||||
.with_user(&target)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::Result;
|
||||
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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) }))
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::Result;
|
||||
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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 {
|
||||
json!(vec)
|
||||
} else {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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 perm = permissions::PermissionCalculator::new(&user)
|
||||
|
||||
@@ -4,10 +4,10 @@ use crate::util::result::{Error, Result};
|
||||
use futures::StreamExt;
|
||||
use mongodb::bson::{doc, Document};
|
||||
use mongodb::options::FindOptions;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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")
|
||||
.find(
|
||||
doc! {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use rocket::{Request, Response};
|
||||
use rocket::response::{self, NamedFile, Responder};
|
||||
use rocket::response::{self, Responder};
|
||||
use rocket::fs::NamedFile;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::database::Ref;
|
||||
|
||||
@@ -2,11 +2,11 @@ use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
use ulid::Ulid;
|
||||
|
||||
#[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 {
|
||||
doc! {
|
||||
"channel_type": "SavedMessages",
|
||||
|
||||
@@ -4,10 +4,10 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use futures::try_join;
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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 target = target.fetch_user().await?;
|
||||
|
||||
@@ -4,10 +4,10 @@ use crate::util::result::{Error, Result};
|
||||
|
||||
use futures::try_join;
|
||||
use mongodb::bson::doc;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
#[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 target = target.fetch_user().await?;
|
||||
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod result;
|
||||
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