diff --git a/src/main.rs b/src/main.rs index be5b780..29377d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ use salvo::prelude::{ handler, CatchPanic, Listener, Request, Response, Router, Server, Service, StaticDir, TcpListener, WebSocketUpgrade, }; -use salvo::websocket::{Message, WebSocket}; +use salvo::websocket::WebSocket; use salvo::writing::Json; use salvo::Depot; use tokio::sync::{mpsc, Mutex}; @@ -40,6 +40,8 @@ async fn session_middleware(req: &mut Request, res: &mut Response, depot: &mut D new_session_id = new_session_id, "Session provided in cookie, but does not exist" ); + } else { + store.sessions.get_mut(&session_id).unwrap().seen(false); } } Err(parse_error) => { diff --git a/src/models.rs b/src/models.rs index 8ad7436..eace9c4 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,4 +1,3 @@ -use rand::Rng; use salvo::{http::cookie::Cookie, websocket::Message, Response}; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, path}; @@ -12,7 +11,7 @@ pub struct Session { pub downloads: Vec, pub first_seen: chrono::DateTime, - // The last time a request OR websocket message with this session was made + // The last time a request OR websocket message from/to this session was made pub last_seen: chrono::DateTime, // The last time a request was made with this session pub last_request: chrono::DateTime, @@ -33,7 +32,6 @@ impl Session { // Add a download to the session pub fn add_download(&mut self, exe: &Executable) -> &SessionDownload { - let mut rng = rand::thread_rng(); let token: u32 = rand::random(); let download = SessionDownload { @@ -127,8 +125,7 @@ impl<'a> State<'a> { } pub async fn new_session(&mut self, res: &mut Response) -> u32 { - let mut rng = rand::thread_rng(); - let id: u32 = rng.gen(); + let id: u32 = rand::random(); let now = chrono::Utc::now(); self.sessions.insert(