mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-06 11:16:00 +00:00
Compare commits
8 Commits
0.3.2
...
0.3.3-alph
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38bedbaaea | ||
|
|
ea276c3517 | ||
|
|
648e33a13e | ||
|
|
a76ec207b3 | ||
|
|
687b300bfc | ||
|
|
6586d8f02c | ||
|
|
a8a8c08c29 | ||
|
|
1806ea824b |
@@ -1,3 +1,2 @@
|
||||
assets
|
||||
target
|
||||
.env
|
||||
44
Cargo.lock
generated
44
Cargo.lock
generated
@@ -1409,6 +1409,12 @@ dependencies = [
|
||||
"opaque-debug 0.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "md5"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.3.4"
|
||||
@@ -1971,6 +1977,20 @@ dependencies = [
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prometheus"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8425533e7122f0c3cc7a37e6244b16ad3a2cc32ae7ac6276e2a75da0d9c200d"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"fnv",
|
||||
"lazy_static",
|
||||
"parking_lot 0.11.1",
|
||||
"regex",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
@@ -2208,8 +2228,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rauth"
|
||||
version = "0.2.0"
|
||||
source = "git+https://gitlab.insrt.uk/insert/rauth?rev=8f3ea627#8f3ea627eb304945b0af0b79aca8e94e474e46ae"
|
||||
version = "0.2.1"
|
||||
source = "git+https://gitlab.insrt.uk/insert/rauth?rev=d48b0087cc546d2c9ef53f27d0693c8378172dfe#d48b0087cc546d2c9ef53f27d0693c8378172dfe"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"json",
|
||||
@@ -2351,7 +2371,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3-alpha.0"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"async-tungstenite",
|
||||
@@ -2367,6 +2387,7 @@ dependencies = [
|
||||
"lettre",
|
||||
"log",
|
||||
"many-to-many",
|
||||
"md5",
|
||||
"mongodb",
|
||||
"num_enum",
|
||||
"once_cell",
|
||||
@@ -2377,11 +2398,13 @@ dependencies = [
|
||||
"rocket",
|
||||
"rocket_contrib",
|
||||
"rocket_cors",
|
||||
"rocket_prometheus",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"snafu",
|
||||
"time 0.2.25",
|
||||
"ulid",
|
||||
"urlencoding",
|
||||
"validator",
|
||||
]
|
||||
|
||||
@@ -2493,6 +2516,15 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rocket_prometheus"
|
||||
version = "0.7.0"
|
||||
source = "git+https://github.com/insertish/rocket_prometheus?rev=3d825aedb42793246c306a81fe67c5b187948983#3d825aedb42793246c306a81fe67c5b187948983"
|
||||
dependencies = [
|
||||
"prometheus",
|
||||
"rocket",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-argon2"
|
||||
version = "0.8.3"
|
||||
@@ -3374,6 +3406,12 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "urlencoding"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9232eb53352b4442e40d7900465dfc534e8cb2dc8f18656fcb2ac16112b5593"
|
||||
|
||||
[[package]]
|
||||
name = "utf-8"
|
||||
version = "0.7.5"
|
||||
|
||||
11
Cargo.toml
11
Cargo.toml
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3-alpha.0"
|
||||
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
@@ -8,15 +8,16 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
futures = "0.3.8"
|
||||
many-to-many = "0.1.2"
|
||||
impl_ops = "0.1.1"
|
||||
many-to-many = "0.1.2"
|
||||
ctrlc = { version = "3.0", features = ["termination"] }
|
||||
async-tungstenite = { version = "0.10.0", features = ["async-std-runtime"] }
|
||||
rauth = { git = "https://gitlab.insrt.uk/insert/rauth", rev = "8f3ea627" }
|
||||
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 = "d48b0087cc546d2c9ef53f27d0693c8378172dfe" }
|
||||
|
||||
hive_pubsub = { version = "0.4.3", features = ["mongo"] }
|
||||
rocket_cors = { git = "https://github.com/insertish/rocket_cors", branch = "master" }
|
||||
rocket_prometheus = { git = "https://github.com/insertish/rocket_prometheus", rev = "3d825aedb42793246c306a81fe67c5b187948983" }
|
||||
rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket", rev = "031948c1daaa146128d8a435be116476f2adde00" }
|
||||
rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "031948c1daaa146128d8a435be116476f2adde00", default-features = false }
|
||||
mongodb = { version = "1.1.1", features = ["tokio-runtime"], default-features = false }
|
||||
@@ -32,11 +33,13 @@ serde_json = "1.0.57"
|
||||
bitfield = "0.13.2"
|
||||
|
||||
reqwest = { version = "0.10.8", features = ["json"] }
|
||||
urlencoding = "1.1.1"
|
||||
lazy_static = "1.4.0"
|
||||
num_enum = "0.5.1"
|
||||
chrono = "0.4.15"
|
||||
time = "0.2.16"
|
||||
rand = "0.7.3"
|
||||
md5 = "0.7.0"
|
||||
regex = "1"
|
||||
|
||||
lettre = "0.10.0-alpha.1"
|
||||
|
||||
10
Dockerfile
10
Dockerfile
@@ -1,16 +1,20 @@
|
||||
# Build Stage
|
||||
FROM ekidd/rust-musl-builder:nightly-2020-11-19 AS builder
|
||||
FROM ekidd/rust-musl-builder:nightly-2021-01-01 AS builder
|
||||
WORKDIR /home/rust/src
|
||||
|
||||
RUN USER=root cargo new --bin revolt
|
||||
WORKDIR ./revolt
|
||||
WORKDIR /home/rust/src/revolt
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
COPY src ./src
|
||||
RUN cargo build --release
|
||||
|
||||
# Bundle Stage
|
||||
FROM scratch
|
||||
FROM alpine:latest
|
||||
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
|
||||
COPY --from=builder /home/rust/src/revolt/target/x86_64-unknown-linux-musl/release/revolt ./
|
||||
COPY assets ./assets
|
||||
EXPOSE 8000
|
||||
EXPOSE 9000
|
||||
ENV ROCKET_ADDRESS 0.0.0.0
|
||||
ENV ROCKET_PORT 8000
|
||||
CMD ["./revolt"]
|
||||
|
||||
@@ -14,5 +14,5 @@ services:
|
||||
- REVOLT_UNSAFE_NO_CAPTCHA=1
|
||||
ports:
|
||||
- "8000:8000"
|
||||
- "9999:9999"
|
||||
- "9000:9000"
|
||||
restart: unless-stopped
|
||||
|
||||
21
src/main.rs
21
src/main.rs
@@ -18,13 +18,14 @@ pub mod notifications;
|
||||
pub mod routes;
|
||||
pub mod util;
|
||||
|
||||
use chrono::Duration;
|
||||
use futures::join;
|
||||
use log::info;
|
||||
use futures::join;
|
||||
use chrono::Duration;
|
||||
use rauth::auth::Auth;
|
||||
use rauth::options::{EmailVerification, Options, SMTP};
|
||||
use rocket_cors::AllowedOrigins;
|
||||
use util::variables::{PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD, SMTP_USERNAME, USE_EMAIL};
|
||||
use rocket_prometheus::PrometheusMetrics;
|
||||
use rauth::options::{EmailVerification, Options, SMTP};
|
||||
use util::variables::{PUBLIC_URL, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD, SMTP_USERNAME, USE_EMAIL, USE_PROMETHEUS};
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
@@ -80,7 +81,17 @@ async fn launch_web() {
|
||||
}),
|
||||
);
|
||||
|
||||
routes::mount(rocket::ignite())
|
||||
let mut rocket = rocket::ignite();
|
||||
|
||||
if *USE_PROMETHEUS {
|
||||
info!("Enabled Prometheus metrics!");
|
||||
let prometheus = PrometheusMetrics::new();
|
||||
rocket = rocket
|
||||
.attach(prometheus.clone())
|
||||
.mount("/metrics", prometheus);
|
||||
}
|
||||
|
||||
routes::mount(rocket)
|
||||
.mount("/", rocket_cors::catch_all_options_routes())
|
||||
.mount("/auth", rauth::routes::routes())
|
||||
.manage(auth)
|
||||
|
||||
@@ -8,7 +8,7 @@ use rocket_contrib::json::JsonValue;
|
||||
#[get("/")]
|
||||
pub async fn root() -> JsonValue {
|
||||
json!({
|
||||
"revolt": "0.3.1",
|
||||
"revolt": "0.3.3-alpha.0",
|
||||
"features": {
|
||||
"registration": !*DISABLE_REGISTRATION,
|
||||
"captcha": {
|
||||
|
||||
@@ -1,29 +1,48 @@
|
||||
use rocket::response::NamedFile;
|
||||
use std::path::Path;
|
||||
use mongodb::options::FindOneOptions;
|
||||
use rocket::response::Redirect;
|
||||
use mongodb::bson::doc;
|
||||
use urlencoding;
|
||||
use md5;
|
||||
|
||||
use crate::database::Ref;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::variables::PUBLIC_URL;
|
||||
use crate::database::*;
|
||||
|
||||
#[get("/<target>/avatar")]
|
||||
pub async fn req(target: Ref) -> Option<NamedFile> {
|
||||
match target.id.chars().nth(25).unwrap() {
|
||||
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' => {
|
||||
NamedFile::open(Path::new("assets/user_red.png")).await.ok()
|
||||
}
|
||||
'8' | '9' | 'A' | 'C' | 'B' | 'D' | 'E' | 'F' => {
|
||||
NamedFile::open(Path::new("assets/user_green.png"))
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
'G' | 'H' | 'J' | 'K' | 'M' | 'N' | 'P' | 'Q' => {
|
||||
NamedFile::open(Path::new("assets/user_blue.png"))
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
'R' | 'S' | 'T' | 'V' | 'W' | 'X' | 'Y' | 'Z' => {
|
||||
NamedFile::open(Path::new("assets/user_yellow.png"))
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
pub async fn req(target: Ref) -> Result<Redirect> {
|
||||
let doc = get_collection("accounts")
|
||||
.find_one(
|
||||
doc! {
|
||||
"_id": &target.id
|
||||
},
|
||||
FindOneOptions::builder()
|
||||
.projection(doc! { "email": 1 })
|
||||
.build()
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError { operation: "find_one", with: "user" })?
|
||||
.ok_or_else(|| Error::UnknownUser)?;
|
||||
|
||||
let email = doc
|
||||
.get_str("email")
|
||||
.map_err(|_| Error::DatabaseError { operation: "get_str(email)", with: "user" })?
|
||||
.to_lowercase();
|
||||
|
||||
let url = format!(
|
||||
"https://www.gravatar.com/avatar/{:x}?s=128&d={}",
|
||||
md5::compute(email),
|
||||
urlencoding::encode(
|
||||
&format!(
|
||||
"{}/users/{}/default_avatar",
|
||||
*PUBLIC_URL,
|
||||
&target.id
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
dbg!(&url);
|
||||
|
||||
Ok(
|
||||
Redirect::to(url)
|
||||
)
|
||||
}
|
||||
|
||||
29
src/routes/users/get_default_avatar.rs
Normal file
29
src/routes/users/get_default_avatar.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use rocket::response::NamedFile;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::database::Ref;
|
||||
|
||||
#[get("/<target>/default_avatar")]
|
||||
pub async fn req(target: Ref) -> Option<NamedFile> {
|
||||
match target.id.chars().nth(25).unwrap() {
|
||||
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' => {
|
||||
NamedFile::open(Path::new("assets/user_red.png")).await.ok()
|
||||
}
|
||||
'8' | '9' | 'A' | 'C' | 'B' | 'D' | 'E' | 'F' => {
|
||||
NamedFile::open(Path::new("assets/user_green.png"))
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
'G' | 'H' | 'J' | 'K' | 'M' | 'N' | 'P' | 'Q' => {
|
||||
NamedFile::open(Path::new("assets/user_blue.png"))
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
'R' | 'S' | 'T' | 'V' | 'W' | 'X' | 'Y' | 'Z' => {
|
||||
NamedFile::open(Path::new("assets/user_yellow.png"))
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ mod fetch_relationship;
|
||||
mod fetch_relationships;
|
||||
mod fetch_user;
|
||||
mod get_avatar;
|
||||
mod get_default_avatar;
|
||||
mod open_dm;
|
||||
mod remove_friend;
|
||||
mod unblock_user;
|
||||
@@ -15,6 +16,7 @@ pub fn routes() -> Vec<Route> {
|
||||
routes![
|
||||
// User Information
|
||||
fetch_user::req,
|
||||
get_default_avatar::req,
|
||||
get_avatar::req,
|
||||
// Direct Messaging
|
||||
fetch_dms::req,
|
||||
|
||||
@@ -19,7 +19,7 @@ lazy_static! {
|
||||
env::var("REVOLT_WS_HOST").unwrap_or_else(|_| "0.0.0.0:9000".to_string());
|
||||
|
||||
// Application Flags
|
||||
pub static ref DISABLE_REGISTRATION: bool = env::var("REVOLT_DISABLE_REGISTRATION").map_or(false, |v| v == "*1");
|
||||
pub static ref DISABLE_REGISTRATION: bool = env::var("REVOLT_DISABLE_REGISTRATION").map_or(false, |v| v == "1");
|
||||
pub static ref USE_EMAIL: bool = env::var("REVOLT_USE_EMAIL_VERIFICATION").map_or(
|
||||
env::var("REVOLT_SMTP_HOST").is_ok()
|
||||
&& env::var("REVOLT_SMTP_USERNAME").is_ok()
|
||||
@@ -28,6 +28,7 @@ lazy_static! {
|
||||
|v| v == *"1"
|
||||
);
|
||||
pub static ref USE_HCAPTCHA: bool = env::var("REVOLT_HCAPTCHA_KEY").is_ok();
|
||||
pub static ref USE_PROMETHEUS: bool = env::var("REVOLT_ENABLE_PROMETHEUS").map_or(false, |v| v == "1");
|
||||
|
||||
// SMTP Settings
|
||||
pub static ref SMTP_HOST: String =
|
||||
|
||||
Reference in New Issue
Block a user