mirror of
https://github.com/mvvasilev/findtheti.me.git
synced 2025-04-11 18:15:01 +03:00
Check for X-Real-IP header, fix Dockerfile, update ip column to account for ipv6
This commit is contained in:
parent
14d82964ba
commit
a8b7aaa678
9 changed files with 29 additions and 16 deletions
3
.dockerignore
Normal file
3
.dockerignore
Normal file
|
@ -0,0 +1,3 @@
|
|||
frontend/package-lock.json
|
||||
frontend/dist
|
||||
ftontend/node_modules
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -426,7 +426,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
|
|||
|
||||
[[package]]
|
||||
name = "findtheti-me"
|
||||
version = "0.1.2"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"chrono",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "findtheti-me"
|
||||
version = "0.1.2"
|
||||
version = "0.1.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
11
Dockerfile
11
Dockerfile
|
@ -14,17 +14,16 @@ RUN cargo build --release
|
|||
|
||||
### Build Front-End ###
|
||||
|
||||
FROM node:lts as nodebuilder
|
||||
FROM node:21 as nodebuilder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY ./frontend/package*.json ./
|
||||
COPY ./frontend/tsconfig*.json ./
|
||||
|
||||
RUN yarn install --prefer-offline --frozen-lockfile --non-interactive --production=true
|
||||
|
||||
COPY ./frontend ./
|
||||
|
||||
RUN yarn install --prefer-offline --frozen-lockfile --non-interactive
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
||||
RUN yarn build
|
||||
|
||||
RUN rm -rf node_modules
|
||||
|
|
|
@ -44,7 +44,7 @@ services:
|
|||
### Advanced (Without Docker)
|
||||
|
||||
1. Compile Backend (`cargo build --release`)
|
||||
2. Build Frontend (`cd frontend && yarn install --production && yarn build`)
|
||||
2. Build Frontend (`cd frontend && yarn install && yarn build`)
|
||||
3. Copy the `findtheti-me` file from `target/release` and place it into your desired installation folder
|
||||
4. Copy the `frontend/dist` folder and place it into the same installation folder, maintaining the directory tree.
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ const AvailabilityPicker = (props: {
|
|||
// @ts-ignore
|
||||
left: e.target?.offsetLeft - scrollLeft,
|
||||
width: element.width,
|
||||
height: (props.availabilityDurationInMinutes/60.0) * 2 * HALFHOUR_DISPLAY_HEIGHT
|
||||
height: ((props.availabilityDurationInMinutes/60.0) * 2 * (HALFHOUR_DISPLAY_HEIGHT + 0.5))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
3
migrations/20240111181203_ChangeIpColumnSizeAgain.sql
Normal file
3
migrations/20240111181203_ChangeIpColumnSizeAgain.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
-- this time with ipv6 in mind
|
||||
ALTER TABLE events.availability
|
||||
ALTER COLUMN user_ip TYPE VARCHAR(255);
|
|
@ -1,8 +1,8 @@
|
|||
use std::net::SocketAddr;
|
||||
use std::net::{SocketAddr, IpAddr};
|
||||
|
||||
use axum::{
|
||||
extract::{ConnectInfo, Path, State},
|
||||
http::StatusCode,
|
||||
http::{StatusCode, HeaderMap},
|
||||
Json,
|
||||
};
|
||||
use chrono::{DateTime, TimeZone, Utc};
|
||||
|
@ -178,6 +178,7 @@ pub async fn create_availabilities(
|
|||
State(app_state): State<AppState>,
|
||||
Path(event_snowflake_id): Path<String>,
|
||||
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||
headers: HeaderMap,
|
||||
Json(dto): Json<CreateAvailabilitiesDto>,
|
||||
) -> UniversalResponseDto<()> {
|
||||
let mut conn = match app_state.db_pool.acquire().await {
|
||||
|
@ -185,10 +186,17 @@ pub async fn create_availabilities(
|
|||
Err(e) => return api::internal_server_error(e.into()),
|
||||
};
|
||||
|
||||
let x_real_ip_header = headers.get("X-Real-IP").and_then(|v| v.to_str().ok()).and_then(|s| s.parse::<IpAddr>().ok());
|
||||
|
||||
let ip_compare_against = match x_real_ip_header {
|
||||
Some(ip) => ip,
|
||||
None => addr.ip(),
|
||||
};
|
||||
|
||||
let res = conn
|
||||
.transaction(|txn| {
|
||||
Box::pin(async move {
|
||||
let user_ip = format!("{}", addr.ip());
|
||||
let remote_ip = format!("{}", ip_compare_against);
|
||||
|
||||
let event = db::fetch_event_by_snowflake_id(txn, event_snowflake_id).await?;
|
||||
|
||||
|
@ -198,7 +206,7 @@ pub async fn create_availabilities(
|
|||
(dto.user_email.is_some()
|
||||
&& a.user_email.is_some()
|
||||
&& a.user_email == dto.user_email)
|
||||
|| a.user_ip == user_ip
|
||||
|| a.user_ip == remote_ip
|
||||
|| a.user_name == dto.user_name
|
||||
});
|
||||
|
||||
|
@ -220,7 +228,7 @@ pub async fn create_availabilities(
|
|||
from_date: a.from_date.naive_utc(),
|
||||
to_date: a.to_date.naive_utc(),
|
||||
user_email: dto.user_email.clone(),
|
||||
user_ip: user_ip.clone(),
|
||||
user_ip: remote_ip.clone(),
|
||||
user_name: dto.user_name.clone(),
|
||||
},
|
||||
)
|
||||
|
|
|
@ -14,7 +14,7 @@ mod db;
|
|||
mod endpoints;
|
||||
mod entity;
|
||||
|
||||
#[tokio::main(flavor = "multi_thread")]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() {
|
||||
println!("Starting findtheti.me...");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue