Adding rate_limiter and api_structs.

This commit is contained in:
Dessalines 2020-09-02 18:17:35 -05:00
parent 88978077b5
commit 3a6982e7b2
8 changed files with 34 additions and 14 deletions

10
docker/dev/Dockerfile vendored
View file

@ -20,12 +20,18 @@ RUN USER=root cargo new server
# Install cargo-build-deps
RUN cargo install --git https://github.com/romac/cargo-build-deps.git
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 server/Cargo.toml server/Cargo.lock ./
COPY server/lemmy_db/Cargo.toml ./lemmy_db/
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
RUN cargo build-deps
@ -34,6 +40,8 @@ RUN cargo build-deps
COPY server/src ./src/
COPY server/lemmy_db/src ./lemmy_db/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/
# Build for debug

View file

@ -13,6 +13,8 @@ WORKDIR /app/server
COPY server/Cargo.toml server/Cargo.lock ./
COPY server/lemmy_db ./lemmy_db
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 \
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
RUN cargo build --release

1
server/Cargo.toml vendored
View file

@ -11,6 +11,7 @@ members = [
"lemmy_utils",
"lemmy_db",
"lemmy_api_structs",
"lemmy_rate_limit",
]
[dependencies]

View file

@ -4,6 +4,10 @@ version = "0.1.0"
authors = ["Felix Ableitner <me@nutomic.com>"]
edition = "2018"
[lib]
name = "lemmy_api_structs"
path = "src/lib.rs"
[dependencies]
lemmy_db = { path = "../lemmy_db" }
serde = { version = "1.0.105", features = ["derive"] }

View file

@ -4,6 +4,10 @@ version = "0.1.0"
authors = ["Felix Ableitner <me@nutomic.com>"]
edition = "2018"
[lib]
name = "lemmy_rate_limit"
path = "src/lib.rs"
[dependencies]
lemmy_utils = { path = "../lemmy_utils" }
lemmy_api_structs = { path = "../lemmy_api_structs" }

View file

@ -1,13 +1,17 @@
#[macro_use]
pub extern crate strum_macros;
pub extern crate tokio;
pub extern crate futures;
pub extern crate actix_web;
pub extern crate futures;
pub extern crate log;
pub extern crate tokio;
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
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 std::{
future::Future,
@ -16,8 +20,6 @@ use std::{
task::{Context, Poll},
};
use tokio::sync::Mutex;
use lemmy_utils::get_ip;
use lemmy_utils::LemmyError;
pub mod rate_limiter;

View file

@ -1,6 +1,5 @@
use lemmy_utils::IPAddr;
use lemmy_utils::LemmyError;
use lemmy_api_structs::APIError;
use lemmy_utils::{IPAddr, LemmyError};
use log::debug;
use std::{collections::HashMap, time::SystemTime};
use strum::IntoEnumIterator;

View file

@ -1,5 +1,7 @@
#[macro_use]
pub extern crate lazy_static;
pub extern crate actix_web;
pub extern crate anyhow;
pub extern crate comrak;
pub extern crate lettre;
pub extern crate lettre_email;
@ -8,12 +10,11 @@ pub extern crate rand;
pub extern crate regex;
pub extern crate serde_json;
pub extern crate url;
pub extern crate actix_web;
pub extern crate anyhow;
pub mod settings;
use crate::settings::Settings;
use actix_web::dev::ConnectionInfo;
use chrono::{DateTime, FixedOffset, Local, NaiveDateTime};
use itertools::Itertools;
use lettre::{
@ -32,7 +33,6 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng};
use regex::{Regex, RegexBuilder};
use std::io::{Error, ErrorKind};
use url::Url;
use actix_web::dev::ConnectionInfo;
pub type ConnectionId = usize;
pub type PostId = i32;