Adding rate_limiter and api_structs.
This commit is contained in:
parent
88978077b5
commit
3a6982e7b2
8 changed files with 34 additions and 14 deletions
10
docker/dev/Dockerfile
vendored
10
docker/dev/Dockerfile
vendored
|
@ -20,12 +20,18 @@ RUN USER=root cargo new server
|
||||||
# Install cargo-build-deps
|
# Install cargo-build-deps
|
||||||
RUN cargo install --git https://github.com/romac/cargo-build-deps.git
|
RUN cargo install --git https://github.com/romac/cargo-build-deps.git
|
||||||
WORKDIR /app/server
|
WORKDIR /app/server
|
||||||
RUN mkdir -p lemmy_db/src/ lemmy_utils/src/
|
RUN mkdir -p lemmy_db/src/ \
|
||||||
|
lemmy_utils/src/ \
|
||||||
|
lemmy_api_structs/src/ \
|
||||||
|
lemmy_rate_limit/src/ \
|
||||||
|
lemmy
|
||||||
|
|
||||||
# Copy the cargo tomls
|
# Copy the cargo tomls
|
||||||
COPY server/Cargo.toml server/Cargo.lock ./
|
COPY server/Cargo.toml server/Cargo.lock ./
|
||||||
COPY server/lemmy_db/Cargo.toml ./lemmy_db/
|
COPY server/lemmy_db/Cargo.toml ./lemmy_db/
|
||||||
COPY server/lemmy_utils/Cargo.toml ./lemmy_utils/
|
COPY server/lemmy_utils/Cargo.toml ./lemmy_utils/
|
||||||
|
COPY server/lemmy_api_structs/Cargo.toml ./lemmy_api_structs/
|
||||||
|
COPY server/lemmy_rate_limit/Cargo.toml ./lemmy_rate_limit/
|
||||||
|
|
||||||
# Cache the deps
|
# Cache the deps
|
||||||
RUN cargo build-deps
|
RUN cargo build-deps
|
||||||
|
@ -34,6 +40,8 @@ RUN cargo build-deps
|
||||||
COPY server/src ./src/
|
COPY server/src ./src/
|
||||||
COPY server/lemmy_db/src ./lemmy_db/src/
|
COPY server/lemmy_db/src ./lemmy_db/src/
|
||||||
COPY server/lemmy_utils/src/ ./lemmy_utils/src/
|
COPY server/lemmy_utils/src/ ./lemmy_utils/src/
|
||||||
|
COPY server/lemmy_api_structs/src/ ./lemmy_api_structs/src/
|
||||||
|
COPY server/lemmy_rate_limit/src/ ./lemmy_rate_limit/src/
|
||||||
COPY server/migrations ./migrations/
|
COPY server/migrations ./migrations/
|
||||||
|
|
||||||
# Build for debug
|
# Build for debug
|
||||||
|
|
2
docker/prod/Dockerfile
vendored
2
docker/prod/Dockerfile
vendored
|
@ -13,6 +13,8 @@ WORKDIR /app/server
|
||||||
COPY server/Cargo.toml server/Cargo.lock ./
|
COPY server/Cargo.toml server/Cargo.lock ./
|
||||||
COPY server/lemmy_db ./lemmy_db
|
COPY server/lemmy_db ./lemmy_db
|
||||||
COPY server/lemmy_utils ./lemmy_utils
|
COPY server/lemmy_utils ./lemmy_utils
|
||||||
|
COPY server/lemmy_api_structs ./lemmy_api_structs
|
||||||
|
COPY server/lemmy_rate_limit ./lemmy_rate_limit
|
||||||
RUN mkdir -p ./src/bin \
|
RUN mkdir -p ./src/bin \
|
||||||
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
|
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
|
||||||
RUN cargo build --release
|
RUN cargo build --release
|
||||||
|
|
1
server/Cargo.toml
vendored
1
server/Cargo.toml
vendored
|
@ -11,6 +11,7 @@ members = [
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"lemmy_db",
|
"lemmy_db",
|
||||||
"lemmy_api_structs",
|
"lemmy_api_structs",
|
||||||
|
"lemmy_rate_limit",
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
4
server/lemmy_api_structs/Cargo.toml
vendored
4
server/lemmy_api_structs/Cargo.toml
vendored
|
@ -4,6 +4,10 @@ version = "0.1.0"
|
||||||
authors = ["Felix Ableitner <me@nutomic.com>"]
|
authors = ["Felix Ableitner <me@nutomic.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "lemmy_api_structs"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_db = { path = "../lemmy_db" }
|
lemmy_db = { path = "../lemmy_db" }
|
||||||
serde = { version = "1.0.105", features = ["derive"] }
|
serde = { version = "1.0.105", features = ["derive"] }
|
||||||
|
|
4
server/lemmy_rate_limit/Cargo.toml
vendored
4
server/lemmy_rate_limit/Cargo.toml
vendored
|
@ -4,6 +4,10 @@ version = "0.1.0"
|
||||||
authors = ["Felix Ableitner <me@nutomic.com>"]
|
authors = ["Felix Ableitner <me@nutomic.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "lemmy_rate_limit"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_utils = { path = "../lemmy_utils" }
|
lemmy_utils = { path = "../lemmy_utils" }
|
||||||
lemmy_api_structs = { path = "../lemmy_api_structs" }
|
lemmy_api_structs = { path = "../lemmy_api_structs" }
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub extern crate strum_macros;
|
pub extern crate strum_macros;
|
||||||
pub extern crate tokio;
|
|
||||||
pub extern crate futures;
|
|
||||||
pub extern crate actix_web;
|
pub extern crate actix_web;
|
||||||
|
pub extern crate futures;
|
||||||
pub extern crate log;
|
pub extern crate log;
|
||||||
|
pub extern crate tokio;
|
||||||
|
|
||||||
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
|
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
|
||||||
use futures::future::{ok, Ready};
|
use futures::future::{ok, Ready};
|
||||||
use lemmy_utils::settings::{RateLimitConfig, Settings};
|
use lemmy_utils::{
|
||||||
|
get_ip,
|
||||||
|
settings::{RateLimitConfig, Settings},
|
||||||
|
LemmyError,
|
||||||
|
};
|
||||||
use rate_limiter::{RateLimitType, RateLimiter};
|
use rate_limiter::{RateLimitType, RateLimiter};
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
future::Future,
|
||||||
|
@ -16,8 +20,6 @@ use std::{
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use lemmy_utils::get_ip;
|
|
||||||
use lemmy_utils::LemmyError;
|
|
||||||
|
|
||||||
pub mod rate_limiter;
|
pub mod rate_limiter;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use lemmy_utils::IPAddr;
|
|
||||||
use lemmy_utils::LemmyError;
|
|
||||||
use lemmy_api_structs::APIError;
|
use lemmy_api_structs::APIError;
|
||||||
|
use lemmy_utils::{IPAddr, LemmyError};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use std::{collections::HashMap, time::SystemTime};
|
use std::{collections::HashMap, time::SystemTime};
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub extern crate lazy_static;
|
pub extern crate lazy_static;
|
||||||
|
pub extern crate actix_web;
|
||||||
|
pub extern crate anyhow;
|
||||||
pub extern crate comrak;
|
pub extern crate comrak;
|
||||||
pub extern crate lettre;
|
pub extern crate lettre;
|
||||||
pub extern crate lettre_email;
|
pub extern crate lettre_email;
|
||||||
|
@ -8,12 +10,11 @@ pub extern crate rand;
|
||||||
pub extern crate regex;
|
pub extern crate regex;
|
||||||
pub extern crate serde_json;
|
pub extern crate serde_json;
|
||||||
pub extern crate url;
|
pub extern crate url;
|
||||||
pub extern crate actix_web;
|
|
||||||
pub extern crate anyhow;
|
|
||||||
|
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
|
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
|
use actix_web::dev::ConnectionInfo;
|
||||||
use chrono::{DateTime, FixedOffset, Local, NaiveDateTime};
|
use chrono::{DateTime, FixedOffset, Local, NaiveDateTime};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lettre::{
|
use lettre::{
|
||||||
|
@ -32,7 +33,6 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||||
use regex::{Regex, RegexBuilder};
|
use regex::{Regex, RegexBuilder};
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use actix_web::dev::ConnectionInfo;
|
|
||||||
|
|
||||||
pub type ConnectionId = usize;
|
pub type ConnectionId = usize;
|
||||||
pub type PostId = i32;
|
pub type PostId = i32;
|
||||||
|
@ -58,8 +58,8 @@ pub struct LemmyError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> From<T> for LemmyError
|
impl<T> From<T> for LemmyError
|
||||||
where
|
where
|
||||||
T: Into<anyhow::Error>,
|
T: Into<anyhow::Error>,
|
||||||
{
|
{
|
||||||
fn from(t: T) -> Self {
|
fn from(t: T) -> Self {
|
||||||
LemmyError { inner: t.into() }
|
LemmyError { inner: t.into() }
|
||||||
|
|
Loading…
Reference in a new issue