forked from jmug/stoatchat
Compare commits
3 Commits
0.3.3-alph
...
0.3.3-alph
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6b51bca26 | ||
|
|
2bafffbbc1 | ||
|
|
bdf5fb95d0 |
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -2308,8 +2308,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rauth"
|
||||
version = "0.2.2"
|
||||
source = "git+https://gitlab.insrt.uk/insert/rauth?rev=73fd602f0aba3d3689307fb1f811f211422fb4d3#73fd602f0aba3d3689307fb1f811f211422fb4d3"
|
||||
version = "0.2.5-alpha.0"
|
||||
source = "git+https://gitlab.insrt.uk/insert/rauth?rev=c52758a5087cd035b0ed9c6eacc942ba5468d2ce#c52758a5087cd035b0ed9c6eacc942ba5468d2ce"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"handlebars",
|
||||
@@ -2319,6 +2319,7 @@ dependencies = [
|
||||
"mongodb",
|
||||
"nanoid",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"rocket",
|
||||
"rocket_contrib",
|
||||
"rust-argon2",
|
||||
@@ -2453,7 +2454,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt"
|
||||
version = "0.3.3-alpha.1"
|
||||
version = "0.3.3-alpha.4"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"async-tungstenite",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt"
|
||||
version = "0.3.3-alpha.1"
|
||||
version = "0.3.3-alpha.4"
|
||||
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
@@ -13,7 +13,7 @@ many-to-many = "0.1.2"
|
||||
ctrlc = { version = "3.0", features = ["termination"] }
|
||||
async-std = { version = "1.8.0", features = ["tokio02", "attributes"] }
|
||||
async-tungstenite = { version = "0.10.0", features = ["async-std-runtime"] }
|
||||
rauth = { git = "https://gitlab.insrt.uk/insert/rauth", rev = "73fd602f0aba3d3689307fb1f811f211422fb4d3" }
|
||||
rauth = { git = "https://gitlab.insrt.uk/insert/rauth", rev = "c52758a5087cd035b0ed9c6eacc942ba5468d2ce" }
|
||||
|
||||
hive_pubsub = { version = "0.4.3", features = ["mongo"] }
|
||||
rocket_cors = { git = "https://github.com/insertish/rocket_cors", branch = "master" }
|
||||
|
||||
88
src/main.rs
88
src/main.rs
@@ -21,12 +21,16 @@ pub mod util;
|
||||
use chrono::Duration;
|
||||
use futures::join;
|
||||
use log::info;
|
||||
use rauth::{auth::Auth, options::{Template, Templates}};
|
||||
use rauth::options::{EmailVerification, Options, SMTP};
|
||||
use rauth::{
|
||||
auth::Auth,
|
||||
options::{Template, Templates},
|
||||
};
|
||||
use rocket_cors::AllowedOrigins;
|
||||
use rocket_prometheus::PrometheusMetrics;
|
||||
use util::variables::{
|
||||
PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD, SMTP_USERNAME, USE_EMAIL, USE_PROMETHEUS, APP_URL, INVITE_ONLY
|
||||
APP_URL, HCAPTCHA_KEY, INVITE_ONLY, PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD,
|
||||
SMTP_USERNAME, USE_EMAIL, USE_HCAPTCHA, USE_PROMETHEUS,
|
||||
};
|
||||
|
||||
#[async_std::main]
|
||||
@@ -61,49 +65,51 @@ async fn launch_web() {
|
||||
.to_cors()
|
||||
.expect("Failed to create CORS.");
|
||||
|
||||
let auth = Auth::new(
|
||||
database::get_collection("accounts"),
|
||||
if *INVITE_ONLY {
|
||||
Options::new()
|
||||
.invite_only_collection(database::get_collection("invites"))
|
||||
let mut options = Options::new()
|
||||
.base_url(format!("{}/auth", *PUBLIC_URL))
|
||||
.email_verification(if *USE_EMAIL {
|
||||
EmailVerification::Enabled {
|
||||
success_redirect_uri: format!("{}/login", *APP_URL),
|
||||
welcome_redirect_uri: format!("{}/welcome", *APP_URL),
|
||||
password_reset_url: Some(format!("{}/login/reset", *APP_URL)),
|
||||
|
||||
verification_expiry: Duration::days(1),
|
||||
password_reset_expiry: Duration::hours(1),
|
||||
|
||||
templates: Templates {
|
||||
verify_email: Template {
|
||||
title: "Verify your REVOLT account.",
|
||||
text: "Verify your email here: {{url}}",
|
||||
html: include_str!("../assets/templates/verify.html"),
|
||||
},
|
||||
reset_password: Template {
|
||||
title: "Reset your REVOLT password.",
|
||||
text: "Reset your password here: {{url}}",
|
||||
html: include_str!("../assets/templates/reset.html"),
|
||||
},
|
||||
welcome: None,
|
||||
},
|
||||
|
||||
smtp: SMTP {
|
||||
from: (*SMTP_FROM).to_string(),
|
||||
host: (*SMTP_HOST).to_string(),
|
||||
username: (*SMTP_USERNAME).to_string(),
|
||||
password: (*SMTP_PASSWORD).to_string(),
|
||||
},
|
||||
}
|
||||
} else {
|
||||
Options::new()
|
||||
}
|
||||
.base_url(format!("{}/auth", *PUBLIC_URL))
|
||||
.email_verification(if *USE_EMAIL {
|
||||
EmailVerification::Enabled {
|
||||
success_redirect_uri: format!("{}/login", *APP_URL),
|
||||
welcome_redirect_uri: format!("{}/welcome", *APP_URL),
|
||||
password_reset_url: Some(format!("{}/login/reset", *APP_URL)),
|
||||
EmailVerification::Disabled
|
||||
});
|
||||
|
||||
verification_expiry: Duration::days(1),
|
||||
password_reset_expiry: Duration::hours(1),
|
||||
if *INVITE_ONLY {
|
||||
options = options.invite_only_collection(database::get_collection("invites"))
|
||||
}
|
||||
|
||||
templates: Templates {
|
||||
verify_email: Template {
|
||||
title: "Verify your REVOLT account.",
|
||||
text: "Verify your email here: {{url}}",
|
||||
html: include_str!("../assets/templates/verify.html")
|
||||
},
|
||||
reset_password: Template {
|
||||
title: "Reset your REVOLT password.",
|
||||
text: "Reset your password here: {{url}}",
|
||||
html: include_str!("../assets/templates/reset.html")
|
||||
},
|
||||
welcome: None
|
||||
},
|
||||
if *USE_HCAPTCHA {
|
||||
options = options.hcaptcha_secret(HCAPTCHA_KEY.clone());
|
||||
}
|
||||
|
||||
smtp: SMTP {
|
||||
from: (*SMTP_FROM).to_string(),
|
||||
host: (*SMTP_HOST).to_string(),
|
||||
username: (*SMTP_USERNAME).to_string(),
|
||||
password: (*SMTP_PASSWORD).to_string(),
|
||||
},
|
||||
}
|
||||
} else {
|
||||
EmailVerification::Disabled
|
||||
}),
|
||||
);
|
||||
let auth = Auth::new(database::get_collection("accounts"), options);
|
||||
|
||||
let mut rocket = rocket::ignite();
|
||||
|
||||
|
||||
74
src/routes/channels/message_query_stale.rs
Normal file
74
src/routes/channels/message_query_stale.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use futures::StreamExt;
|
||||
use mongodb::bson::{doc, from_document};
|
||||
use rocket_contrib::json::{Json, JsonValue};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Options {
|
||||
ids: Vec<String>
|
||||
}
|
||||
|
||||
#[post("/<target>/messages/stale", data = "<data>")]
|
||||
pub async fn req(user: User, target: Ref, data: Json<Options>) -> Result<JsonValue> {
|
||||
if data.ids.len() > 150 {
|
||||
return Err(Error::LabelMe);
|
||||
}
|
||||
|
||||
let target = target.fetch_channel().await?;
|
||||
|
||||
let perm = permissions::PermissionCalculator::new(&user)
|
||||
.with_channel(&target)
|
||||
.for_channel()
|
||||
.await?;
|
||||
if !perm.get_view() {
|
||||
Err(Error::LabelMe)?
|
||||
}
|
||||
|
||||
let mut cursor = get_collection("messages")
|
||||
.find(
|
||||
doc! {
|
||||
"_id": {
|
||||
"$in": &data.ids
|
||||
},
|
||||
"channel": target.id()
|
||||
},
|
||||
None
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find",
|
||||
with: "messages",
|
||||
})?;
|
||||
|
||||
let mut updated = vec![];
|
||||
let mut found_ids = vec![];
|
||||
while let Some(result) = cursor.next().await {
|
||||
if let Ok(doc) = result {
|
||||
let msg = from_document::<Message>(doc)
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "from_document",
|
||||
with: "message",
|
||||
})?;
|
||||
|
||||
found_ids.push(msg.id.clone());
|
||||
if msg.edited.is_some() {
|
||||
updated.push(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut deleted = vec![];
|
||||
for id in &data.ids {
|
||||
if found_ids.iter().find(|x| *x == id).is_none() {
|
||||
deleted.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(json!({
|
||||
"updated": updated,
|
||||
"deleted": deleted
|
||||
}))
|
||||
}
|
||||
@@ -9,6 +9,7 @@ mod message_delete;
|
||||
mod message_edit;
|
||||
mod message_fetch;
|
||||
mod message_query;
|
||||
mod message_query_stale;
|
||||
mod message_send;
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
@@ -17,6 +18,7 @@ pub fn routes() -> Vec<Route> {
|
||||
delete_channel::req,
|
||||
message_send::req,
|
||||
message_query::req,
|
||||
message_query_stale::req,
|
||||
message_fetch::req,
|
||||
message_edit::req,
|
||||
message_delete::req,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::util::variables::{
|
||||
DISABLE_REGISTRATION, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, USE_EMAIL, USE_HCAPTCHA, INVITE_ONLY
|
||||
DISABLE_REGISTRATION, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, INVITE_ONLY, USE_EMAIL, USE_HCAPTCHA,
|
||||
};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
@@ -8,7 +8,7 @@ use rocket_contrib::json::JsonValue;
|
||||
#[get("/")]
|
||||
pub async fn root() -> JsonValue {
|
||||
json!({
|
||||
"revolt": "0.3.3-alpha.1",
|
||||
"revolt": "0.3.3-alpha.4",
|
||||
"features": {
|
||||
"registration": !*DISABLE_REGISTRATION,
|
||||
"captcha": {
|
||||
|
||||
41
src/routes/users/find_mutual.rs
Normal file
41
src/routes/users/find_mutual.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use futures::StreamExt;
|
||||
use mongodb::options::FindOptions;
|
||||
use mongodb::bson::{Document, doc};
|
||||
use rocket_contrib::json::JsonValue;
|
||||
|
||||
#[get("/<target>/mutual")]
|
||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
let channels = get_collection("channels")
|
||||
.find(
|
||||
doc! {
|
||||
"$or": [
|
||||
{ "type": "Group" },
|
||||
],
|
||||
"$and": [
|
||||
{ "recipients": &user.id },
|
||||
{ "recipients": &target.id }
|
||||
]
|
||||
},
|
||||
FindOptions::builder()
|
||||
.projection(doc! { "_id": 1 })
|
||||
.build()
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find",
|
||||
with: "channels",
|
||||
})?
|
||||
.filter_map(async move |s| s.ok())
|
||||
.collect::<Vec<Document>>()
|
||||
.await
|
||||
.into_iter()
|
||||
.filter_map(|x| x.get_str("_id").ok().map(|x| x.to_string()))
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
Ok(json!({
|
||||
"channels": channels
|
||||
}))
|
||||
}
|
||||
@@ -6,6 +6,7 @@ mod fetch_dms;
|
||||
mod fetch_relationship;
|
||||
mod fetch_relationships;
|
||||
mod fetch_user;
|
||||
mod find_mutual;
|
||||
mod get_avatar;
|
||||
mod get_default_avatar;
|
||||
mod open_dm;
|
||||
@@ -22,6 +23,7 @@ pub fn routes() -> Vec<Route> {
|
||||
fetch_dms::req,
|
||||
open_dm::req,
|
||||
// Relationships
|
||||
find_mutual::req,
|
||||
fetch_relationships::req,
|
||||
fetch_relationship::req,
|
||||
add_friend::req,
|
||||
|
||||
Reference in New Issue
Block a user