From e91e40e0fcec48bcf35f4f5d6338e0c12c9822d7 Mon Sep 17 00:00:00 2001 From: blek Date: Thu, 26 Oct 2023 23:54:47 +1000 Subject: [PATCH] attach user ip to the file record --- filed/src/files/mod.rs | 8 +++++--- filed/src/web/forms.rs | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/filed/src/files/mod.rs b/filed/src/files/mod.rs index e0dff4c..0ab410e 100644 --- a/filed/src/files/mod.rs +++ b/filed/src/files/mod.rs @@ -1,6 +1,6 @@ #![allow(unused)] -use std::{sync::Arc, error::Error, ops::Add}; +use std::{sync::Arc, error::Error, ops::Add, net::IpAddr}; use argon2::{PasswordHash, password_hash::SaltString, Params, PasswordHasher}; use chrono::{DateTime, Local}; @@ -22,6 +22,7 @@ pub struct File { pub delete_at: DateTime, pub delete_mode: DeleteMode, pub password: Option, // argon2id hash + pub uploader_ip: Option, sha512: String } @@ -101,7 +102,7 @@ impl File { Ok(ndata) } - pub async fn create(data: Vec, mime: String, name: Option, env: Env, delete_mode: DeleteMode, password: Option) -> Result> { + pub async fn create(data: Vec, mime: String, name: Option, env: Env, delete_mode: DeleteMode, password: Option, uploader_ip: Option) -> Result> { let mut filename = String::new(); let mut hash = Sha512::new(); @@ -140,7 +141,8 @@ impl File { Some(hash.serialize().to_string()) }, None => None - } + }, + uploader_ip } ) } diff --git a/filed/src/web/forms.rs b/filed/src/web/forms.rs index f64bff0..9748aef 100644 --- a/filed/src/web/forms.rs +++ b/filed/src/web/forms.rs @@ -146,7 +146,7 @@ fn bad_req_html(data: String) -> Box { ) } -pub async fn upload(form: FormData, _ip: Option, state: SharedState) -> Result, Rejection> { +pub async fn upload(form: FormData, ip: Option, state: SharedState) -> Result, Rejection> { if ! state.config.files.allow_uploads { return Ok( @@ -205,7 +205,8 @@ pub async fn upload(form: FormData, _ip: Option, state: SharedState) -> formdata.filename.clone(), state.env.clone(), formdata.delmode, - formdata.password + formdata.password, + ip ).await .map_err(|x| HttpReject::StringError(x.to_string())) ?;