feat: make constants configurable
This commit is contained in:
parent
97a1cb97a9
commit
5826d3586f
978
server/Cargo.lock
generated
978
server/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -7,9 +7,9 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
base64 = "0.21"
|
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
|
data-encoding = "2.6.0"
|
||||||
if_chain = "1"
|
if_chain = "1"
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
@ -7,4 +7,6 @@ pub struct Config {
|
|||||||
pub address: String,
|
pub address: String,
|
||||||
pub packs: PathBuf,
|
pub packs: PathBuf,
|
||||||
pub database: String,
|
pub database: String,
|
||||||
|
pub vote_threshold_hide: i32,
|
||||||
|
pub max_messages: i32,
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
pub const VOTE_THRESHOLD_HIDE: i32 = -1;
|
|
@ -23,7 +23,6 @@ mod message;
|
|||||||
mod web;
|
mod web;
|
||||||
mod util;
|
mod util;
|
||||||
mod config;
|
mod config;
|
||||||
mod consts;
|
|
||||||
|
|
||||||
static MIGRATOR: Migrator = sqlx::migrate!();
|
static MIGRATOR: Migrator = sqlx::migrate!();
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
use base64::Engine;
|
|
||||||
use base64::prelude::BASE64_STANDARD;
|
|
||||||
use sha3::{Digest, Sha3_384};
|
use sha3::{Digest, Sha3_384};
|
||||||
|
|
||||||
// TerritoryIntendedUse = 13 or 14
|
// TerritoryIntendedUse = 13 or 14
|
||||||
@ -50,5 +48,5 @@ pub fn hash(input: &str) -> String {
|
|||||||
let mut hasher = Sha3_384::default();
|
let mut hasher = Sha3_384::default();
|
||||||
hasher.update(input.as_bytes());
|
hasher.update(input.as_bytes());
|
||||||
let result = hasher.finalize();
|
let result = hasher.finalize();
|
||||||
BASE64_STANDARD.encode(result)
|
data_encoding::BASE64.encode(&result)
|
||||||
}
|
}
|
||||||
|
@ -122,14 +122,14 @@ async fn logic(state: Arc<State>, id: i64, location: u32, query: GetLocationQuer
|
|||||||
.map_err(warp::reject::custom)?
|
.map_err(warp::reject::custom)?
|
||||||
};
|
};
|
||||||
|
|
||||||
filter_messages(&mut messages, id);
|
filter_messages(&mut messages, id, state.config.vote_threshold_hide);
|
||||||
Ok(warp::reply::json(&messages))
|
Ok(warp::reply::json(&messages))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter_messages(messages: &mut Vec<RetrievedMessage>, id: i64) {
|
fn filter_messages(messages: &mut Vec<RetrievedMessage>, id: i64, vote_threshold_hide: i32) {
|
||||||
// remove messages where the user has been offline for over 35 minutes
|
// remove messages where the user has been offline for over 35 minutes
|
||||||
// also remove messages with low score (that aren't the from the user)
|
// also remove messages with low score (that aren't the from the user)
|
||||||
messages.retain(|msg| msg.last_seen_minutes < 35 && (msg.user == id || (msg.positive_votes - msg.negative_votes) >= crate::consts::VOTE_THRESHOLD_HIDE));
|
messages.retain(|msg| msg.last_seen_minutes < 35 && (msg.user == id || (msg.positive_votes - msg.negative_votes) >= vote_threshold_hide));
|
||||||
|
|
||||||
// shuffle messages since we'll be excluding later based on messages
|
// shuffle messages since we'll be excluding later based on messages
|
||||||
// that have already been included, so this will be more fair
|
// that have already been included, so this will be more fair
|
||||||
|
@ -63,7 +63,7 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, mut query: HashMap<String
|
|||||||
messages.reverse();
|
messages.reverse();
|
||||||
|
|
||||||
for msg in &mut messages {
|
for msg in &mut messages {
|
||||||
msg.is_hidden = msg.positive_votes - msg.negative_votes < crate::consts::VOTE_THRESHOLD_HIDE;
|
msg.is_hidden = msg.positive_votes - msg.negative_votes < state.config.vote_threshold_hide;
|
||||||
}
|
}
|
||||||
|
|
||||||
if version == 1 {
|
if version == 1 {
|
||||||
|
@ -58,7 +58,7 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, message: Message) -> Resu
|
|||||||
.map_err(AnyhowRejection)
|
.map_err(AnyhowRejection)
|
||||||
.map_err(warp::reject::custom)?;
|
.map_err(warp::reject::custom)?;
|
||||||
|
|
||||||
if existing.count >= 10 + extra as i32 {
|
if existing.count >= state.config.max_messages + extra as i32 {
|
||||||
return Err(warp::reject::custom(WebError::TooManyMessages));
|
return Err(warp::reject::custom(WebError::TooManyMessages));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user