DATABASE_PASSWORD=password
DATABASE_URL=postgres://lemmy:password@lemmy_db:5432/lemmy
JWT_SECRET=changeme
+RATE_LIMIT_MESSAGE=30
+RATE_LIMIT_MESSAGE_PER_SECOND=60
+RATE_LIMIT_POST=3
+RATE_LIMIT_POST_PER_SECOND=600
+RATE_LIMIT_REGISTER=1
+RATE_LIMIT_REGISTER_PER_SECOND=3600
COPY ui /app/ui
RUN yarn build
-FROM rust:1.37 as rust
+FROM rust:1.38 as rust
# Install musl
RUN apt-get update
- DATABASE_URL=${DATABASE_URL}
- JWT_SECRET=${JWT_SECRET}
- HOSTNAME=${DOMAIN}
+ - RATE_LIMIT_MESSAGE=${RATE_LIMIT_MESSAGE}
+ - RATE_LIMIT_MESSAGE_PER_SECOND=${RATE_LIMIT_MESSAGE_PER_SECOND}
+ - RATE_LIMIT_POST=${RATE_LIMIT_POST}
+ - RATE_LIMIT_POST_PER_SECOND=${RATE_LIMIT_POST_PER_SECOND}
+ - RATE_LIMIT_REGISTER=${RATE_LIMIT_REGISTER}
+ - RATE_LIMIT_REGISTER_PER_SECOND=${RATE_LIMIT_REGISTER_PER_SECOND}
restart: always
depends_on:
- lemmy_db
DATABASE_PASSWORD=password
DATABASE_URL=postgres://lemmy:password@lemmy_db:5432/lemmy
JWT_SECRET=changeme
+RATE_LIMIT_MESSAGE=30
+RATE_LIMIT_MESSAGE_PER_SECOND=60
+RATE_LIMIT_POST=3
+RATE_LIMIT_POST_PER_SECOND=600
+RATE_LIMIT_REGISTER=1
+RATE_LIMIT_REGISTER_PER_SECOND=3600
- DATABASE_URL=${DATABASE_URL}
- JWT_SECRET=${JWT_SECRET}
- HOSTNAME=${DOMAIN}
+ - RATE_LIMIT_MESSAGE=${RATE_LIMIT_MESSAGE}
+ - RATE_LIMIT_MESSAGE_PER_SECOND=${RATE_LIMIT_MESSAGE_PER_SECOND}
+ - RATE_LIMIT_POST=${RATE_LIMIT_POST}
+ - RATE_LIMIT_POST_PER_SECOND=${RATE_LIMIT_POST_PER_SECOND}
+ - RATE_LIMIT_REGISTER=${RATE_LIMIT_REGISTER}
+ - RATE_LIMIT_REGISTER_PER_SECOND=${RATE_LIMIT_REGISTER_PER_SECOND}
restart: always
depends_on:
- lemmy_db
site: site_view,
admins: admins,
banned: banned,
- online: 0
+ online: 0,
})
}
}
site: Some(site_view),
admins: admins,
banned: banned,
- online: 0
+ online: 0,
})
}
}
db_url: String,
hostname: String,
jwt_secret: String,
+ rate_limit_message: i32,
+ rate_limit_message_per_second: i32,
+ rate_limit_post: i32,
+ rate_limit_post_per_second: i32,
+ rate_limit_register: i32,
+ rate_limit_register_per_second: i32,
}
impl Settings {
db_url: env::var("DATABASE_URL").expect("DATABASE_URL must be set"),
hostname: env::var("HOSTNAME").unwrap_or("rrr".to_string()),
jwt_secret: env::var("JWT_SECRET").unwrap_or("changeme".to_string()),
+ rate_limit_message: env::var("RATE_LIMIT_MESSAGE")
+ .unwrap_or("30".to_string())
+ .parse()
+ .unwrap(),
+ rate_limit_message_per_second: env::var("RATE_LIMIT_MESSAGE_PER_SECOND")
+ .unwrap_or("60".to_string())
+ .parse()
+ .unwrap(),
+ rate_limit_post: env::var("RATE_LIMIT_POST")
+ .unwrap_or("3".to_string())
+ .parse()
+ .unwrap(),
+ rate_limit_post_per_second: env::var("RATE_LIMIT_POST_PER_SECOND")
+ .unwrap_or("600".to_string())
+ .parse()
+ .unwrap(),
+ rate_limit_register: env::var("RATE_LIMIT_REGISTER")
+ .unwrap_or("1".to_string())
+ .parse()
+ .unwrap(),
+ rate_limit_register_per_second: env::var("RATE_LIMIT_REGISTER_PER_SECOND")
+ .unwrap_or("3600".to_string())
+ .parse()
+ .unwrap(),
}
}
fn api_endpoint(&self) -> String {
#[test]
fn test_slur_filter() {
- let test = "coons test dindu ladyboy tranny retardeds. This is a bunch of other safe text.".to_string();
+ let test =
+ "coons test dindu ladyboy tranny retardeds. This is a bunch of other safe text.".to_string();
let slur_free = "No slurs here";
assert_eq!(
remove_slurs(&test),
assert!(has_slurs(&test));
assert!(!has_slurs(slur_free));
}
-
}
lazy_static! {
use crate::api::site::*;
use crate::api::user::*;
use crate::api::*;
-
-const RATE_LIMIT_MESSAGE: i32 = 30;
-const RATE_LIMIT_MESSAGES_PER_SECOND: i32 = 60;
-const RATE_LIMIT_POST: i32 = 3;
-const RATE_LIMIT_POSTS_PER_SECOND: i32 = 60 * 10;
-const RATE_LIMIT_REGISTER: i32 = 1;
-const RATE_LIMIT_REGISTER_PER_SECOND: i32 = 60 * 60;
+use crate::Settings;
/// Chat server sends this messages to session
#[derive(Message)]
}
fn check_rate_limit_register(&mut self, id: usize) -> Result<(), Error> {
- self.check_rate_limit_full(id, RATE_LIMIT_REGISTER, RATE_LIMIT_REGISTER_PER_SECOND)
+ self.check_rate_limit_full(
+ id,
+ Settings::get().rate_limit_register,
+ Settings::get().rate_limit_register_per_second,
+ )
}
fn check_rate_limit_post(&mut self, id: usize) -> Result<(), Error> {
- self.check_rate_limit_full(id, RATE_LIMIT_POST, RATE_LIMIT_POSTS_PER_SECOND)
+ self.check_rate_limit_full(
+ id,
+ Settings::get().rate_limit_post,
+ Settings::get().rate_limit_post_per_second,
+ )
}
fn check_rate_limit_message(&mut self, id: usize) -> Result<(), Error> {
- self.check_rate_limit_full(id, RATE_LIMIT_MESSAGE, RATE_LIMIT_MESSAGES_PER_SECOND)
+ self.check_rate_limit_full(
+ id,
+ Settings::get().rate_limit_message,
+ Settings::get().rate_limit_message_per_second,
+ )
}
fn check_rate_limit_full(&mut self, id: usize, rate: i32, per: i32) -> Result<(), Error> {