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())) ?;